<?php
namespace boobycore;
use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\player\PlayerRespawnEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\item\Item;
use pocketmine\event\entity\EntityLevelChangeEvent;
use pocketmine\Player;
use pocketmine\Server;

class bobb extends PluginBase implements Listener{

    public function onEnable(){
        $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function bobbyItems(Player $player){
        $inv = $player->getInventory();
        $inv->clearAll();

        $inv->setItem(0, Item::get(102)->setCustomName(" "));
        $inv->setItem(1, Item::get(403)->setCustomName("§r§a§lInformation"));
        $inv->setItem(2, Item::get(102)->setCustomName(" "));
        $inv->setItem(3, Item::get(102)->setCustomName(" "));
        $inv->setItem(4, Item::get(345)->setCustomName("§r§l§eMini-Games"));
        $inv->setItem(5, Item::get(102)->setCustomName(" "));
        $inv->setItem(6, Item::get(102)->setCustomName(" "));
        $inv->setItem(7, Item::get(54)->setCustomName("§r§l§5Cosmetics"));
        $inv->setItem(8, Item::get(102)->setCustomName(" "));
    }

    /** @eventHandler */
    public function onJoin(PlayerJoinEvent $event){
        $this->bobbyItems($event->getPlayer());
    }

    /** @eventHandler */
    public function onInteract(PlayerInteractEvent $event){
        $player = $event->getPlayer();
        $item = $player->getItemInHand();
        $inv = $player->getInventory();

        if($item->getId() === 403 && $item->getCustomName() === "§r§a§lInformation"){
            $inv->clearAll();
            $inv->setItem(2, Item::get(339)->setCustomName("§a§lServer Info"));
            $inv->setItem(5, Item::get(340)->setCustomName("§e§lProfile"));
            $inv->setItem(8, Item::get(377)->setCustomName("§b§lSettings"));
            $inv->setItem(0, Item::get(351,1)->setCustomName("§c§lBack"));
        }

        if($item->getId() === 345 && $item->getCustomName() === "§r§l§eMini-Games"){
            $inv->clearAll();
            $inv->setItem(2, Item::get(2)->setCustomName("§bSky§fWars"));
            $inv->setItem(3, Item::get(276)->setCustomName("§cDuels"));
            $inv->setItem(4, Item::get(288)->setCustomName("§aMLG§fBlock"));
            $inv->setItem(5, Item::get(46)->setCustomName("§cTNT§eTag"));
            $inv->setItem(6, Item::get(267)->setCustomName("§9The§cBridge"));
            $inv->setItem(7, Item::get(277)->setCustomName("§bSpleef"));
            $inv->setItem(8, Item::get(388)->setCustomName("§cBed§fWars"));
            $inv->setItem(0, Item::get(351,1)->setCustomName("§c§lBack"));

                    }
        }

        if($item->getId() === 54 && $item->getCustomName() === "§r§l§5Cosmetics"){
            $inv->clearAll();
            $inv->setItem(3, Item::get(388)->setCustomName("§bParticles"));
            $inv->setItem(7, Item::get(384)->setCustomName("§ePets"));
            $inv->setItem(0, Item::get(351,1)->setCustomName("§c§lBack"));
        }

        if($item->getId() === 351 && $item->getCustomName() === "§c§lBack"){
            $this->bobbyItems($player);
        }
                            if($item->getId() === 2 && $item->getCustomName() === "§bSky§fWars"){
                    	$player->getServer()->dispatchCommand($player, "menusw");
                    }
                                        if($item->getId() === 276 && $item->getCustomName() === "§cDuels"){
                    	$player->getServer()->dispatchCommand($player, "menudu");
                    }
                                        if($item->getId() === 288 && $item->getCustomName() === "§aMLG§fBlock"){
                    	$player->getServer()->dispatchCommand($player, "menumb");
                    }
                                        if($item->getId() === 46 && $item->getCustomName() === "§cTNT§eTag"){
                    	$player->getServer()->dispatchCommand($player, "menutnt");
                    }
                                        if($item->getId() === 267 && $item->getCustomName() === "§9The§cBridge"){
                    	$player->getServer()->dispatchCommand($player, "menutb");
                    }
                                        if($item->getId() === 277 && $item->getCustomName() === "§bSpleef"){
                    	$player->getServer()->dispatchCommand($player, "menuspe");
                    }
                                        if($item->getId() === 388 && $item->getCustomName() === "§cBed§fWars"){
                    	$player->getServer()->dispatchCommand($player, "menubw");
    }

    /** @eventHandler */
    public function onQuit(PlayerQuitEvent $event){
        $event->getPlayer()->getInventory()->clearAll();
    }

    /** @eventHandler */
    public function onRespawn(PlayerRespawnEvent $event){
        $this->bobbyItems($event->getPlayer());
    }

public function changey(EntityLevelChangeEvent $ev){
    $p = $ev->getEntity();
    $inv=$p->getInventory();
    if(!$p instanceof Player) return;

    $target = $ev->getTarget(); // This is the new world
    $default = $p->getServer()->getDefaultLevel(); // Your lobby
$bw=$p->getServer()->getLevelByName("Eastwood");
    if($target === $default){ // Player is entering lobby
            $this->bobbyItems($p); // Give lobby items
        }
        
   }
}