Command for teleport a player

Discussion in 'Plugin Development' started by xMinecraft, Jan 12, 2013.

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

    xMinecraft

    Hello.
    I create one command for teleport one player to x location.
    The command is /tiendavip:

    Code:
    if(commandLabel.equalsIgnoreCase("tiendavip")) {
                Player player = (Player) sender;
                String xcoor = "1,889";
                String ycoor = "67";
                String zcoor = "142";
                double x = Double.parseDouble(xcoor);
                double y = Double.parseDouble(ycoor);
                double z = Double.parseDouble(zcoor);
                Location e = new Location(player.getWorld(), x, y, z);
                player.teleport(e);
            }
    This's not work :S
    Help me?
     
  2. Offline

    microgeek

    As far as I know parseDouble will not remove commas, I may be wrong though. Other that that, it looks fine.
     
  3. Offline

    xMinecraft

    So? String xcoor = "1889";?
     
  4. Offline

    microgeek

    Yes, that should work.

    Why are you storing it in a String any ways? Just use the double value in the method?
    :confused:
     
  5. Offline

    xMinecraft

    Code:
            if(commandLabel.equalsIgnoreCase("tiendavip")) {
                Player player = (Player) sender;
                double x = Double.parseDouble("1889");
                double y = Double.parseDouble("67");
                double z = Double.parseDouble("142");
                Location e = new Location(player.getWorld(), x, y, z);
                player.teleport(e);
            }
     
  6. Offline

    microgeek

    Is a lot easier.
     
  7. Offline

    chasechocolate

    Why parse the double when you can just make a double?
    Code:java
    1. if(commandLabel.equalsIgnoreCase("tiendavip")) {
    2. Player player = (Player) sender;
    3. double x = 1889;
    4. double y = 67;
    5. double z = 142;
    6. Location e = new Location(player.getWorld(), x, y, z);
    7. player.teleport(e);
    8. }
     
  8. Offline

    xMinecraft

    Thanks.
    How I can do to make the player look for a x block?
     
  9. Offline

    zeeveener

    If you mean change the direction they are looking, you will have to manipulate the pitch and yaw.
    They are floats instead of doubles.

    Yaw is the left-right direction.
    Pitch is the up-down direction.
    Play around with that until you get what you are looking for.
     
  10. Offline

    Gungsu

    Guys one help!
    I need select world to go, how do I convert the string to world?

    I got,
    I use this:
    Bukkit.getWorld(String);
    example:
    Code:
    if(commandLabel.equalsIgnoreCase("tiendavip")) {
    Player player = (Player) sender;
    String w = "world";
    double x = 1889;
    double y = 67;
    double z = 142;
    Location e = new Location(Bukkit.getWorld(w), x, y, z);
    player.teleport(e);
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
Thread Status:
Not open for further replies.

Share This Page