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

Registry not working

Discussion in 'Development' started by neb16, May 19, 2019.

  1. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    So currently im trying to make a plugin that uses muqsit's library here is my current code:

    PHP:
    <?php

    namespace Commands;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\{
        
    CommandCommandSender
    };
    use 
    pocketmine\utils\TextFormat as C;
    use 
    muqsit\invmenu\InvMenu;





    class 
    ServerSelectorGUI{

        
    /** @var InvMenu */
        
    private $menu;

        public function 
    __construct(string $name){
            
    $this->menu InvMenu::create(InvMenu::TYPE_CHEST)
                ->
    readonly()
                ->
    setName($name)
                ->
    setListener([$this"onServerSelectorTransaction"])//you can call class functions this way
                
    ->onInventoryClose(function(Player $player) : void{
                    
    $player->sendMessage(TextFormat::GREEN "You are being transferred...");
                });
        }

        public function 
    addServerToList(Item $itemstring $addressint $port) : void{
            
    $nbt $item->getNamedTag();
            
    $nbt->setString("Server"$address ":" $port);
            
    $item->setNamedTag($nbt);
            
    $this->menu->addItem($item);
        }

        public function 
    onServerSelectorTransaction(Player $playerItem $itemClickedOn) : bool{
            
    $player->transfer(...explode(":"$itemClickedOn->getNamedTag()->getString("Server""play.onthefallbackserv.er:19132")));
            return 
    true;
        }

        public function 
    sendTo(Player $player) : void{
            
    $this->menu->send($player);
        }
    }

    $gui = new ServerSelectorGUI("Server Selector");
    $gui->addServerToList(Item::get(Item::DIAMOND_PICKAXE), "play.onmyserverplea.se"19132);
    $gui->addServerToList(Item::get(Item::IRON), "play.onmyserverplea.se"19133);






    class 
    Main extends PluginBase{

        public function 
    onLoad(): void{
            
    $this->getLogger()->info(C::GREEN "Loading Commands...");
        }

        public function 
    onEnable(): void{
            
    $this->getLogger()->info(C::YELLOW "Enabled Commands!");
            if(!
    InvMenuHandler::isRegistered()){
                
    InvMenuHandler::register($this);
            }
        }

        public function 
    onDisable(): void{
            
    $this->getLogger()->info(C::RED "Commands Disabled!");
        }

      
        
        

        public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args): bool{
            
            
            
            switch(
    $command){
                case 
    "test":
                
    $sender->sendMessage("Test works :)");
                break;
                case 
    "transfer":
                
                
    $gui->sendTo($player);
                break;
            }
            return 
    true;
        }
    }
    And I get this error:

    Code:
    [Server thread/CRITICAL]: Error: "Class 'muqsit\invmenu\InvMenu' not found" (EXCEPTION) in "plugins/Commands/src/Commands/Main" at line 22
    
    And yes I did install his plugin.
     
  2. Eren5960

    Eren5960 Spider Jockey

    Messages:
    27
    GitHub:
    Eren5960
    İnvMenu is virion plugin. You must be use DEVirion.
     
  3. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    Alright I did all that now it can call the library, but now I get this:

    Code:
    [Server thread/CRITICAL]: TypeError: "Argument 1 passed to muqsit\invmenu\InvMenu::onInventoryClose() must be an instance of pocketmine\Player, instance of Closure given, called in /root/mcpe/plugins/Commands/src/Commands/Main.php on line 29" (EXCEPTION) in "/root/mcpe/virions/InvMenu-master/src/muqsit/invmenu/InvMenu" at line 135
    
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Same code?
     
  5. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    yes
     
  6. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    Should I move the selector class inside the command function?
     
  7. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    https://github.com/Muqsit/InvMenu/blob/master/src/muqsit/invmenu/InvMenu.php#L135

    @Muqsit probably done some upgrades. Examples at invmenu's wiki are outdated...

    You can use setInventoryCloseListener(callable $func) instead.
     
  8. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
  9. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
  10. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    No, but when you make it, I can check it
     
  11. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Just replace onInventoryClose with setInventoryCloseListener like @GamakCZ said
    I've just updated the InvMenu wiki :oops:
     
  12. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    Alright thanks
     
  13. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101

    Here is the updated code, I realized that it kept crashing because I did not call pocketmine\item\Item, but now I guess I need to define it???

    Code:
    [14:46:14] [Server thread/CRITICAL]: Error: "Call to undefined method muqsit\invmenu\InvMenu::addItem()" (EXCEPTION) in "plugins/Commands/src/Commands/Main" at line 38
    

    PHP:
    <?php

    namespace Commands;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\{
    CommandCommandSender
    };
    use 
    pocketmine\utils\TextFormat as C;
    use 
    muqsit\invmenu\InvMenu;
    use 
    pocketmine\nbt\tag\{
    CompoundTagListTagDoubleTagFloatTag
    };
    use 
    muqsit\invmenu\inventories\BaseFakeInventory;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\item\Item;


    class 
    ServerSelectorGUI{

    /** @var InvMenu */
    private $menu;

    public function 
    __construct(string $name){
    $this->menu InvMenu::create(InvMenu::TYPE_CHEST)
    ->
    readonly()
    ->
    setName($name)
    ->
    setListener([$this"onServerSelectorTransaction"])//you can call class functions this way
    ->setInventoryCloseListener(function(Player $player) : void{
    $player->sendMessage(TextFormat::GREEN "You are being transferred...");
    });
    }

    public function 
    addServerToList(Item $itemstring $addressint $port) : void{
    $nbt $item->getNamedTag();
    $nbt->setString("Server"$address ":" $port);
    $item->setNamedTag($nbt);
    $this->menu->addItem($item);
    }

    public function 
    onServerSelectorTransaction(Player $playerItem $itemClickedOn) : bool{
    $player->transfer(...explode(":"$itemClickedOn->getNamedTag()->getString("Server""play.onthefallbackserv.er:19132")));
    return 
    true;
    }

    public function 
    sendTo(Player $player) : void{
    $this->menu->send($player);
    }
    }

    $gui = new ServerSelectorGUI("Server Selector");
    $gui->addServerToList(Item::get(Item::DIAMOND_PICKAXE), "play.onmyserverplea.se"19132);
    $gui->addServerToList(Item::get(Item::IRON), "play.onmyserverplea.se"19133);





    class 
    Main extends PluginBase{

    public function 
    onLoad(): void{
    $this->getLogger()->info(C::GREEN "Loading Commands...");
    }

    public function 
    onEnable(): void{
    $this->getLogger()->info(C::YELLOW "Enabled Commands!");
    if(!
    InvMenuHandler::isRegistered()){
    InvMenuHandler::register($this);
    }
    }

    public function 
    onDisable(): void{
    $this->getLogger()->info(C::RED "Commands Disabled!");
    }







    public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args): bool{



    switch(
    $command){
    case 
    "test":
    $sender->sendMessage("Test works :)");
    break;
    case 
    "transfer":

    $gui->sendTo($player);
    break;
    }
    return 
    true;
    }
    }
     
  14. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    A virion is not a plugin. There is no such thing as "virion plugin".
     
  15. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101

    Hmmm, ok. But do you see any erros with the code?
     
  16. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Use $this->menu->getInventory()->addItem($item); insteadof $this->menu->addItem($item);
     
  17. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    Alright fixed that and a couple of other things but as usual it creates another problem -_-:

    Code:
    [14:58:14] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to Commands\ServerSelectorGUI::sendTo() must be an instance of Commands\Player, instance of pocketmine\Player given, called in /root/mcpe/plugins/Commands/src/Commands/Main.php on line 98" (EXCEPTION) in "plugins/Commands/src/Commands/Main" at line 48
    
    PHP:


    public function __construct(string $name){
    $this->menu InvMenu::create(InvMenu::TYPE_CHEST)
    ->
    readonly()
    ->
    setName($name)
    ->
    setListener([$this"onServerSelectorTransaction"])//you can call class functions this way
    ->setInventoryCloseListener(function(Player $player) : void{
    $player->sendMessage(TextFormat::GREEN "You are being transferred...");
    });
    }

    public function 
    addServerToList(Item $itemstring $addressint $port) : void{
    $nbt $item->getNamedTag();
    $nbt->setString("Server"$address ":" $port);
    $item->setNamedTag($nbt);
    $this->menu->getInventory()->addItem($item);
    }

    public function 
    onServerSelectorTransaction(Player $playerItem $itemClickedOn) : bool{
    $player->transfer(...explode(":"$itemClickedOn->getNamedTag()->getString("Server""play.onthefallbackserv.er:19132")));
    return 
    true;
    }

    public function 
    sendTo(Player $player) : void{
    $this->menu->send($player);
    }
    }






    class 
    Main extends PluginBase{

    public function 
    onLoad(): void{
    $this->getLogger()->info(C::GREEN "Loading Commands...");
    }

    public function 
    onEnable(): void{
    $this->getLogger()->info(C::YELLOW "Enabled Commands!");
    if(!
    InvMenuHandler::isRegistered()){
    InvMenuHandler::register($this);
    }
    }

    public function 
    onDisable(): void{
    $this->getLogger()->info(C::RED "Commands Disabled!");
    }







    public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args): bool{



    switch(
    $command){
    case 
    "test":
    $sender->sendMessage("Test works :)");
    break;
    case 
    "transfer":
    $player $sender->getPlayer();


    $gui = new ServerSelectorGUI("Server Selector");
    $gui->addServerToList(Item::get(Item::DIAMOND_PICKAXE), "play.onmyserverplea.se"19132);
    $gui->addServerToList(Item::get(Item::IRON_INGOT), "play.onmyserverplea.se"19133);


    $gui->sendTo($player);
    break;
    }
    return 
    true;
    }
    }
     
  18. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    Did I define player wrong?
     
  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.