Clamp difficulty levels to prevent invalid values

Some features added in 1.4.2 use the difficulty value as an index to an
array so while before having it set to an invalid value would do nothing
or maybe cause an odd side effect somewhere it now crashes the server. This
patch ensures difficulty values are clamped between 0 and 3, inclusive.
This commit is contained in:
Travis Watkins 2012-10-28 10:07:11 -05:00
parent 37a0d6757d
commit 0fb806c566

View File

@ -182,7 +182,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
}
public int getDifficulty() {
return this.propertyManager.getInt("difficulty", 1);
return Math.max(0, Math.min(3, this.propertyManager.getInt("difficulty", 1))); // CraftBukkit - clamp values
}
public boolean isHardcore() {