Hi, basically, I try to make my plugin to force to send items to a player when the player change of level..I tried the PlayerMoveEvent but it was kinda stupid.. Example the player get in the level "lobby", it will clear the inventory and send a couple of items, when he enter in level "combo" it will clearAll and send other items...with PlayerMoveEvent it was KINDA working but lets say that the server didn't like that way lol. I checked a little into pocketmine and I found EntityLevelChangeEvent...I have no idea on how to use it but I am pretty sure that its there.. It would only send one time items. Thank you
and I want each of my worlds to have specific items example Diamond = item Combo = item1 Lobby = item2 and if the entity change level to Combo from Diamond, it will clear inventory and send item1, Diamond to Combo = clear inventory and send item, Diamond to Lobby = clear inventory and send item2 and etc
PHP: class YourClass implements Listener { public function levelChange(EntityLevelChangeEvent $event) { $entity = $event->getEntity(); if ($entity instanceof Player) { $level = $event->getTarget()->getName(); $levels = ['lobby' => [Item::get(Item::DIAMOND), Item::get(Item::EMERALD)], 'combo' => [Item::get(Item::DIRT), Item::get(Item::GRASS)]] foreach ($levels[$level] as $item) { $entity->getInventory()->clearAll(); $entity->getInventory()->addItem($item); } } }}
add: PHP: public function onEnable() : void{ $this->getServer()->getPluginManager()->registerEvents($this, $this); }
Just a little thing example if I put PHP: 'Combo' => [Item::get(Item::DIRT), Item::get(Item::GRASS), Item::get(Item::DIAMOND_SWORD)], It will only add the Diamond Sword (always the last item), how can I fix that ?
For each item, the inventory is cleared, causing this issue. You should move the line clearing the inventory out of the foreach loop.