diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/TeleportCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/TeleportCommand.java index 18d828c13..21c26eb72 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/TeleportCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/TeleportCommand.java @@ -30,6 +30,32 @@ public class TeleportCommand extends BaseCommand return String.format(COORDINATE_FORMAT, in); } + private static Double parseCoordinate(String in, double beginning) + { + try + { + if (in.startsWith("~")) + { + if (in.length() == 1) + { + return beginning; + } + + String relativeIn = in.substring(1); + + double relative = Double.parseDouble(relativeIn); + + return beginning + relative; + } + + return Double.parseDouble(in); + } + catch (NumberFormatException ex) + { + return null; + } + } + @Override public boolean execute(Player player, String alias, String[] args) { @@ -82,30 +108,30 @@ public class TeleportCommand extends BaseCommand // Teleport to coordinates... else if (args.length == 3) { - List coordinates = new ArrayList<>(); + List coordinates = new ArrayList<>(); - try + coordinates.add(parseCoordinate(args[0], player.getLocation().getX())); + coordinates.add(parseCoordinate(args[1], player.getLocation().getY())); + coordinates.add(parseCoordinate(args[2], player.getLocation().getZ())); + + for (Double coordinate : coordinates) { - for (String arg : args) + if (coordinate == null) { - coordinates.add(Float.parseFloat(arg)); + message(player, "Hmm, those coordinates don't look quite right."); + return true; } } - catch (NumberFormatException ex) - { - message(player, "Hmm, those coordinates don't look quite right."); - return true; - } Location destination = player.getLocation().clone(); destination.setX(coordinates.get(0)); - destination.setX(coordinates.get(1)); - destination.setX(coordinates.get(2)); + destination.setY(coordinates.get(1)); + destination.setZ(coordinates.get(2)); - message(player, "You teleported to coordinates (" - + F.name(formatCoordinate(destination.getZ())) + message(player, "You teleported to (" + + F.name(formatCoordinate(destination.getX())) + C.mBody + ", " - + F.name(formatCoordinate(destination.getZ())) + + F.name(formatCoordinate(destination.getY())) + C.mBody + ", " + F.name(formatCoordinate(destination.getZ())) + C.mBody + ").");