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 (args.length == 4) {
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
int pos = 1;
|
int pos = 1;
|
||||||
int x = getInteger(sender, args[pos++], MIN_COORD, MAX_COORD);
|
final int x, y, z;
|
||||||
int y = getInteger(sender, args[pos++], 0, world.getMaxHeight());
|
try {
|
||||||
int z = getInteger(sender, args[pos], MIN_COORD, MAX_COORD);
|
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);
|
player.setBedSpawnLocation(new Location(world, x, y, z), true);
|
||||||
Command.broadcastCommandMessage(sender, "Set " + player.getDisplayName() + "'s spawnpoint to " + x + ", " + y + ", " + z);
|
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);
|
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;
|
int i = min;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
i = Integer.valueOf(value);
|
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) {
|
if (i < min) {
|
||||||
i = min;
|
i = min;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren