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

Error with pocketmine\level\Position

Discussion in 'Development' started by DanielYTK, Feb 9, 2017.

  1. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    my error:
    Code:
     
    Unhandled exception executing command 'minas' in minas: Argument 4 passed to pocketmine\level\Position::__construct() must be an instance of pocketmine\level\Level, string given, called in C:\Users\DanielYTK\Documents\PocketMine-MP\plugins\Teleportes\src\DanielYTK\Main.php on line 55
    
    my code:
    PHP:
    <?php

    namespace DanielYTK;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Config;

    class 
    Main extends PluginBase implements Listener{
        public function 
    onEnable(){
            
    $plano = array(
                
    'y' => 0,
                
    'x' => 0,
                
    'z' => 0,
                
    'world' => "",
            );
            
    Server::getInstance()->getLogger()->info("§aNo§cWarps§f - §aHabilitado");
            
    Server::getInstance()->getPluginManager()->registerEvents($this$this);
            @
    mkdir($this->getDataFolder());
            
    $this->minas = new Config($this->getDataFolder()."minas.yml",Config::YAML,$plano);
            
    $this->minas->save();
            
    $this->minapvp = new Config($this->getDataFolder()."minapvp.yml",Config::YAML,$plano);
            
    $this->minapvp->save();
            
    $this->plots = new Config($this->getDataFolder()."plots.yml",Config::YAML,$plano);
            
    $this->plots->save();
            
    $this->loja = new Config($this->getDataFolder()."loja.yml",Config::YAML,$plano);
            
    $this->loja->save();
            
    $this->lojavip = new Config($this->getDataFolder()."lojavip.yml",Config::YAML,$plano);
            
    $this->lojavip->save();
            
    $this->lobby = new Config($this->getDataFolder()."lobby.yml",Config::YAML,$plano);
            
    $this->lobby->save();
            
    $this->arena = new Config($this->getDataFolder()."arena.yml",Config::YAML,$plano);
            
    $this->arena->save();
            
    //cmds : minas,minapvp,plots,loja,lojavip,lobby,arena
           
        
    }
        public function 
    onDisable() {
            
    Server::getInstance()->getLogger()->info("§aNo§cWarps§f - §aDesabilitado");
        }
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args) {
            switch (
    strtolower($command->getName())){
                case 
    "minas":
                    if(!isset(
    $args[0])){
                        if(
    $sender->isOp()){
                            
    $sender->sendMessage("§cVocê pode setar o local com: /minas setar");
                        if(!
    Server::getInstance()->isLevelLoaded($this->minas->get('world'))){
                            
    Server::getInstance()->loadLevel($this->minas->get('world'));
                            
    $sender->sendMessage("§aO mundo foi carregado!");
                            }
                        }
                        
    $sender->teleport(new Position($this->minas->get('x'), $this->minas->get('y'), $this->minas->get('z'), $this->minas->get('world'))); //line 55
                    
    }
                    if(
    strtolower($args[0]) == "setar"){
                        if(
    $sender->isOp()){
                        
    $x $sender->getX();
                        
    $y $sender->getY();
                        
    $z $sender->getZ();
                        
    $world $sender->getLevel()->getFolderName();
                        
    $this->minas->set('x'$x);
                        
    $this->minas->set('y'$y);
                        
    $this->minas->set('z'$z);
                        
    $this->minas->set('world'$world);
                        
    $sender->sendMessage("§aMinas setada!");
                        
    $this->minas->save();
                        } else {
                            
    $sender->sendMessage("§cVocê não é OPERADOR");
                        }
                    }
                    break; 
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You're trying to make a position of a saved string as level. As the crash dumb says, Position::__construct() requires a Level, not a string. Change it to
    PHP:
    $this->getServer()->getLevelByName($this->minas->get('world'))
    And it should do the job.
     
  3. Vaivez66

    Vaivez66 Spider

    Messages:
    12
    GitHub:
    Vaivez66
    Uh oh... :D
     
  4. DanielYTK

    DanielYTK Zombie

    Messages:
    227
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Mark thread as [SOLVED]
     
  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.