2021-06-14 20:50:22 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
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
|
2022-06-08 09:30:41 +02:00
|
|
|
index 1b66c33a55a9516269c80f5052fb103418b11367..745b8724b7536a5b2c2c94ae8fd703ea755e8072 100644
|
2021-06-14 20:50:22 +02:00
|
|
|
--- 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
|
2022-06-08 09:30:41 +02:00
|
|
|
commandlistenerwrapper.sendSuccess(Component.translatable("commands.gamerule.set", key.getId(), t0.toString()), true);
|
2021-06-14 20:50:22 +02:00
|
|
|
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
|
2022-06-08 09:30:41 +02:00
|
|
|
index 800325a544bb9f228ccbeb0a52d7f380a8c6083e..3c93bfeb94168f832904a8462ae23b06e81e080d 100644
|
2021-06-14 20:50:22 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/GameRules.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/GameRules.java
|
2022-06-08 09:30:41 +02:00
|
|
|
@@ -262,10 +262,10 @@ public class GameRules {
|
2021-06-14 20:50:22 +02:00
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
- protected abstract void updateFromArgument(CommandContext<CommandSourceStack> context, String name);
|
|
|
|
+ protected abstract void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<T> gameRuleKey); // Paper
|
|
|
|
|
|
|
|
- public void setFromArgument(CommandContext<CommandSourceStack> context, String name) {
|
|
|
|
- this.updateFromArgument(context, name);
|
|
|
|
+ public void setFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<T> gameRuleKey) { // Paper
|
|
|
|
+ this.updateFromArgument(context, name, gameRuleKey); // Paper
|
|
|
|
this.onChanged(((CommandSourceStack) context.getSource()).getServer());
|
|
|
|
}
|
|
|
|
|
2022-06-08 09:30:41 +02:00
|
|
|
@@ -323,8 +323,11 @@ public class GameRules {
|
2021-06-14 20:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
- protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name) {
|
|
|
|
- this.value = BoolArgumentType.getBool(context, name);
|
|
|
|
+ protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<BooleanValue> 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<Boolean>) 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() {
|
2022-06-08 09:30:41 +02:00
|
|
|
@@ -388,8 +391,11 @@ public class GameRules {
|
2021-06-14 20:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
- protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name) {
|
|
|
|
- this.value = IntegerArgumentType.getInteger(context, name);
|
|
|
|
+ protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<IntegerValue> 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<Integer>) 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
|
2022-07-04 16:38:06 +02:00
|
|
|
index a04ae390f2d054b2ad9fb91eca04955471247b5a..da84c3106b9e6210e234585fdd9eb75e1db041f5 100644
|
2021-06-14 20:50:22 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2022-07-04 16:38:06 +02:00
|
|
|
@@ -1804,8 +1804,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-06-14 20:50:22 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2022-07-04 16:38:06 +02:00
|
|
|
@@ -1840,8 +1845,12 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-06-14 20:50:22 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|