From 96281f6c76a885e57e917a25582e8d5b60f3b83e Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 26 Jan 2013 13:45:09 -0600 Subject: [PATCH] Fix invalid integers in spawnpoint command. Fixes BUKKIT-3509 getInteger returns min value on illegal number formats, so we change behavior to throw an exception when requested. By: feildmaster --- .../bukkit/command/defaults/SpawnpointCommand.java | 12 +++++++++--- .../org/bukkit/command/defaults/VanillaCommand.java | 12 ++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java b/paper-api/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java index d58054dd6c..4214bee03d 100644 --- a/paper-api/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/command/defaults/VanillaCommand.java b/paper-api/src/main/java/org/bukkit/command/defaults/VanillaCommand.java index 7908836361..997cb39c24 100644 --- a/paper-api/src/main/java/org/bukkit/command/defaults/VanillaCommand.java +++ b/paper-api/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;