1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

MenuGUI Command Help

Discussion in 'Help' started by ZackyVN, Aug 7, 2018.

  1. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    Here is my code :
    <?php

    namespace Menu;

    use pocketmine\inventory\transaction\action\SlotChangeAction;
    use pocketmine\item\Item;
    use pocketmine\Player;
    use pocketmine\math\Vector3;
    use pocketmine\plugin\PluginBase;
    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;
    use pocketmine\event\Listener;
    use muqsit\invmenu\InvMenuHandler;
    use muqsit\invmenu\InvMenu;

    class Menu{

    private $plugin;

    public function __Construct(Main $plugin){
    $this->plugin = $plugin;
    if (!InvMenuHandler::isRegistered()) {
    InvMenuHandler::register($plugin);
    }

    public function onCommand(CommandSender $sender, Command $cmd, string $label,array $args) : bool {
    switch($cmd->getName()){
    case "menu":
    if($sender instanceof Player){
    $player = $sender->getName();
    $this->Menu($sender);
    }else{
    $sender->sendMessage("Er.......");
    }
    return true;
    }
    }

    public function Menu(Player $player){
    $menu = InvMenu::create(InvMenu::TYPE_CHEST);
    $menu->readonly();
    $menu->setName("§l§eGame§b Menu");
    //[Murder] Item
    $murder = Item::get(378, 0, 1);
    $murder->setCustomName("§l§cMur§eder");
    $murder->setLore(array("§l§eTap to§a Play"));
    //[Player Head] Item
    $playerhead = Item::get(144, 0, 1);
    $playerhead->setLore(array("§aĐây là thông tin của bạn! Chạm vào để xem§r\n§aTên: $player"));
    $playerhead->setCustomName("§l§aI§bn§cf§do");
    //Inventory
    $inv = $menu->getInventory();
    $inv->setItem(6, $playerhead);
    $inv->setItem(13, $murder);
    $menu->setListener([$this, "onTransaction"]);
    $menu->setListener(function(Player $player, item $itemClickedOn, Item $itemClickedwith): bool{
    if($itemClickedOn->getCustomName() == "§l§cMur§eder"){
    $this->getServer()->getCommandMap()->dispatch($player, "mdui");
    }
    return true;
    });
    $menu->send($player);
    }

    public function onTransaction(Player $player, Item $itemTakenOut, Item $itemPutIn, SlotChangeAction $inventoryAction) : bool{
    $player->removeWindow($inventoryAction->getInventory());
    return true;
    }
    }
    It didnt show the fake chest when i typed /menu
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.