Grabbing Locations and teleporting a player to them

Discussion in 'Plugin Development' started by Vinceguy1, Jun 10, 2012.

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

    Vinceguy1

    How do i grab a players location and then teleport that player to that location (THIS IS FOR HOMES I DONT WANT A /tp) i know how to make it save in files and such, but what do i do to get the location and then how do i set the location?
     
  2. Something like this if you are loading the coordinates from a config file

    Code:
    // Get the coordinates and store it as a location
    Location home = new Location(config.getInt("homes." + player.getName() + ".home1.X"), config.getInt("homes." + player.getName() + ".home1.Y"), config.getInt("homes." + player.getName() + ".home1.Z"));
    // Set the yaw and pitch of the location
    home.setYaw(config.getInt("homes." + player.getName() + ".home1.Yaw"));
    home.setPitch(config.getInt("homes." + player.getName() + ".home1.Pitch"));
    // Teleport the user to the location
    player.teleport(home);
    // Send them a nice message
    player.sendMessage(ChatColor.YELLOW + "Welcome to your home!");
    Please note that the code will not work as is, you will have to modify it to make it work for you.
     
  3. iKeirNez Why don't you set yaw and pitch when you create the location? Also why are you using int for them? Double would fit better:
    Code:java
    1. player.teleport(new Location(config.getDouble("homes." + player.getName() + ".home1.X"), config.getIDouble("homes." + player.getName() + ".home1.Y"), config.getDouble("homes." + player.getName() + ".home1.Z"), (float)config.getDouble("homes." + player.getName() + ".home1.Yaw"), (float)config.getDouble("homes." + player.getName() + ".home1.Pitch")));
    2. player.sendMessage(ChatColor.YELLOW + "Welcome to your home!");
     
  4. I was doing this all from memory, forgot that you could specify it when you create the location. I only posted what I knew would definetely work.
     
Thread Status:
Not open for further replies.

Share This Page