Solved Teleport Player to coordnates

Discussion in 'Plugin Development' started by FireBreath14, Feb 24, 2013.

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

    FireBreath14

    I'm having trouble teleporting a player to a specific set of coordnates. Heres the code im using:

    Code:
    double x = (double)plugin.getConfig().get("spawn.x");
            double y = (double)plugin.getConfig().get("spawn.y");
            double z = (double)plugin.getConfig().get("spawn.z");
            player.getLocation().setX(x);
            player.getLocation().setY(y);
            player.getLocation().setZ(z);
    Earlier in the code, an admin sets the spawn.* points. now i need to teleport players that login to the point that the admin set. thanks for helping :)

    Don't get an error, just it doesnt work xD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Offline

    gamerzap

    I think you have to actually set the players location.
    Try
    player.setLocation(new Location(player.getWorld(), x, y, z));
     
  3. Offline

    david_rosales

    For the config do getConfig().getDouble(yourpath);
     
  4. Offline

    Xx_LeetGamer_xX

    This should work, just make sure to set the pitch/yaw in your config for the best teleportation.

    Code:
    World w = Bukkit.getWorld(getConfig().getString("spawn.world"));
    
    if(w == null){
        //TODO: Error message?
        return;
    }
    
    double x = getConfig().getDouble("spawn.x");
    double y = getConfig().getDouble("spawn.y");
    double z = getConfig().getDouble("spawn.z");
    
    float pitch = (float) getConfig().getDouble("spawn.pitch");
    float yaw = (float) getConfig().getDouble("spawn.yaw");
    
    Location l = new Loaction(w, x, y, z);
    l.setPitch(pitch);
    l.setYaw(yaw);
    
    p.teleport(l);
     
    FireBreath14 likes this.
  5. Offline

    FireBreath14


    aaaahhhh thank you! heres what i used:

    Code:
    World w = player.getWorld();
            Location l = new Location(w, x, y, z);
            player.teleport(l);
    i just needed to teleport them. lol but hey thanks!
     
    Xx_LeetGamer_xX likes this.
Thread Status:
Not open for further replies.

Share This Page