1.12.2 Get cords from last position of a player

Discussion in 'Spigot Plugin Development' started by Skrump, Mar 9, 2020.

  1. Hey!!
    I found it a bit difficult to write an easily understandable title for this, so I'm going to try to explain it as well as I can.

    I have a problem where whenever someone goes to another server (using BungeeCord) they spawn in the wrong world. I need to manually teleport the player to the other world. I do that by using the Multiverse-Core command /mv tp <player> <world>. This works just fine but I was wondering if I could send the player to the right world myself via my plugin.
    This seems easy but I can't think of a way to get the location where the player has last been in another world. I could log their disconnect location but I feel like there might be a better way.


    This is easy what the essential code will be:
    Code (Java):
    Location loc = new Location(world, x, y, z);

    player.teleport(loc);
    I just don't know how to get the x, y & z. I don't want to send players back to spawn each time they join the server.
     
  2. So, you want to teleport the player to the spawn at every login but don't want to do it everytime?
     
  3. Do you mean teleporting them to their last location on that server? If so, just store the x,y,z, and world in a file or database (yaml would work nicely) and when they join, retrieve those coordinates and teleport them, using
    Code (Text):
    player.teleport(new Location(Bukkit.getServer().getWorld(worldName), x, y, z)
    I would refresh the saved coords whenever the player leaves + every few minutes, to prevent against loss of data in server crashes.

    Alternatively, if you want to teleport them to the same location they were on the previous server, you could use a shared database for storing this or else probably some bungeecord socket magic.