From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sun, 20 Dec 2020 16:41:44 -0800 Subject: [PATCH] Added WorldGameRuleChangeEvent diff --git a/src/main/java/net/minecraft/server/commands/GameRuleCommand.java b/src/main/java/net/minecraft/server/commands/GameRuleCommand.java index 1b66c33a55a9516269c80f5052fb103418b11367..745b8724b7536a5b2c2c94ae8fd703ea755e8072 100644 --- a/src/main/java/net/minecraft/server/commands/GameRuleCommand.java +++ b/src/main/java/net/minecraft/server/commands/GameRuleCommand.java @@ -33,7 +33,7 @@ public class GameRuleCommand { CommandSourceStack commandlistenerwrapper = (CommandSourceStack) context.getSource(); T t0 = commandlistenerwrapper.getLevel().getGameRules().getRule(key); // CraftBukkit - t0.setFromArgument(context, "value"); + t0.setFromArgument(context, "value", key); // Paper commandlistenerwrapper.sendSuccess(Component.translatable("commands.gamerule.set", key.getId(), t0.toString()), true); return t0.getCommandResult(); } diff --git a/src/main/java/net/minecraft/world/level/GameRules.java b/src/main/java/net/minecraft/world/level/GameRules.java index 4a0321f56ef80aa4991e61f586ddd3f6b45e499b..de713f1ca1d61a6b1fca2b66de9162556d102449 100644 --- a/src/main/java/net/minecraft/world/level/GameRules.java +++ b/src/main/java/net/minecraft/world/level/GameRules.java @@ -271,10 +271,10 @@ public class GameRules { this.type = type; } - protected abstract void updateFromArgument(CommandContext context, String name); + protected abstract void updateFromArgument(CommandContext context, String name, GameRules.Key gameRuleKey); // Paper - public void setFromArgument(CommandContext context, String name) { - this.updateFromArgument(context, name); + public void setFromArgument(CommandContext context, String name, GameRules.Key gameRuleKey) { // Paper + this.updateFromArgument(context, name, gameRuleKey); // Paper this.onChanged(((CommandSourceStack) context.getSource()).getServer()); } @@ -332,8 +332,11 @@ public class GameRules { } @Override - protected void updateFromArgument(CommandContext context, String name) { - this.value = BoolArgumentType.getBool(context, name); + protected void updateFromArgument(CommandContext context, String name, GameRules.Key gameRuleKey) { // Paper start + io.papermc.paper.event.world.WorldGameRuleChangeEvent event = new io.papermc.paper.event.world.WorldGameRuleChangeEvent(context.getSource().getBukkitWorld(), context.getSource().getBukkitSender(), (org.bukkit.GameRule) org.bukkit.GameRule.getByName(gameRuleKey.toString()), String.valueOf(BoolArgumentType.getBool(context, name))); + if (!event.callEvent()) return; + this.value = Boolean.parseBoolean(event.getValue()); + // Paper end } public boolean get() { @@ -397,8 +400,11 @@ public class GameRules { } @Override - protected void updateFromArgument(CommandContext context, String name) { - this.value = IntegerArgumentType.getInteger(context, name); + protected void updateFromArgument(CommandContext context, String name, GameRules.Key gameRuleKey) { // Paper start + io.papermc.paper.event.world.WorldGameRuleChangeEvent event = new io.papermc.paper.event.world.WorldGameRuleChangeEvent(context.getSource().getBukkitWorld(), context.getSource().getBukkitSender(), (org.bukkit.GameRule) org.bukkit.GameRule.getByName(gameRuleKey.toString()), String.valueOf(IntegerArgumentType.getInteger(context, name))); + if (!event.callEvent()) return; + this.value = Integer.parseInt(event.getValue()); + // Paper end } public int get() { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 69187c3809369cf2dbe15a0f99e510e762f682d2..5c8270adf72114263d4e7b212201a7ea24bc95ae 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1839,8 +1839,13 @@ public class CraftWorld extends CraftRegionAccessor implements World { if (!this.isGameRule(rule)) return false; + // Paper start + GameRule gameRule = GameRule.getByName(rule); + io.papermc.paper.event.world.WorldGameRuleChangeEvent event = new io.papermc.paper.event.world.WorldGameRuleChangeEvent(this, null, gameRule, value); + if (!event.callEvent()) return false; + // Paper end GameRules.Value handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule)); - handle.deserialize(value); + handle.deserialize(event.getValue()); // Paper handle.onChanged(this.getHandle().getServer()); return true; } @@ -1875,8 +1880,12 @@ public class CraftWorld extends CraftRegionAccessor implements World { if (!this.isGameRule(rule.getName())) return false; + // Paper start + io.papermc.paper.event.world.WorldGameRuleChangeEvent event = new io.papermc.paper.event.world.WorldGameRuleChangeEvent(this, null, rule, String.valueOf(newValue)); + if (!event.callEvent()) return false; + // Paper end GameRules.Value handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule.getName())); - handle.deserialize(newValue.toString()); + handle.deserialize(event.getValue()); // Paper handle.onChanged(this.getHandle().getServer()); return true; }