mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-14 19:55:52 -07:00
Update Bukkit for Minecraft 1.4(.2) changes.
By: Travis Watkins <amaranth@ubuntu.com>
This commit is contained in:
@@ -16,7 +16,7 @@ import com.google.common.collect.ImmutableList;
|
||||
public class TeleportCommand extends VanillaCommand {
|
||||
public TeleportCommand() {
|
||||
super("tp");
|
||||
this.description = "Teleports the given player to another player";
|
||||
this.description = "Teleports the given player to another player or location";
|
||||
this.usageMessage = "/tp [player] <target>\n/tp [player] <x> <y> <z>";
|
||||
this.setPermission("bukkit.command.teleport");
|
||||
}
|
||||
@@ -56,9 +56,14 @@ public class TeleportCommand extends VanillaCommand {
|
||||
player.teleport(target, TeleportCause.COMMAND);
|
||||
Command.broadcastCommandMessage(sender, "Teleported " + player.getName() + " to " + target.getName());
|
||||
} else if (player.getWorld() != null) {
|
||||
int x = getInteger(sender, args[args.length - 3], -30000000, 30000000);
|
||||
int y = getInteger(sender, args[args.length - 2], 0, 256);
|
||||
int z = getInteger(sender, args[args.length - 1], -30000000, 30000000);
|
||||
double x = getCoordinate(sender, player.getLocation().getX(), args[args.length - 3]);
|
||||
double y = getCoordinate(sender,player.getLocation().getY(), args[args.length - 2], 0, 0);
|
||||
double z = getCoordinate(sender, player.getLocation().getZ(), args[args.length - 1]);
|
||||
|
||||
if (x == -30000001 || y == -30000001 || z == -30000001) {
|
||||
sender.sendMessage("Please provide a valid location!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Location location = new Location(player.getWorld(), x, y, z);
|
||||
player.teleport(location);
|
||||
@@ -67,6 +72,39 @@ public class TeleportCommand extends VanillaCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
private double getCoordinate(CommandSender sender, double current, String input) {
|
||||
return getCoordinate(sender, current, input, -30000000, 30000000);
|
||||
}
|
||||
|
||||
private double getCoordinate(CommandSender sender, double current, String input, int min, int max) {
|
||||
boolean relative = input.startsWith("~");
|
||||
double result = relative ? current : 0;
|
||||
|
||||
if (!relative || input.length() > 1) {
|
||||
boolean exact = input.contains(".");
|
||||
if (relative) input = input.substring(1);
|
||||
|
||||
double testResult = getDouble(sender, input);
|
||||
if (testResult == -30000001) {
|
||||
return -30000001;
|
||||
}
|
||||
result += testResult;
|
||||
|
||||
if (!exact && !relative) result += 0.5f;
|
||||
}
|
||||
if (min != 0 || max != 0) {
|
||||
if (result < min) {
|
||||
result = -30000001;
|
||||
}
|
||||
|
||||
if (result > max) {
|
||||
result = -30000001;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(String input) {
|
||||
return input.equalsIgnoreCase("tp");
|
||||
|
@@ -38,6 +38,26 @@ public abstract class VanillaCommand extends Command {
|
||||
return i;
|
||||
}
|
||||
|
||||
public static double getDouble(CommandSender sender, String input) {
|
||||
try {
|
||||
return Double.parseDouble(input);
|
||||
} catch (NumberFormatException ex) {
|
||||
return -30000001;
|
||||
}
|
||||
}
|
||||
|
||||
public static double getDouble(CommandSender sender, String input, double min, double max) {
|
||||
double result = getDouble(sender, input);
|
||||
|
||||
if (result < min) {
|
||||
result = min;
|
||||
} else if (result > max) {
|
||||
result = max;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected String createString(String[] args, int start) {
|
||||
StringBuilder string = new StringBuilder();
|
||||
|
||||
|
Reference in New Issue
Block a user