Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Teleport between world

Comments in 'Plugin Development' started by deot, Oct 31, 2015.

  1. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Hi,
    I have coded out and teleport is working (ignore that RakLib bug first)
    This is my code, and yes the teleportation is working :) But, it looks like teleported me to en empty world... :eek: Flat empty world....

    This is my code:
    PHP:
    public $arena

    public function onEnable(){
            
    $this->arena $this->getServer()->getLevelByName('arena');
    }

    public function 
    joinToArena(Player $p){
            
    $p->teleport(new Position(-99460, -997$this->arena));
    }
    Do I did anything wrong? I'm trying teleport player to the world with the folder named "arena" from default level.... I checked the coordinates, it's correct, but it should take me to arena instead of a FLAT land....
    Help?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    try checking the player's coords one tick after the teleportation.
  3. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    I checked, the coordinate is same as the coordinate in my code
    I'm just thinking it doesn't transfer player to another world...
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Are you sure $this->arena is loaded when you defined it?
  5. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    I think it is.... I put in in OnEnable...
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I know. I said loaded.
    deot likes this.
  7. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Code:
        public $arn;
       
        public function onEnable(){
            $arena = $this->getServer()->getLevelByName("arena");
            $this->getServer()->loadLevel($arena);
            $this->arn = $arena;
    }
    Yeah, I loaded it.... like above but it turned all my plugin upside down...!! All PlayerInteractEvent, PlayerMoveEvent don't work (I mean the codes in there don't even run) Do I load it wrongly?? =.=
  8. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    I think getLevelByName() returns an object, not a string.
    Use this instead:
    PHP:
    $this->getServer()->loadLevel("arena");
    Last edited: Oct 31, 2015
    PEMapModder likes this.
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    For the events, you need to register.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This shows that you don't understand PHP at all. If you do, you would realize that a variable that holds null without reference wouldn't suddenly turn into a Level object because of a statement executed later.
  11. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Please help, I am having the same issues as @deot , it teleports me to the cords in the same world, not a different one...
    PHP:
    public function onEnable(){
        
    $building "LobbyChristmas";
        
    $this->getServer()->loadLevel($this->building);
    }

    public function 
    onJoin(PlayerJoinEvent $event){
        
    $player $event->getPlayer();
        
    $cords $this->plugin->worlds->get("buildingSpawn");
        
    var_dump($cords);
        
    $world $this->plugin->getServer()->getLevelByName($this->plugin->building);
        
    var_dump($world);
        
    $player->teleport(new Position($cords[0],$cords[1],$cords[2],$world));
    }
    Vardump of $cords:
    Code:
    array(3) {
      [0] =>
      int(128)
      [1] =>
      int(12)
      [2] =>
      int(128)
    }
    
    Vardump of $world:
    Code:
    class pocketmine\level\Level#9139 (0) {
    }
    
    
    PHP:
     $player->teleport($world->getSafeSpawn()); 
    Does not work either.
    Last edited: Dec 8, 2015
  12. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Try this instead:
    PHP:
    $player->teleport($world->getSpawnLocation());
  13. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    That does not work either, which files should I be importing to use this function completely?

    Here are my current use statements in EventHandler.php:
    PHP:
    use pocketmine\Player;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\level\Position\getLevel;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\level\Location;
    use 
    pocketmine\level\particle\FloatingTextParticle;
    use 
    pocketmine\level\particle\Particle;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\entity\EntityLevelChangeEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerPreLoginEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\player\PlayerRespawnEvent;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\inventory\BaseTransaction;
    use 
    pocketmine\inventory\BigShapelessRecipe;
    use 
    pocketmine\inventory\CraftingTransactionGroup;
    use 
    pocketmine\inventory\FurnaceInventory;
    use 
    pocketmine\inventory\Inventory;
    use 
    pocketmine\inventory\InventoryHolder;
    use 
    pocketmine\inventory\SimpleTransactionGroup;
    use 
    pocketmine\inventory\StonecutterShapelessRecipe;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\plugin\PluginTask;
    use 
    falkirks\simplewarp\event\PlayerWarpEvent;
  14. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    When you load the level does it actually load? Check the console for error messages.
    The level.dat probably has a different name than the world folder, which could be causing problems.
  15. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    It is a freshly generated level, I even tried different levels and loading them on plugin startup and putting them in the pocketmine.yml.
  16. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Seems that any way I try teleporting the player through the plugin, does not put them in a different world:
    I tried teleporting with:
    (when I say //Does nothing it means that it just tps me to the spawn of the lobby)
    PHP:
    $player $event->getPlayer();
    $level $this->plugin->getServer()->getLevelByName($this->plugin->building);
    //Does nothing
    $player->teleport(new Vector3($x,$y,$z,$level));
    //Does nothing
    $player->teleport($level->getSpawnLocation());
    //Does nothing
    $player->teleport(new Position($cords[0],$cords[1],$cords[2],$level));
    //Does nothing
    $player->teleport($this->plugin->getServer()->getLevelByName($this->plugin->building)->getSafeSpawn());
    I also tried installing Manyworlds and doing:
    PHP:
    //does nothing
    $this->plugin->getServer()->dispatchCommand($player->getName(), "mw tp ".$this->plugin->building);
    //says teleporting by console, does nothing
    $this->plugin->getServer()->dispatchCommand(new ConsoleCommandSender(), "mw tp ".$player->getName()." ".$this->plugin->building);
    However, I found that actually typing the command into the console teleports me to the right world. This means that there is a line wrong somewhere in my plugin, but I cannot see it :(
  17. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    What does
    PHP:
    var_dump($this->plugin->building);
    say in the console?
  18. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    wo
    The name of the world: "LobbyChristmas"
  19. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Would anyone care to see the full plugin on GitHub?
  20. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Did you double-check that?
    Andrey Nazarchuk likes this.

Share This Page

Advertisement