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

help TPui plugin

Discussion in 'Plugin Help' started by Winchester, Sep 2, 2018.

  1. Winchester

    Winchester Baby Zombie

    Messages:
    133
    apparently the error is on line 21 but I do not know how to

    Code:
    <?php
    
    namespace TeleportUI;
    
    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;
    use pocketmine\event\Listener;
    use pocketmine\{command\ConsoleCommandSender, Server, Player, utils\TextFormat};
    use pocketmine\plugin\PluginBase;
    
    class Main extends PluginBase implements Listener{
    
        public function onEnable(){
            $this->getServer()->getPluginManager()->registerEvents($this, $this);
            $this->getLogger()->info("TeleportUI by @retired_dev!");
        }
    
        public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{
            $player = $sender->getPlayer();
            switch($command->getName()){
                case "tpui":
                    $this->menuForm($player);
            }
            return true;
        }
    
        public function teleportForm($player){
            if($player instanceof Player){
                $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI");
                $form = $api->createSimpleForm(function (Player $sender, array $data){
                    if(isset($data[0])){
                        switch($data[0]){
                            case 0:
                                $this->tpaskForm($sender);
                                break;
                            case 1:
                                 $this->tpahereForm($sender);
                                break;
                            case 2:
                                $this->tpacceptForm($sender);
                                break;
                            case 3:
                                $this->tpdenyForm($sender);
                                break;
                        }
                    }
                });
                $form->setTitle("Teleport");
                $form->setContent("Teleport to other players!");
                $form->addButton("Tpask");
                $form->addButton("Tpahere");
                $form->addButton("Tpaccept");
                $form->addButton("Tpdeny");
                $form->sendToPlayer($player);
            }
        }
    
        public function tpaskForm($player){
            $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            $form = $api->createCustomForm(function (Player $event, array $data){
                $player = $event->getPlayer();
                $result = $data[0];
                if($result != null){
                    $this->askName = $result;
                    $this->getServer()->getCommandMap()->dispatch($player, "tpask " . $this->askName);
                }
            });
            $form->setTitle(TextFormat::GREEN . "Tpask Request");
            $form->addInput("Request to teleport to this player!");
            $form->sendToPlayer($player);
        }
        
        public function tpahereForm($player){
            $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            $form = $api->createCustomForm(function (Player $event, array $data){
                $player = $event->getPlayer();
                $result = $data[0];
                if($result != null){
                    $this->ahereName = $result;
                    $this->getServer()->getCommandMap()->dispatch($player, "tpahere " . $this->ahereName);
                }
            });
            $form->setTitle(TextFormat::GREEN . "Tpahere Request");
            $form->addInput("Request to teleport this player to you!");
            $form->sendToPlayer($player);
        }
        
        public function tpacceptForm($player){
            $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            $form = $api->createCustomForm(function (Player $event, array $data){
                $player = $event->getPlayer();
                $result = $data[0];
                if($result != null){
                    $this->acceptName = $result;
                    $this->getServer()->getCommandMap()->dispatch($player, "tpaccept " . $this->acceptName);
                }
            });
            $form->setTitle(TextFormat::GREEN . "Tpaccept player's request");
            $form->addInput("Accept player's teleport request!");
            $form->sendToPlayer($player);
        }
        
        public function tpdenyForm($player){
            $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            $form = $api->createCustomForm(function (Player $event, array $data){
                $player = $event->getPlayer();
                $result = $data[0];
                if($result != null){
                    $this->denyName = $result;
                    $this->getServer()->getCommandMap()->dispatch($player, "tpdeny " . $this->denyName);
                }
            });
            $form->setTitle(TextFormat::GREEN . "Tpdeny player's request");
            $form->addInput("Deny player's teleport request!");
            $form->sendToPlayer($player);
        }
    
    
    }
    
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    $this->menuForm doesn't exist, that's why. Also, next time it would be helpful if you say what the error is.
     
  3. Winchester

    Winchester Baby Zombie

    Messages:
    133
    [Server thread/CRITICAL]: Houve uma exceção ao executar o comando 'tpui' em tpui: Call to undefined method TeleportUI\Main::menuForm()
    [14:11:57] [Server thread/CRITICAL]: Error: "Call to undefined method TeleportUI\Main::menuForm()" (EXCEPTION) in "TeleportUI-master/src/TeleportUI/Main" at line 17
    [14:11:57] [Server thread/DEBUG]: #0 src/pocketmine/command/PluginCommand(58): TeleportUI\Main->onCommand(pocketmine\Player object, pocketmine\command\PluginCommand object, string tpui, array Array())
    [14:11:57] [Server thread/DEBUG]: #1 src/pocketmine/command/SimpleCommandMap(258): pocketmine\command\PluginCommand->execute(pocketmine\Player object, string tpui, array Array())
    [14:11:57] [Server thread/DEBUG]: #2 src/pocketmine/Server(1955): pocketmine\command\SimpleCommandMap->dispatch(pocketmine\Player object, string tpui)
    [14:11:57] [Server thread/DEBUG]: #3 src/pocketmine/Player(2191): pocketmine\Server->dispatchCommand(pocketmine\Player object, string tpui)
    [14:11:57] [Server thread/DEBUG]: #4 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(222): pocketmine\Player->chat(string /tpui)
    [14:11:57] [Server thread/DEBUG]: #5 src/pocketmine/network/mcpe/protocol/CommandRequestPacket(54): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleCommandRequest(pocketmine\network\mcpe\protocol\CommandRequestPacket object)
    [14:11:57] [Server thread/DEBUG]: #6 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(92): pocketmine\network\mcpe\protocol\CommandRequestPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    [14:11:57] [Server thread/DEBUG]: #7 src/pocketmine/network/mcpe/protocol/BatchPacket(114): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\CommandRequestPacket object)
    [14:11:57] [Server thread/DEBUG]: #8 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(92): pocketmine\network\mcpe\protocol\BatchPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    [14:11:57] [Server thread/DEBUG]: #9 src/pocketmine/Player(3056): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    [14:11:57] [Server thread/DEBUG]: #10 src/pocketmine/network/mcpe/RakLibInterface(162): pocketmine\Player->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    [14:11:57] [Server thread/DEBUG]: #11 vendor/pocketmine/raklib/src/server/ServerHandler(98): pocketmine\network\mcpe\RakLibInterface->handleEncapsulated(string 192.168.15.10 50802, raklib\protocol\EncapsulatedPacket object, integer 0)
    [14:11:57] [Server thread/DEBUG]: #12 src/pocketmine/network/mcpe/RakLibInterface(103): raklib\server\ServerHandler->handlePacket()
    [14:11:57] [Server thread/DEBUG]: #13 src/pocketmine/network/Network(94): pocketmine\network\mcpe\RakLibInterface->process()
    [14:11:57] [Server thread/DEBUG]: #14 src/pocketmine/network/mcpe/RakLibInterface(80): pocketmine\network\Network->processInterface(pocketmine\network\mcpe\RakLibInterface object)
    [14:11:57] [Server thread/DEBUG]: #15 vendor/pocketmine/snooze/src/SleeperHandler(120): pocketmine\network\mcpe\RakLibInterface->pocketmine\network\mcpe\{closure}()
    [14:11:57] [Server thread/DEBUG]: #16 vendor/pocketmine/snooze/src/SleeperHandler(82): pocketmine\snooze\SleeperHandler->processNotifications()
    [14:11:57] [Server thread/DEBUG]: #17 src/pocketmine/Server(2259): pocketmine\snooze\SleeperHandler->sleepUntil(double 1535908317.8169)
    [14:11:57] [Server thread/DEBUG]: #18 src/pocketmine/Server(2134): pocketmine\Server->tickProcessor()
    [14:11:57] [Server thread/DEBUG]: #19 src/pocketmine/Server(1700): pocketmine\Server->start()
    [14:11:57] [Server thread/DEBUG]: #20 src/pocketmine/PocketMine(243): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string D:\BlackHatSociety\, string D:\BlackHatSociety\plugins\)
    [14:11:57] [Server thread/DEBUG]: #21 D:/BlackHatSociety/PocketMine-MP.phar(1): require(string phar://D:/BlackHatSociety/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
     
  4. Winchester

    Winchester Baby Zombie

    Messages:
    133
    Can you tell me how to fix this?
     
  5. Qeis2007

    Qeis2007 Witch

    Messages:
    70
    GitHub:
    FrostingBita
    It think this work:
    PHP:
    <?php

    namespace TeleportUI;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\{command\ConsoleCommandSenderServerPlayerutils\TextFormat};
    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase implements Listener{

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info("TeleportUI by @retired_dev!");
        }

        public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args) : bool{
            
    $player $sender->getPlayer();
            switch(
    $command->getName()){
                case 
    "tpui":
                    
    $this->teleportForm($player);
            }
            return 
    true;
        }

        public function 
    teleportForm($player){
            if(
    $player instanceof Player){
                
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
                
    $form $api->createSimpleForm(function (Player $sender, array $data){
                    if(isset(
    $data[0])){
                        switch(
    $data[0]){
                            case 
    0:
                                
    $this->tpaskForm($sender);
                                break;
                            case 
    1:
                                 
    $this->tpahereForm($sender);
                                break;
                            case 
    2:
                                
    $this->tpacceptForm($sender);
                                break;
                            case 
    3:
                                
    $this->tpdenyForm($sender);
                                break;
                        }
                    }
                });
                
    $form->setTitle("Teleport");
                
    $form->setContent("Teleport to other players!");
                
    $form->addButton("Tpask");
                
    $form->addButton("Tpahere");
                
    $form->addButton("Tpaccept");
                
    $form->addButton("Tpdeny");
                
    $form->sendToPlayer($player);
            }
        }

        public function 
    tpaskForm($player){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createCustomForm(function (Player $event, array $data){
                
    $player $event->getPlayer();
                
    $result $data[0];
                if(
    $result != null){
                    
    $this->askName $result;
                    
    $this->getServer()->getCommandMap()->dispatch($player"tpask " $this->askName);
                }
            });
            
    $form->setTitle(TextFormat::GREEN "Tpask Request");
            
    $form->addInput("Request to teleport to this player!");
            
    $form->sendToPlayer($player);
        }
       
        public function 
    tpahereForm($player){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createCustomForm(function (Player $event, array $data){
                
    $player $event->getPlayer();
                
    $result $data[0];
                if(
    $result != null){
                    
    $this->ahereName $result;
                    
    $this->getServer()->getCommandMap()->dispatch($player"tpahere " $this->ahereName);
                }
            });
            
    $form->setTitle(TextFormat::GREEN "Tpahere Request");
            
    $form->addInput("Request to teleport this player to you!");
            
    $form->sendToPlayer($player);
        }
       
        public function 
    tpacceptForm($player){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createCustomForm(function (Player $event, array $data){
                
    $player $event->getPlayer();
                
    $result $data[0];
                if(
    $result != null){
                    
    $this->acceptName $result;
                    
    $this->getServer()->getCommandMap()->dispatch($player"tpaccept " $this->acceptName);
                }
            });
            
    $form->setTitle(TextFormat::GREEN "Tpaccept player's request");
            
    $form->addInput("Accept player's teleport request!");
            
    $form->sendToPlayer($player);
        }
       
        public function 
    tpdenyForm($player){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createCustomForm(function (Player $event, array $data){
                
    $player $event->getPlayer();
                
    $result $data[0];
                if(
    $result != null){
                    
    $this->denyName $result;
                    
    $this->getServer()->getCommandMap()->dispatch($player"tpdeny " $this->denyName);
                }
            });
            
    $form->setTitle(TextFormat::GREEN "Tpdeny player's request");
            
    $form->addInput("Deny player's teleport request!");
            
    $form->sendToPlayer($player);
        }


    }
     
  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.