diff options
author | Wesley Wolfe <weswolf@aol.com> | 2012-10-31 04:16:50 -0500 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2012-10-31 04:19:11 -0500 |
commit | 4f7ded55db2a92fa1c7a8ea4d45d2a8332a4e749 (patch) | |
tree | ceb1d71d4f47f8f7d79b293a19c7400a81382d40 /src/main | |
parent | a94a0b209d1a7c43400bc657b053f793d009c3f9 (diff) | |
download | bukkit-4f7ded55db2a92fa1c7a8ea4d45d2a8332a4e749.tar bukkit-4f7ded55db2a92fa1c7a8ea4d45d2a8332a4e749.tar.gz bukkit-4f7ded55db2a92fa1c7a8ea4d45d2a8332a4e749.tar.lz bukkit-4f7ded55db2a92fa1c7a8ea4d45d2a8332a4e749.tar.xz bukkit-4f7ded55db2a92fa1c7a8ea4d45d2a8332a4e749.zip |
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.
Diffstat (limited to 'src/main')
3 files changed, 14 insertions, 11 deletions
diff --git a/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java b/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java index 50692157..02dcd4f7 100644 --- a/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java +++ b/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java @@ -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); diff --git a/src/main/java/org/bukkit/command/defaults/TeleportCommand.java b/src/main/java/org/bukkit/command/defaults/TeleportCommand.java index cbb42abe..2c2e11f0 100644 --- a/src/main/java/org/bukkit/command/defaults/TeleportCommand.java +++ b/src/main/java/org/bukkit/command/defaults/TeleportCommand.java @@ -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; } } diff --git a/src/main/java/org/bukkit/command/defaults/VanillaCommand.java b/src/main/java/org/bukkit/command/defaults/VanillaCommand.java index d762e64f..7b893bd9 100644 --- a/src/main/java/org/bukkit/command/defaults/VanillaCommand.java +++ b/src/main/java/org/bukkit/command/defaults/VanillaCommand.java @@ -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; } } |