Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Undefined Method

Comments in 'Plugin Development' started by Skullex, May 15, 2016.

  1. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    I got this error on a Transaction from the chest to the players Inventory

    Code:
    "Could not pass event 'pocketmine\event\inventory\InventoryTransactionEvent' to 'CommandChests v1': Call to undefined method pocketmine\event\inventory\InventoryTransactionEvent::getPlayer() on CommandChests\Main
    [09:34:38] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\event\inventory\InventoryTransactionEvent::getPlayer()" (EXCEPTION) in "/CommandChests-master/src/CommandChests/Main" at line 29
    
    I don't see what I did wrong, any help?

    PHP:
    <?php

    namespace CommandChests;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\Player;

    use 
    pocketmine\event\inventory\InventoryTransactionEvent;
    use 
    pocketmine\item\Item;

    class 
    Main extends PluginBase implements Listener {
       
        public function 
    onEnable(){
            
    $this->getLogger()->info(TextFormat::AQUA "has been loaded successfully!");
            
    $this->getServer()->getPluginManager()->registerEvents($this ,$this);
            
    $this->saveDefaultConfig();
            
    $this->reloadConfig();
            
    //$items = $config->get("Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9", "Item10", "Item11", "Item12", "Item13", "Item14", "Item15", "Item16", "Item17", "Item18", "Item19", "Item20");
           
            //$config1 = (new Config($this->getDataFolder()."/commands.yml", Config::YAML, array("Item1" => "276", "Item2" => "323", "Item3" => "354", "Item4" => "346", "Item5" => "345", "Item6" => "35:2", "Item7" => "0", "Item8" => "0", "Item9" => "0", "Item10" => "0", "Item11" => "0", "Item12" => "0", "Item13" => "0", "Item14" => "0", "Item15" => "0", "Item16" => "0", "Item17" => "0", "Item18" => "35:14")))->getAll();
        
    }
       
        public function 
    onTransaction(InventoryTransactionEvent $event){
            
    $player $event->getPlayer();
            
    $inv $event->getInventory();
            
    $chest $inv->getHolder();
            
    $item $event->getItem()->getId();
            
    $cfg $this->getConfig();
            
    $playername $event->getPlayer()->getName();
            if(
    $player instanceof Player){
                if(
    $inv instanceof ChestInventory){
                    if(
    $event->getPlayer()->getLevel()->getName() == "New spawn"){
                        
    $event->setCancelled(true);                  
                        
    //$item = $chest->getInventory()->getItem($items);
                        
    if($item === $cfg->get("Item-1") and $cfg->get("Enable-1") == true){
                foreach(
    $cfg->get("Command-1") as $cmd1) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd1));   
                }
                }elseif(
    $item === $cfg->get("Item-2") and $cfg->get("Enable-2") == true){
                foreach(
    $cfg->get("Command-2") as $cmd2) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd2));   
                }
                }elseif(
    $item === $cfg->get("Item-3") and $cfg->get("Enable-3") == true){
                foreach(
    $cfg->get("Command-3") as $cmd3) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd3));   
                }
                }elseif(
    $item === $cfg->get("Item-4") and $cfg->get("Enable-4") == true){
                foreach(
    $cfg->get("Command-4") as $cmd4) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd4));   
                }
                }elseif(
    $item === $cfg->get("Item-5") and $cfg->get("Enable-5") == true){
                foreach(
    $cfg->get("Command-5") as $cmd5) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd5));   
                }
                }elseif(
    $item === $cfg->get("Item-6") and $cfg->get("Enable-6") == true){
                foreach(
    $cfg->get("Command-6") as $cmd6) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd6));   
                }
                }elseif(
    $item === $cfg->get("Item-7") and $cfg->get("Enable-7") == true){
                foreach(
    $cfg->get("Command-7") as $cmd7) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd7));   
                }
                }elseif(
    $item === $cfg->get("Item-8") and $cfg->get("Enable-8") == true){
                foreach(
    $cfg->get("Command-8") as $cmd8) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd8));   
                }
                }elseif(
    $item === $cfg->get("Item-9") and $cfg->get("Enable-9") == true){
                foreach(
    $cfg->get("Command-9") as $cmd9) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd9));   
                }
                }elseif(
    $item === $cfg->get("Item-10") and $cfg->get("Enable-10") == true){
                foreach(
    $cfg->get("Command-10") as $cmd10) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd10));
                }
                            }elseif(
    $item === $cfg->get("Item-11") and $cfg->get("Enable-11") == true){
                foreach(
    $cfg->get("Command-11") as $cmd11) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd11));
                }
                            }elseif(
    $item === $cfg->get("Item-12") and $cfg->get("Enable-12") == true){
                foreach(
    $cfg->get("Command-12") as $cmd12) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd12));
                }
                            }elseif(
    $item === $cfg->get("Item-13") and $cfg->get("Enable-13") == true){
                foreach(
    $cfg->get("Command-13") as $cmd13) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd13));
                }
                            }elseif(
    $item === $cfg->get("Item-14") and $cfg->get("Enable-14") == true){
                foreach(
    $cfg->get("Command-14") as $cmd14) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd14));
                }
                            }elseif(
    $item === $cfg->get("Item-15") and $cfg->get("Enable-15") == true){
                foreach(
    $cfg->get("Command-15") as $cmd15) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd15));
                }
                            }elseif(
    $item === $cfg->get("Item-16") and $cfg->get("Enable-16") == true){
                foreach(
    $cfg->get("Command-16") as $cmd16) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd16));
                }
                            }elseif(
    $item === $cfg->get("Item-17") and $cfg->get("Enable-17") == true){
                foreach(
    $cfg->get("Command-17") as $cmd17) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd17));
                }
                            }elseif(
    $item === $cfg->get("Item-18") and $cfg->get("Enable-18") == true){
                foreach(
    $cfg->get("Command-18") as $cmd18) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd18));
                }
                            }elseif(
    $item === $cfg->get("Item-19") and $cfg->get("Enable-19") == true){
                foreach(
    $cfg->get("Command-19") as $cmd19) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd19));
                }
                            }elseif(
    $item === $cfg->get("Item-20") and $cfg->get("Enable-20") == true){
                foreach(
    $cfg->get("Command-20") as $cmd20) {
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{player}"$playername$cmd20));
                }
                        }
                    }
                }
            }
        }
    }
  2. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    To get the player do:
    PHP:
    public function onInvTrans(InventoryTransactionEvent $event){

    $transa $event->getTransaction()->getTransactions();
    $int $event->getTransaction()->getInventories();


            foreach (
    $transa as $t) {
                foreach (
    $int as $inst) {


                    
    $inst $inst->getHolder();
                    if (
    $inst instanceof Player) {
                        
    $player $inst;
                    }

              
                    if (
    $inst instanceof Chest) {
                        
    $chest $inst;
                    }

    }


    }}}
    cake23 and Irish like this.

Share This Page

Advertisement