Add ability to teleport to coordinates in /tp

This commit is contained in:
ArcticZeroo 2018-02-20 16:53:23 -05:00 committed by Alexander Meech
parent e777394516
commit a941631fe7
1 changed files with 47 additions and 0 deletions

View File

@ -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<Float> 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;
}