Hi, I have asked many Plugin Developers about this issue of mine. I want my plugin to check if the player has that item in his/her Inventory on PlayerJoinEvent and possibly remove the item on PlayerQuitEvent. My code would explain more I guess. Thanks. PHP: <?phpnamespace ItemDoesIt\RTG;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\Player;use pocketmine\event\Listener;use pocketmine\event\player\PlayerItemHeldEvent;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\event\player\PlayerQuitEvent;use pocketmine\level\Level;use pocketmine\item\Item;use pocketmine\entity\Effect;use pocketmine\event\player\PlayerMoveEvent;use pocketmine\command\CommandSender;use pocketmine\command\Command;use pocketmine\inventory\Inventory;class Main extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); //if($this->getServer()->getPluginManager()->getPlugin("ServerCore")) { //$this->getLogger()->critical("ServerCore isn't supported atm!"); //$this->setEnabled(false); //} } public function onGive($player) { $player->getInventory()->addItem(Item::get(388, 0, 1)->setCustomName("§eSpawn\nTeleports you to Spawn")); $player->getInventory()->addItem(Item::get(347, 0, 1)->setCustomName("§bRandom Effect\nGives you a random Effect")); } public function onHeld(PlayerItemHeldEvent $e) { $player = $e->getPlayer(); $hand = $player->getInventory()->getItemInHand(); if($hand->getCustomName() === "§eSpawn\nTeleports you to Spawn") { $l = $this->getServer()->getDefaultLevel()->getSafeSpawn(); $player->teleport($l); } if($hand->getCustomName() === "§bRandom Effect\nGives you a random Effect") { switch(mt_rand(1,3)) { case "1": $effect = Effect::getEffect(3); $effect->setDuration(13 * 20); $effect->setAmplifier(1); $player->addEffect($effect); return; case "2": $effectt = Effect::getEffect(19); $effectt->setDuration(13 * 20); $effectt->setAmplifier(1); $player->addEffect($effectt); return; case "3": $effecttt = Effect::getEffect(20); $effecttt->setDuration(13 * 20); $effecttt->setAmplifier(1); $player->addEffect($effecttt); return; } } } public function onJoin(PlayerJoinEvent $ev) { $player = $ev->getPlayer(); foreach($player->getInventory()->getItems() as $inv) { if($inv->getId() !== 388) { $this->getLogger()->warning("passed"); $this->onGive($player); } } } // Temp prior to onjoin verification doesnt work.. this doesnt work either error is from Item::getItem public function onQuit(PlayerQuitEvent $e) { $p = $e->getPlayer(); $i = $p->getInventory(); $i = Item::getItem(388, 0, 1); $ii = Item::getItem(347, 0, 1); $i->removeItem($i); $i->removeItem($ii); $this->getLogger()->warning("passed2"); } public function onDisable() { } } Or PR here https://github.com/RTGNetworkkk/ItemDoesIt
Doesnt PlayerQuitEvent::getPlayer returns OfflinePlayer? i remember i tried removing items from player's inventory when they quit, but i got an error
PlayerQuitEvent was added as PlayerJoinEvent doesn't work with my code. I'll remove it once PlayerJoinEvent is fixed.
Hi IG, PHP: $player->getInventory()->getItems.... There is no getItems() method in PocketMine, but there is getContents(). Take a look at this: https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Player.php#L2722
No. PlayerQuitEvent can be fired even before PlayerPreLoginEvent. Just use some sessioning skills to check if the player has been given what you have given him!