From 38fa220f698a5eb10df81ec9eef329fe051d6cbb Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 21 Jun 2019 20:35:22 +1000 Subject: [PATCH] Fix setting game rules via the API --- nms-patches/GameRules.patch | 64 +++++++++++++++++++ .../org/bukkit/craftbukkit/CraftWorld.java | 8 ++- 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 nms-patches/GameRules.patch diff --git a/nms-patches/GameRules.patch b/nms-patches/GameRules.patch new file mode 100644 index 0000000000..3b755ac9d5 --- /dev/null +++ b/nms-patches/GameRules.patch @@ -0,0 +1,64 @@ +--- a/net/minecraft/server/GameRules.java ++++ b/net/minecraft/server/GameRules.java +@@ -78,7 +78,7 @@ + } + + public > T get(GameRules.GameRuleKey gamerules_gamerulekey) { +- return (GameRules.GameRuleValue) this.A.get(gamerules_gamerulekey); ++ return (T) this.A.get(gamerules_gamerulekey); // CraftBukkit - decompile error + } + + public NBTTagCompound a() { +@@ -103,7 +103,7 @@ + } + + private static > void a(GameRules.GameRuleVisitor gamerules_gamerulevisitor, GameRules.GameRuleKey gamerules_gamerulekey, GameRules.GameRuleDefinition gamerules_gameruledefinition) { +- gamerules_gamerulevisitor.a(gamerules_gamerulekey, gamerules_gameruledefinition); ++ gamerules_gamerulevisitor.a((GameRules.GameRuleKey) gamerules_gamerulekey, (GameRules.GameRuleDefinition) gamerules_gameruledefinition); // CraftBukkit - decompile error + } + + public boolean getBoolean(GameRules.GameRuleKey gamerules_gamerulekey) { +@@ -154,7 +154,7 @@ + } + + @Override +- protected void setValue(String s) { ++ public void setValue(String s) { // PAIL - private->public + this.a = Boolean.parseBoolean(s); + } + +@@ -204,7 +204,7 @@ + } + + @Override +- protected void setValue(String s) { ++ public void setValue(String s) { // PAIL - private->public + this.a = b(s); + } + +@@ -246,14 +246,14 @@ + this.a(((CommandListenerWrapper) commandcontext.getSource()).getServer()); + } + +- protected void a(@Nullable MinecraftServer minecraftserver) { ++ public void a(@Nullable MinecraftServer minecraftserver) { // PAIL - private->public + if (minecraftserver != null) { + this.a.c.accept(minecraftserver, this.e()); + } + + } + +- protected abstract void setValue(String s); ++ public abstract void setValue(String s); // PAIL - private->public + + protected abstract String getValue(); + +@@ -283,7 +283,7 @@ + } + + public T a() { +- return (GameRules.GameRuleValue) this.b.apply(this); ++ return this.b.apply(this); // CraftBukkit - decompile error + } + } + diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index eb3e5426b5..b9cf667153 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1904,7 +1904,9 @@ public class CraftWorld implements World { if (!isGameRule(rule)) return false; - getHandle().getGameRules().get(getGameRulesNMS().get(rule)).b(null, value); + GameRules.GameRuleValue handle = getHandle().getGameRules().get(getGameRulesNMS().get(rule)); + handle.setValue(value); + handle.a(getHandle().getMinecraftServer()); return true; } @@ -1938,7 +1940,9 @@ public class CraftWorld implements World { if (!isGameRule(rule.getName())) return false; - getHandle().getGameRules().get(getGameRulesNMS().get(rule.getName())).b(null, newValue.toString()); + GameRules.GameRuleValue handle = getHandle().getGameRules().get(getGameRulesNMS().get(rule.getName())); + handle.setValue(newValue.toString()); + handle.a(getHandle().getMinecraftServer()); return true; }