Actually make /tp <x, y, z> work
This commit is contained in:
parent
42a0da0d3e
commit
b71538b700
@ -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<Float> coordinates = new ArrayList<>();
|
||||
List<Double> 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)
|
||||
{
|
||||
coordinates.add(Float.parseFloat(arg));
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
if (coordinate == null)
|
||||
{
|
||||
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 + ").");
|
||||
|
Loading…
Reference in New Issue
Block a user