diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java | 12 | ||||
-rw-r--r-- | src/main/java/org/bukkit/command/defaults/VanillaCommand.java | 12 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java b/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java index d58054dd..4214bee0 100644 --- a/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java +++ b/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java @@ -47,9 +47,15 @@ public class SpawnpointCommand extends VanillaCommand { if (args.length == 4) { if (world != null) { int pos = 1; - 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], MIN_COORD, MAX_COORD); + final int x, y, z; + try { + x = getInteger(sender, args[pos++], MIN_COORD, MAX_COORD, true); + y = getInteger(sender, args[pos++], 0, world.getMaxHeight()); + z = getInteger(sender, args[pos], MIN_COORD, MAX_COORD, true); + } catch(NumberFormatException ex) { + sender.sendMessage(ex.getMessage()); + return true; + } player.setBedSpawnLocation(new Location(world, x, y, z), true); Command.broadcastCommandMessage(sender, "Set " + player.getDisplayName() + "'s spawnpoint to " + x + ", " + y + ", " + z); diff --git a/src/main/java/org/bukkit/command/defaults/VanillaCommand.java b/src/main/java/org/bukkit/command/defaults/VanillaCommand.java index 79088363..997cb39c 100644 --- a/src/main/java/org/bukkit/command/defaults/VanillaCommand.java +++ b/src/main/java/org/bukkit/command/defaults/VanillaCommand.java @@ -26,12 +26,20 @@ public abstract class VanillaCommand extends Command { return getInteger(sender, value, min, Integer.MAX_VALUE); } - protected int getInteger(CommandSender sender, String value, int min, int max) { + int getInteger(CommandSender sender, String value, int min, int max) { + return getInteger(sender, value, min, max, false); + } + + int getInteger(CommandSender sender, String value, int min, int max, boolean Throws) { int i = min; try { i = Integer.valueOf(value); - } catch (NumberFormatException ex) {} + } catch (NumberFormatException ex) { + if (Throws) { + throw new NumberFormatException(String.format("%s is not a valid number", value)); + } + } if (i < min) { i = min; |