Teleporting to certain coordinates

Discussion in 'Plugin Development' started by Xerfox, Aug 20, 2013.

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

    Xerfox

    I know how to teleport players to other players, but I want it so when someone enters a command like ./donorshopsend <player>, it sends the specified player to the coordinates that I have in the code. Thanks to everyone and anyone that can help! :)
     
  2. Offline

    aidenkrz

    Here Is the Code For The Teleporting to cordes


    Code:java
    1. // Now to choose the teleport location
    2. Location loc = null;
    3. switch (selector)
    4.  
    5. {
    6. case 0: loc = new Location(target.getWorld(), 100, 60, 100);
    7. break;
    8. }


    Drop A Like If I Helped
     
  3. Xerfox
    This is the simplest way to do it. With this method, the coordinates are hard-coded into the plugin.

    Code:

    Code:java
    1. Player targetplayer = Bukkit.getServer().getPlayer(args[0]);
    2. if (commandLabel.equalsIgnoreCase("donorshopsend")){
    3. targetplayer.teleport(new Location(targetplayer.getWorld(), x, y, z, yaw, pitch));
    4. //Replace x, y, z, yaw, pitch with the corresponding coordinates
    5. }


    You can also get & set the location from the config. Let me know if that's what what you want or if the above code is fine :)

    That only works for servers running Java 7. Not alot of servers run that, and can cause severe problems.

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

    epicfacecreeper

    You don't NEED the pitch and yaw btw.
     
  5. That ensures that the player is facing the correct direction. Without that, the player will be facing north.
     
  6. Offline

    aidenkrz

    Well My Server Does Not Run Java 7 and it works
     
  7. Offline

    Xerfox

    Thanks man! Helped so much :D I appreciate it!
     
  8. Interesting. I've learned that using Java 7 stuff on servers running Java 6 is a big no-no. Anyways, what I suggested will work on any server :)

    No prob :)
    With that method, just make sure that the target player is in the world with the donor shop. As I stated before, you can set and get the donorshop location from the config. This would be much better than the simple version I told you, depending on your needs :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  9. Offline

    Xerfox

    Yeah but this is for a custom plugin, and it won't be going onto bukkit. Thanks for the help I greatly appreciate it :D
     
  10. Offline

    Samthelord1

  11. Offline

    aidenkrz

  12. Offline

    epicfacecreeper

    Switch has been in java for a while. Java 7 introduced switching strings.
    Also, update java. Please.
     
Thread Status:
Not open for further replies.

Share This Page