mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 08:47:35 +01:00
Replace 'Magic Numbers' in commands.
These numbers are mirrored in vanilla code as the coordinate limits for a world. Replaced usages to a static final member for code readability. By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
parent
80c98cb5d4
commit
cc865ea15c
@ -6,7 +6,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -47,10 +46,9 @@ public class SpawnpointCommand extends VanillaCommand {
|
||||
if (args.length == 4) {
|
||||
if (world != null) {
|
||||
int pos = 1;
|
||||
int maxPos = 30000000;
|
||||
int x = getInteger(sender, args[pos++], -maxPos, maxPos);
|
||||
int x = getInteger(sender, args[pos++], MIN_COORD, MAX_COORD);
|
||||
int y = getInteger(sender, args[pos++], 0, world.getMaxHeight());
|
||||
int z = getInteger(sender, args[pos], -maxPos, maxPos);
|
||||
int z = getInteger(sender, args[pos], MIN_COORD, MAX_COORD);
|
||||
|
||||
player.setBedSpawnLocation(new Location(world, x, y, z), true);
|
||||
sender.sendMessage("Set " + player.getDisplayName() + "'s spawnpoint to " + x + ", " + y + ", " + z);
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class TeleportCommand extends VanillaCommand {
|
||||
|
||||
public TeleportCommand() {
|
||||
super("tp");
|
||||
this.description = "Teleports the given player to another player or location";
|
||||
@ -60,7 +61,7 @@ public class TeleportCommand extends VanillaCommand {
|
||||
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) {
|
||||
if (x == MIN_COORD_MINUS_ONE || y == MIN_COORD_MINUS_ONE || z == MIN_COORD_MINUS_ONE) {
|
||||
sender.sendMessage("Please provide a valid location!");
|
||||
return true;
|
||||
}
|
||||
@ -73,7 +74,7 @@ public class TeleportCommand extends VanillaCommand {
|
||||
}
|
||||
|
||||
private double getCoordinate(CommandSender sender, double current, String input) {
|
||||
return getCoordinate(sender, current, input, -30000000, 30000000);
|
||||
return getCoordinate(sender, current, input, MIN_COORD, MAX_COORD);
|
||||
}
|
||||
|
||||
private double getCoordinate(CommandSender sender, double current, String input, int min, int max) {
|
||||
@ -85,8 +86,8 @@ public class TeleportCommand extends VanillaCommand {
|
||||
if (relative) input = input.substring(1);
|
||||
|
||||
double testResult = getDouble(sender, input);
|
||||
if (testResult == -30000001) {
|
||||
return -30000001;
|
||||
if (testResult == MIN_COORD_MINUS_ONE) {
|
||||
return MIN_COORD_MINUS_ONE;
|
||||
}
|
||||
result += testResult;
|
||||
|
||||
@ -94,11 +95,11 @@ public class TeleportCommand extends VanillaCommand {
|
||||
}
|
||||
if (min != 0 || max != 0) {
|
||||
if (result < min) {
|
||||
result = -30000001;
|
||||
result = MIN_COORD_MINUS_ONE;
|
||||
}
|
||||
|
||||
if (result > max) {
|
||||
result = -30000001;
|
||||
result = MIN_COORD_MINUS_ONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,10 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public abstract class VanillaCommand extends Command {
|
||||
static final int MAX_COORD = 30000000;
|
||||
static final int MIN_COORD_MINUS_ONE = -30000001;
|
||||
static final int MIN_COORD = -30000000;
|
||||
|
||||
protected VanillaCommand(String name) {
|
||||
super(name);
|
||||
}
|
||||
@ -42,7 +46,7 @@ public abstract class VanillaCommand extends Command {
|
||||
try {
|
||||
return Double.parseDouble(input);
|
||||
} catch (NumberFormatException ex) {
|
||||
return -30000001;
|
||||
return MIN_COORD_MINUS_ONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user