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 d7c9144d4..18d828c13 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/TeleportCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/TeleportCommand.java @@ -1,5 +1,9 @@ package mineplex.mapparser.command.teleport; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; import org.bukkit.entity.Player; import mineplex.core.common.util.C; @@ -11,6 +15,7 @@ import mineplex.mapparser.command.BaseCommand; public class TeleportCommand extends BaseCommand { + private final static String COORDINATE_FORMAT = "%.2f"; private TeleportManager _teleportManager; public TeleportCommand(TeleportManager teleportManager) @@ -20,6 +25,11 @@ public class TeleportCommand extends BaseCommand _teleportManager = teleportManager; } + private static String formatCoordinate(double in) + { + return String.format(COORDINATE_FORMAT, in); + } + @Override public boolean execute(Player player, String alias, String[] args) { @@ -66,8 +76,45 @@ public class TeleportCommand extends BaseCommand return true; } + message(player, "You teleported " + F.name(sending.getName()) + " to " + F.name(destination.getName()) + C.mBody + "."); _teleportManager.teleportPlayer(sending, destination); } + // Teleport to coordinates... + else if (args.length == 3) + { + List coordinates = new ArrayList<>(); + + try + { + for (String arg : args) + { + coordinates.add(Float.parseFloat(arg)); + } + } + 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)); + + message(player, "You teleported to coordinates (" + + F.name(formatCoordinate(destination.getZ())) + + C.mBody + ", " + + F.name(formatCoordinate(destination.getZ())) + + C.mBody + ", " + + F.name(formatCoordinate(destination.getZ())) + + C.mBody + ")."); + _teleportManager.teleportPlayer(player, destination); + } + else + { + message(player, "Hmm, your command doesn't look quite right."); + } return true; }