Keep fly/game mode in teleport between worlds

Discussion in 'Plugin Development' started by Ne0nx3r0, Jun 18, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Ne0nx3r0

    How can I keep a player's fly/gamemode status after a teleport to a different world?

    I've tried things similar to the following (with and without tasks) without any luck:

    Code:java
    1. Location l = p.getLocation();
    2.  
    3. l.setWorld(skyland);
    4. l.setY(4);
    5.  
    6. if(!p.isFlying()){
    7. l.getBlock().getRelative(BlockFace.DOWN).setType(Material.DIRT);
    8. }
    9.  
    10. if(p.getGameMode().equals(GameMode.CREATIVE)){
    11. plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable(){
    12. @Override
    13. public void run() {
    14. p.setGameMode(GameMode.CREATIVE);
    15. p.setAllowFlight(true);
    16. p.setFlying(true);
    17. }
    18. },1);
    19. }
    20. else if(p.isFlying()){
    21. plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable(){
    22. @Override
    23. public void run() {
    24. p.setAllowFlight(true);
    25. p.setFlying(true);
    26. }
    27. },1);
    28. }
    29.  
    30. p.teleport(l);;
     
  2. Offline

    flaaghara

    Get a copy of whatever information you want to persist and store it locally. After your setWorld() and setY() methods fire, just call more methods which set the Player's gamemode (and other stuff you saved) and you should be good to go.

    EDIT: I'm assuming you tried this already as your first step. If this doesn't work then you can use a task which perhaps fires a second or two after the world teleport? The method for that would go in the same aforementioned place.
     
  3. Offline

    Gater12

  4. Offline

    Ne0nx3r0

Thread Status:
Not open for further replies.

Share This Page