geforkt von Mirrors/Paper
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 <admin@feildmaster.com>
Dieser Commit ist enthalten in:
Ursprung
0ffcec85cb
Commit
96281f6c76
@ -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);
|
||||
|
@ -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;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren