<?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 $sa;
    public function onEnable(){
        $this->getServer()->loadLevel("authlob");
        $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function bobbyItems(Player $player){
        $inv = $player->getInventory();
        $inv->clearAll();   
        $inv->setItem(1, Item::get(340)->setCustomName("§r§aInformation"));
        $inv->setItem(4, Item::get(345)->setCustomName("§r§eMini-Games"));
        $inv->setItem(7, Item::get(342)->setCustomName("§r§5Cosmetics"));
    }
    public function duelsItems(Player $p){
    	$inv = $p->getInventory();
    $inv->clearAll();
    $inv->setItem(0, item::get(351,1,1)->setCustomName("§r§l§cLobby"));
    $inv->setItem(8, item::get(364,0,1)->setCustomName("§r§l§2Hunger§fGames"));
    $inv->setItem(2, item::get(369,0,1)->setCustomName("§r§l§eSumo"));
    $inv->setItem(5, item::get(299,0,1)->setCustomName("§r§l§9Boxing"));
    }
    public function leadItems(Player $p){
    	$inv = $p->getInventory();
    $inv->clearAll();
    $inv->setItem(0, item::get(351,1,1)->setCustomName("§r§l§cLobby"));
    $inv->setItem(8, item::get(340,0,1)->setCustomName("§r§l§eServer Info"));
    $inv->setItem(5, item::get(397,3,1)->setCustomName("§r§l§bProfile"));
    }

    /** @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() === 340 && $item->getCustomName() === "§r§aInformation"){
            $inv->clearAll();
            $inv->setItem(2, Item::get(339)->setCustomName("§r§5Server Info"));
            $inv->setItem(5, Item::get(340)->setCustomName("§r§eProfile"));
            $inv->setItem(8, Item::get(396)->setCustomName("§r§aShop"));
            $inv->setItem(0, Item::get(351,1)->setCustomName("§c§lBack"));
        }

        if($item->getId() === 345 && $item->getCustomName() === "§r§eMini-Games"){
            $inv->clearAll();
            $inv->setItem(2, Item::get(262)->setCustomName("§r§eLeaderboards"));
            $inv->setItem(4, Item::get(2)->setCustomName("§r§bSky§fWars"));
            $inv->setItem(7, Item::get(276)->setCustomName("§r§cDuels"));
            $inv->setItem(6, Item::get(288)->setCustomName("§r§aMLG§fBlock"));
            $inv->setItem(8, Item::get(159,11)->setCustomName("§r§9The§cBridge"));
            $inv->setItem(5, Item::get(355)->setCustomName("§r§cBed§fWars"));
            $inv->setItem(0, Item::get(351,1)->setCustomName("§c§lBack"));

                    }
        

        if($item->getId() === 342 && $item->getCustomName() === "§r§5Cosmetics"){
            $inv->clearAll();
            $inv->setItem(3, Item::get(351,8)->setCustomName("§r§bParticles\n§8(§7Soon§8)"));
            $inv->setItem(7, Item::get(351,8)->setCustomName("§r§ePets\n§8(§7Soon§8)"));
            $inv->setItem(0, Item::get(351,1)->setCustomName("§c§lBack"));
        }
                                    if($item->getId() === 2 && $item->getCustomName() == "§r§bSky§fWars"){
                    	$player->getServer()->dispatchCommand($player, "skywars join");
                    }
                            if($item->getId() === 396 && $item->getCustomName() == "§r§aShop"){
                    	$player->getServer()->dispatchCommand($player, "menushop");
                    }
                                        if($item->getId() == 276 && $item->getCustomName() === "§r§cDuels"){
                    	$player->getServer()->dispatchCommand($player, "duels");
                    }
                                        if($item->getId() == 288 && $item->getCustomName() === "§r§aMLG§fBlock"){
                    	$player->getServer()->dispatchCommand($player, "mlg entrar");
                    }
                                        if($item->getId() == 322 && $item->getCustomName() === "§r§2Hunger§fGames"){
                    	$player->sendMessage("§8(§bBaG§8) §cUnder development!");
                    }
                                                if($item->getId() === 339 && $item->getCustomName() == "§r§5Server Info"){
                    	$player->getServer()->dispatchCommand($player, "hungergames");
                    }
                                                                    if($item->getId() === 340 && $item->getCustomName() == "§r§eProfile"){
                    	$player->getServer()->dispatchCommand($player, "hungergames");
                    }
                                                                                        if($item->getId() === 397 && $item->getCustomName() == "§r§l§bProfile"){
                    	$player->getServer()->dispatchCommand($player, "hungergames");
                    }
                                                                                        if($item->getId() === 364 && $item->getCustomName() == "§r§l§2Hunger§fGames"){
                    	$player->getServer()->dispatchCommand($player, "hg join");
                    }
                                                                                        if($item->getId() === 299 && $item->getCustomName() == "§r§l§9Boxing"){
                    	$player->getServer()->dispatchCommand($player, "boxing entrar");
                    }
                                                                                        if($item->getId() === 369 && $item->getCustomName() == "§r§l§eSumo"){
                    	$player->getServer()->dispatchCommand($player, "sumo join");
                    }
                                                                                        if($item->getId() === 340 && $item->getCustomName() == "§r§l§eServer Info"){
                    	$player->getServer()->dispatchCommand($player, "hungergames");
                    }
                                                                                        if($item->getId() === 351 && $item->getCustomName() == "§r§l§cLobby"){
                    	$player->teleport($player->getServer()->getDefaultLevel()->getSafeSpawn());
                    }
                                        if($item->getId() == 159 && $item->getCustomName() === "§r§9The§cBridge"){
                    	$player->getServer()->dispatchCommand($player, "bridge entrar");
                    }
                                                            if($item->getId() == 262 && $item->getCustomName() === "§r§eLeaderboards"){
                    	$player->getServer()->dispatchCommand($player, "lboards");
                    }
                                        if($item->getId() == 369 && $item->getCustomName() === "§r§bMLG§cRush"){
                    	$player->getServer()->dispatchCommand($player, "mlgrush join");
                    }
                                        if($item->getId() == 355 && $item->getCustomName() === "§r§cBed§fWars"){
                    	$player->getServer()->dispatchCommand($player, "bw join");
    }
            if($item->getId() === 351 && $item->getCustomName() === "§c§lBack"){
            $this->bobbyItems($player);
        }
    }

    /** @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
        }
        
   }
}