From 99a5f13b5e41edef2074054c744b9f8fea4f3263 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sun, 19 Dec 2010 23:53:56 -0800 Subject: [PATCH] Added /tpback, not exactly working correctly yet. --- vMinecraftCommands.java | 28 +++++++++++++++++++ vMinecraftUsers.java | 61 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java index 9e437fecb..8f4b31649 100644 --- a/vMinecraftCommands.java +++ b/vMinecraftCommands.java @@ -58,6 +58,7 @@ public class vMinecraftCommands{ cl.register("/freeze", "freeze"); cl.register("/tp", "teleport"); cl.register("/tphere", "tphere"); + cl.register("/tpback", "tpback"); cl.register("/masstp", "masstp", "Teleports those with lower permissions to you"); //Health @@ -177,6 +178,17 @@ public class vMinecraftCommands{ .globalmessages()); return EXIT_SUCCESS; } + public static int tpback(Player player, String[] args){ + if(player.canUseCommand("/tpback")){ + double x = vMinecraftUsers.getProfile(player).getTpx(); + double y = vMinecraftUsers.getProfile(player).getTpy(); + double z = vMinecraftUsers.getProfile(player).getTpz(); + player.teleportTo(x, y, z, 0, 0); + return EXIT_SUCCESS; + + } + return EXIT_SUCCESS; + } //===================================================================== //Function: prefix (/prefix) //Input: Player player: The player using the command @@ -1013,6 +1025,14 @@ public class vMinecraftCommands{ //If the player exists transport the user to the player else { + //Storing their previous location for tpback + double x = player.getLocation().x; + double y = player.getLocation().y; + double z = player.getLocation().z; + vMinecraftUsers.getProfile(player).setTpback(x, y, z); + if(player.canUseCommand("/tpback")){ + player.sendMessage(Colors.DarkPurple + "Your previous location has been stored, use /tpback to return."); + } vMinecraftChat.gmsg( player, vMinecraftChat.getName(player) + Colors.LightBlue + " has teleported to " + vMinecraftChat.getName(playerTarget)); @@ -1094,6 +1114,14 @@ public class vMinecraftCommands{ log.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self."); playerTarget.teleportTo(player); + double x = player.getLocation().x; + double y = player.getLocation().y; + double z = player.getLocation().z; + vMinecraftUsers.getProfile(playerTarget).setTpback(x, y, z); + if(playerTarget.canUseCommand("/tpback")) + { + playerTarget.sendMessage(Colors.DarkPurple + "Your previous location has been stored, use /tpback to return."); + } } return EXIT_SUCCESS; } diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index b39e02fce..02a525b6c 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -153,6 +153,9 @@ class PlayerList nickName, tag, suffix; + private double tpx, + tpy, + tpz; private boolean dead; @@ -242,6 +245,20 @@ class PlayerList } } } + //XYZ TP Back value + //Not sure if declaring a double this way will work or not + if(character.length > 7) + { + double tpx = new Double(character[7]).doubleValue(); + } + if(character.length > 8) + { + double tpy = new Double(character[8]).doubleValue(); + } + if(character.length > 9) + { + double tpz = new Double(character[9]).doubleValue(); + } in.close(); return true; } @@ -285,7 +302,7 @@ class PlayerList writer.append(nickName + ":"); writer.append(suffix + ":"); writer.append(defaultColor + ":"); - + int i = 0; for(String ignore : ignoreList) { @@ -294,8 +311,10 @@ class PlayerList writer.append(","); } writer.append(":"); - writer.append(aliasList.toString()); + writer.append(tpx + ":"); + writer.append(tpy + ":"); + writer.append(tpz + ":"); writer.append("\r\n"); } } @@ -325,6 +344,7 @@ class PlayerList out.append(nickName + ":"); out.append(suffix + ":"); out.append(defaultColor + ":"); + int i = 0; for(String ignore : ignoreList) @@ -334,6 +354,9 @@ class PlayerList out.append(","); } out.append(":"); + out.append(tpx + ":"); + out.append(tpy + ":"); + out.append(tpz + ":"); out.append(aliasList.toString()); out.newLine(); @@ -456,6 +479,40 @@ class PlayerList tag = newTag; save(); } + //===================================================================== + //Function: setTpback + //Input: None + //Output: None + //Use: Sets a player's tpback xyz coordinates + //===================================================================== + public void setTpback(double x, double y, double z) + { + //Coordinates + x = tpx; + y = tpy; + z = tpz; + } + //===================================================================== + //Function: getTpbx + //Input: None + //Output: Double: The player's tpback x coords + //Use: Gets the x value of tpback + //===================================================================== + public double getTpx() { return tpx; } + //===================================================================== + //Function: getTpy + //Input: None + //Output: Double: The player's tpback x coords + //Use: Gets the x value of tpback + //===================================================================== + public double getTpy() { return tpy; } + //===================================================================== + //Function: getTpz + //Input: None + //Output: Double: The player's tpback x coords + //Use: Gets the x value of tpback + //===================================================================== + public double getTpz() { return tpz; } //===================================================================== //Function: getTag