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
|
2024-01-19 22:13:42 +01:00
|
|
|
Subject: [PATCH] Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/commands/GameRuleCommand.java b/src/main/java/net/minecraft/server/commands/GameRuleCommand.java
|
2024-01-19 22:13:42 +01:00
|
|
|
index c8c358531dbc167e249bac2af246c5e34fbdd4df..10c1790226e25da3b9b599c9a40de57d5727ddc4 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");
|
2024-01-19 22:13:42 +01:00
|
|
|
+ t0.setFromArgument(context, "value", key); // Paper - Add WorldGameRuleChangeEvent
|
2023-06-08 01:56:33 +02:00
|
|
|
commandlistenerwrapper.sendSuccess(() -> {
|
|
|
|
return Component.translatable("commands.gamerule.set", key.getId(), t0.toString());
|
|
|
|
}, true);
|
2021-06-14 20:50:22 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/GameRules.java b/src/main/java/net/minecraft/world/level/GameRules.java
|
2024-01-19 22:13:42 +01:00
|
|
|
index 334001cb749600c973c82391e1c11f0e40bd2dfb..f3cdf1fa7731eb7bb1cb89aa6a37204d81257cb0 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
|
2023-12-06 04:00:14 +01:00
|
|
|
@@ -285,10 +285,10 @@ public class GameRules {
|
2021-06-14 20:50:22 +02:00
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
- protected abstract void updateFromArgument(CommandContext<CommandSourceStack> context, String name);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ protected abstract void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<T> gameRuleKey); // Paper - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
|
|
|
|
- public void setFromArgument(CommandContext<CommandSourceStack> context, String name) {
|
|
|
|
- this.updateFromArgument(context, name);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ public void setFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<T> gameRuleKey) { // Paper - Add WorldGameRuleChangeEvent
|
|
|
|
+ this.updateFromArgument(context, name, gameRuleKey); // Paper - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
this.onChanged(((CommandSourceStack) context.getSource()).getServer());
|
|
|
|
}
|
|
|
|
|
2023-12-06 04:00:14 +01:00
|
|
|
@@ -346,8 +346,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);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<BooleanValue> gameRuleKey) { // Paper start - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
+ 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());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean get() {
|
2023-12-06 04:00:14 +01:00
|
|
|
@@ -411,8 +414,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);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<IntegerValue> gameRuleKey) { // Paper start - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
+ 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());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int get() {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2024-01-23 12:06:27 +01:00
|
|
|
index 705c1b2bba2b60b260c59a6953151f34cdfc8960..e092afa65bc6d14c53a09175b0a8cd9ad50a7477 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
|
2023-12-26 21:00:21 +01:00
|
|
|
@@ -1930,8 +1930,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-06-14 20:50:22 +02:00
|
|
|
|
|
|
|
if (!this.isGameRule(rule)) return false;
|
|
|
|
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper start - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
+ 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;
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule));
|
|
|
|
- handle.deserialize(value);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
handle.onChanged(this.getHandle().getServer());
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-26 21:00:21 +01:00
|
|
|
@@ -1967,8 +1972,12 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-06-14 20:50:22 +02:00
|
|
|
|
|
|
|
if (!this.isGameRule(rule.getName())) return false;
|
|
|
|
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper start - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
+ 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;
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule.getName()));
|
|
|
|
- handle.deserialize(newValue.toString());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
handle.onChanged(this.getHandle().getServer());
|
|
|
|
return true;
|
|
|
|
}
|