From 0fb806c566594317df6b14ab13c825db88eba60f Mon Sep 17 00:00:00 2001 From: Travis Watkins Date: Sun, 28 Oct 2012 10:07:11 -0500 Subject: [PATCH] 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. --- src/main/java/net/minecraft/server/DedicatedServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java index 0c74861453..4bf7f9c82b 100644 --- a/src/main/java/net/minecraft/server/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/DedicatedServer.java @@ -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() {