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

Solved "Call to undefined method getServer()

Discussion in 'Plugin Help' started by Ryux, Dec 25, 2019.

  1. Ryux

    Ryux Creeper

    Messages:
    5
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    Storia\Commands;

    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\command\Command;
    use 
    jojoe77777\FormAPI\SimpleForm;
    use 
    jojoe77777\FormAPI\CustomForm;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\Server;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\utils\TextFormat;
    use 
    Storia\Loader;
    use 
    Storia\EventListener;

    use 
    pocketmine\command\PluginCommand;

    class 
    ArenaCommand extends Command
    {

        public 
    $plugin;

        public function 
    __construct(Loader $plugin)
        {
            
    parent::__construct("arenas""Travel to a arena""arenas");
            
    $plugin->main $plugin;
        }

        public function 
    execute(CommandSender $senderstring $commandLabel, array $args)
        {
            
    $form = new SimpleForm(function (Player $sender$data) {
                if (
    $data === null) {
                    return 
    false;
                }
                switch (
    $data) {
                    case 
    0;
                        
    $sender->sendMessage("Teleported to Gapple.");
                        
    $sender->teleport($this->getServer()->getLevelByName("YourWorld")->getSafeSpawn());
                        
    $this->GappleKit($sender);
                        break;
    I keep getting this error : [Server thread/CRITICAL]: Error: "Call to undefined method Storia\Commands\ArenaCommand::getServer()" (EXCEPTION) in "plugins/Storia/src/Storia/Commands/ArenaCommand" at line 44

    if someone can help me that would be great :)
     
  2. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    PHP:
    $sender->teleport($this->getServer()->getLevelByName("YourWorld")->getSafeSpawn());
    Change to this because there arent any getServer function in the ArenaCommand
    PHP:
    $sender->teleport($this->plugin->getServer()->getLevelByName("YourWorld")->getSafeSpawn());
    PHP:
    $plugin->main $plugin;
    Change to this
    PHP:
    $this->main $plugin;
     
  3. Ryux

    Ryux Creeper

    Messages:
    5
    So i decided to change it up a bit using your advice, I get this Error now, "Call to a member function getSafeSpawn() on null"
    Code:
    $level = "Gapple";
                    $sender->teleport($this->main->getServer()->getLevelByName($level)->getSafeSpawn());
     
  4. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    Look like there isnt any world called "Gapple". Make sure you type the level name right
     
  5. Ryux

    Ryux Creeper

    Messages:
    5
    Still get the same error '"Call to a member function getSafeSpawn() on null""

    I even made sure the world was loaded, used multiworld to load it. I also did it with the default "world", still got the same error.
     
  6. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Impossible, are you sure you are loading the up to date plugin? (Are you restarting the server and not reloading it between tries?)
     
  7. Ryux

    Ryux Creeper

    Messages:
    5
    Yeah, I'm making a core. The core itself loads fine
     
  8. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    Just do getSpawnLocation
     
  9. Ryux

    Ryux Creeper

    Messages:
    5
    Call to a member function getSpawnLocation() on null
     
  10. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    Your world isnt loaded
     
    HimbeersaftLP likes this.
  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.