InvMenu problem

Discussion in 'Plugin Help' started by SaltyCubex, Dec 29, 2020.

  1. SaltyCubex

    SaltyCubex Creeper

    Messages:
    2
    Hi im trying to test InvMenu currently but I keep on getting this error: [TypeError: "Argument 1 passed to Test\Main::Test\{closure}() must be an instance of pocketmine\Player, instance of muqsit\invmenu\transaction\InvMenuTransaction given]
    Here's my code:
    PHP:
    <?php
    namespace Test;

    use 
    muqsit\invmenu\{InvMenuInvMenuHandler};
    use 
    pocketmine\command\{CommandCommandSender};
    use 
    pocketmine\item\Item;
    use 
    pocketmine\nbt\BigEndianNBTStream;
    use 
    pocketmine\nbt\tag\{CompoundTagListTag};
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\{ConfigTextFormat as TF};
    use 
    pocketmine\event\Listener;

    class 
    Main extends PluginBase implements Listener{

                    public function 
    onEnable(){
                        if (!
    InvMenuHandler::isRegistered()){
                            
    InvMenuHandler::register($this);
                        }
                    }
                    
                    public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool {
                    switch(
    $cmd->getName()){
                        case 
    "menu":
                        if(
    $sender instanceof Player){
                            
    $menu InvMenu::create(InvMenu::TYPE_CHEST);
                            
    $inv $menu->getInventory();
                            
    $menu->readOnly();
                            
    $item Item::get(5401);
                            
    $item->setCustomName("§l§8[§bFREE SHOUTOUT§8]");
                            
    $item->setLore(["§l§8----------\n§l§aFree clout for you :)"]);
                            
    $inv->addItem($item);
                            
    $menu->setListener(function (Player $playerItem $itemItem $itemClickedWithSlotChangeAction $action){
                                if(
    $item->getId() == 53){
                                
    $this->getServer()->dispatchCommand($player"say A player wanted free clout aint gonna do it :)))");
                                
    $player->removeWindow($action->getInventory());
                                }                           
                            });
                            
    $menu->send($sender);
                    }
                    }
                    return 
    true;
                    }
    }
     
  2. RicardoMilos384

    RicardoMilos384 Slime

    Messages:
    81
    GitHub:
    ricardomilos384

    PHP:
    $menu->setListener(InvMenu::readonly(function(DeterministicInvMenuTransaction $transaction) : void
            
    $player $transaction->getPlayer();
            
    $item $transaction->getItemClicked();
            
    $itemClickedWith $transaction->getItemClickedWith();
            
    $inv $transaction->getAction()->getInventory();
    });
     
  3. SaltyCubex

    SaltyCubex Creeper

    Messages:
    2
    where am I suppose to put this?
     
  4. ItsInspire

    ItsInspire Spider

    Messages:
    10
    GitHub:
    itsinspire
    Replace
    PHP:
    $menu->setListener(function (Player $playerItem $itemItem $itemClickedWithSlotChangeAction $action){
                                if(
    $item->getId() == 53){
                                
    $this->getServer()->dispatchCommand($player"say A player wanted free clout aint gonna do it :)))");
                                
    $player->removeWindow($action->getInventory());
                                }                           
                            });
    with the given code
     

Share This Page

  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.