How to get x,y,z of player and teleport

Discussion in 'Plugin Development' started by jacklin213, Nov 19, 2012.

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

    jacklin213

    I would like to know how to get x,y,z of a player and the direction hes facing in. and when someone uses a command they teleport to that location facing the same way
     
  2. Offline

    ZeusAllMighty11 Retired Staff

    Code:
    // Is player target or player player? confused
    Double pX = target.getLocation().getX();
    Double pY = target.getLocation().getY();
    Double pZ = target.getLocation().getZ();
    Double pPitch = target.getLocation().getPitch();
    Double pYaw = target.getLocation().getYaw();
    World pWorld = target.getWorld();
     
    Location pLoc = new Location(pWorld,pX,pY,pZ);
    pLoc.setPitch(pPitch);
    pLoc.setYaw(pYaw);
    // if commands say something
    // if it's the command you want to teleport
     
    player.teleport(pLoc);
    
     
  3. Offline

    jacklin213

    wats pitach and yaw?
    EDIT: no work
    The constructor Location(World, double, double, double, double, double) is undefined
     
  4. Offline

    ZeusAllMighty11 Retired Staff

    Fixed the code. Sorry it's 3am lol.


    Also, Pitch and Yaw are like the angles and direction player is facing I think.. I don't know how to explain

    http://forums.bukkit.org/threads/what-is-yaw-and-pitch.101146/

    here is a thread I found on it

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

    desht

    Why not just do:
    PHP:
    player.teleport(target.getLocation());
    ?

    Pitch is the "up/down" angle of the player's head: to be precise, the angle of the player's head around the horizontal axis perpendicular to the player's facing direction.

    Yaw is the "left/right" angle of the player's head: to be precise, the angle of the player's head around the vertical axis.
     
  6. Offline

    ZeusAllMighty11 Retired Staff


    Well he said get the xyz AND teleport, so he might be using the coords for something later
     
  7. Offline

    jacklin213

    ah they are floats as well apprently

    dont know y this isnt working

    Code:java
    1. @EventHandler
    2. public void onJoinEvent(PlayerJoinEvent event) {
    3. Player p = event.getPlayer();
    4. p.teleport(pos);
    5.  
    6. }


    main (open)
    Code:java
    1. package me.jacklin213.tplogin;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.World;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class TPLogin extends JavaPlugin {
    15.  
    16. public final Logger logger = Logger.getLogger("Minecraft");
    17. public TPLListener tpl = new TPLListener(this);
    18. public static TPLogin plugin;
    19. public double x;
    20. public double y;
    21. public double z;
    22. public float pitch;
    23. public float yaw;
    24. public World world = Bukkit.getWorld("world");
    25. public Location pos;
    26.  
    27.  
    28. public void onDisable() {
    29. logger.info(String.format("[%s] Disabled Version %s", getDescription()
    30. .getName(), getDescription().getVersion()));
    31. }
    32.  
    33. public void onEnable() {
    34. logger.info(String.format("[%s] Enabled Version %s by jacklin213",
    35. getDescription().getName(), getDescription().getVersion()));
    36. }
    37.  
    38. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]){
    39. if (sender instanceof Player){
    40. if (commandLabel.equalsIgnoreCase("tplogin")){
    41. if (args.length == 1){
    42. if(args[0].equalsIgnoreCase("set")){
    43. if (sender.hasPermission("tplogin.set")){
    44. Location player = (Location) sender;
    45. x = player.getX();
    46. y = player.getY();
    47. z = player.getZ();
    48. pitch = player.getPitch();
    49. yaw = player.getYaw();
    50. Location pos = new Location(world, x ,y ,z);
    51. pos.setPitch(pitch);
    52. pos.setYaw(yaw);
    53. return true;
    54. } else {
    55. sender.sendMessage(ChatColor.RED + "You do not have the permission to do this!");
    56. return true;
    57. }
    58. }
    59. } else if (args.length > 1 || args.length == 0) {
    60. sender.sendMessage(ChatColor.RED + "Not enough arguments!");
    61. return true;
    62. }
    63. }
    64. }
    65.  
    66.  
    67. return false;
    68.  
    69. }
    70.  
    71. }
    72.  


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

    desht

    Try using a sync delayed task with a zero delay to teleport the player.
     
  9. Offline

    jacklin213

    erm sorry how do i do that?
     
  10. Offline

    desht

  11. Offline

    jacklin213

    been there dont under stand it :(
    i would b greatfull if there was an example ty
     
  12. Offline

    V10lator

    Cowboys1919 likes this.
  13. Offline

    desht

  14. Offline

    jacklin213

    Do I put my pos.teleport inside run()?
     
  15. Offline

    fireblast709

    yes, you do the p.teleport(pos) in there :3 (inside the public void run(), that is)
     
  16. Offline

    jacklin213

    so this delay thingy will make my plugin work?
     
  17. Offline

    RealDope

    You should probably just try it and see...
     
    Cowboys1919 likes this.
Thread Status:
Not open for further replies.

Share This Page