Get kicked when trying to teleport with config objects

Discussion in 'Development' started by M4nt0s, Sep 7, 2019.

  1. M4nt0s

    M4nt0s Spider Jockey

    Messages:
    30
    GitHub:
    M4nt0s
    This is the crashdump:

    Code:
    PocketMine-MP Crash Dump Sat Sep 7 11:28:09 EDT 2019
    
    Error: Argument 2 passed to pocketmine\nbt\tag\DoubleTag::__construct() must be of the type float, string given, called in phar:///home/mch/multicraft/servers/server1287/PocketMine-MP.phar/src/pocketmine/entity/Entity.php on line 945
    File: vendor/pocketmine/nbt/src/tag/DoubleTag
    Line: 40
    Type: TypeError
    
    Code:
    [31]
    [32] class DoubleTag extends NamedTag{
    [33]     /** @var float */
    [34]     private $value;
    [35]
    [36]     /**
    [37]      * @param string $name
    [38]      * @param float  $value
    [39]      */
    [40]     public function __construct(string $name = "", float $value = 0.0){
    [41]         parent::__construct($name);
    [42]         $this->value = $value;
    [43]     }
    [44]
    [45]     public function getType() : int{
    [46]         return NBT::TAG_Double;
    [47]     }
    [48]
    [49]     public function read(NBTStream $nbt, ReaderTracker $tracker) : void{
    [50]         $this->value = $nbt->getDouble();
    I never seen an error like this befor.

    And this is the part in my code i think is doing the crash.

    Code:
    public function onInteract(PlayerInteractEvent $event){
        $block = $event->getBlock();
        $player = $event->getPlayer();
        $name = $player->getName();
            $lvl = $player->getLevel();
        $id = $block->getId();
        $tile =
        $player->getLevel()->getTile($block);
        if($tile instanceof Sign){
            $text = $tile->getText();
            $line1 = $tile->getLine(1);
            $line2 = $tile->getLine(2);
            $line3 = $tile->getLine(3);
            $line0 = $tile->getLine(0);
             $this->map = new Config($this->getDataFolder()."$line2.yml", Config::YAML);
    if($line1 == "[Minefield]"){
    if(file_exists($this->getDataFolder()."$line2.yml")){
        $this->map = new Config($this->getDataFolder()."$line2.yml", Config::YAML);
        
    $player->teleport(new Vector3($this->map->get("lobbyx"), $this->map->get("lobbyy"), $this->map->get("lobbyz"), $this->map->get("lobbyworld")));
    }else{
        $player->sendMessage("Teleport failed!!");
    }
    }else{
        $player->sendMessage("No Map found!");
    }
    }
    }
    
    If someone can help me, I would be really grateful.
     
  2. HimbeersaftLP

    HimbeersaftLP Chicken

    Messages:
    1,687
    GitHub:
    HimbeersaftLP
    Your coordinates are read from the config as strings, typecast them to a float to convert them.
    Example:
    PHP:
    $player->teleport(new Vector3(
      (double) 
    $this->map->get("lobbyx"),
      (double) 
    $this->map->get("lobbyy"),
      (double) 
    $this->map->get("lobbyz"),
      
    $this->map->get("lobbyworld")
    ));
     
    M4nt0s likes this.
  3. M4nt0s

    M4nt0s Spider Jockey

    Messages:
    30
    GitHub:
    M4nt0s
    Thx/Danke
     
    HimbeersaftLP likes this.
  4. HimbeersaftLP

    HimbeersaftLP Chicken

    Messages:
    1,687
    GitHub:
    HimbeersaftLP
    No problem.
    Is your username a reference to the sweet Mentos or the YouTuber nameMethos?
     
    Fadhel likes this.
  5. M4nt0s

    M4nt0s Spider Jockey

    Messages:
    30
    GitHub:
    M4nt0s
    Neither of them. Is only a modified version of my real name.
     
    HimbeersaftLP likes this.

Share This Page

  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.