How do I teleport multiple players without having errors?

Discussion in 'Plugin Development' started by xNaXDy, Aug 12, 2012.

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

    xNaXDy

    I tried this code to port all players to another world when a match starts:

    Code:
    for(Player p: getServer().getOnlinePlayers())
                    {
                        if(p.getWorld() != getServer().getWorld(toSelectWorld) && p.isOnline())
                        {
                            p.getLocation().setWorld(getServer().getWorld(toSelectWorld));
                            p.teleport(new Location(getServer().getWorld(toSelectWorld), Map.getMapByName(map).startX, Map.getMapByName(map).startY, Map.getMapByName(map).startZ));
                        }
                    }
    All players have been ported, but they were unable to see other players, or, sometimes they were unable to see certain players. For example Player A can see Player B but Player B can't see Player A, etc.

    Then I figured if I put this function in onPlayerMove()

    Code:
    if(p.getWorld() != getServer().getWorld(toSelectWorld) && p.isOnline())
                        {
                            p.getLocation().setWorld(getServer().getWorld(toSelectWorld));
                            p.teleport(new Location(getServer().getWorld(toSelectWorld), Map.getMapByName(map).startX, Map.getMapByName(map).startY, Map.getMapByName(map).startZ));
                        }
    It worked, but then I have the problem with AFK'ing players, they wouldn't get ported.

    Now my question is if there is any method I haven't tried yet to port all players to a world without having issues like not seeing others.
     
  2. Offline

    Phil2812

    xNaXDy
    Probably a bug in the current version(s): https://bukkit.atlassian.net/browse/BUKKIT-2199
    But I remember that beeing an issue back when I played with my closer friends on an own small server (maybe a year ago).
    And sorry I have no idea how you could do this other than experimenting with some other events that even occur for afk players or maybe you could try to teleport them again after they got teleported using a PlayerTeleportEvent?
    So you loop through a list of all players and teleport them to location y and then get them telported to location x (where you want them) by listening for the player teleport event.
     
  3. Offline

    xNaXDy

    Thanks for your help!

    For everyone else having this problem, this is how I solved it:

    Teleport the players to a new world to about 20000, 256, (whatever)
    They will fall, and therefore trigger the onPlayerMove event
    In this event, put in

    Code:
    Player p = event.getPlayer();
    if(p.getLocation().getX() > 10000 && p.getWorld() == getServer().getWorld("yourWorldYouWantToTpThePlayersInLongNameLol"))
    {
        // Your code to teleport to the real position.
    }
    The players will teleport and after a short time (of walking around) they will see everyone else :)
     
    TheTrixsta likes this.
  4. Offline

    xXSniperzzXx_SD


    So do you have to teleport them to a new world? like the nether? or could you just teleport them higher then the place you want them and then once they start falling have it activate the PlayerMoveEvent?
     
Thread Status:
Not open for further replies.

Share This Page