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

Need help on code!

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

  1. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    I'm working on a custom plugin and I need help:

    Error:
    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
    
    
    Code:
    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;
    }
    }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You are missing
    PHP:
    use pocketmine\Player;
     
  3. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    Wow thx it works now!
    One more question, how would I add a custom name to the item, for example this code:
    PHP:
     $gui->addServerToList(Item::get(Item::DIAMOND_PICKAXE), "play.onmyserverplea.se"19132);
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
     
  5. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    Alrighty thx!
     
  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.