Paper/patches/server/0513-Added-WorldGameRuleChangeEvent.patch
Nassim Jahnke e035fd7034
Updated Upstream (Bukkit/CraftBukkit/Spigot)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
cc9aa21a SPIGOT-6399, SPIGOT-7344: Clarify collidable behavior for player entities
f23325b6 Add API for per-world simulation distances
26e1774e Add API for per-world view distances
0b541e60 Add PlayerLoginEvent#getRealAddress
5f027d2d PR-949: Add Vector#fromJOML() overloads for read-only vector types

CraftBukkit Changes:
bcf56171a PR-1321: Clean up some stuff which got missed during previous PRs
7f833a2d1 SPIGOT-7462: Players no longer drop XP after dying near a Sculk Catalyst
752aac669 Implement APIs for per world view and simulation distances
57d7ef433 Preserve empty enchantment tags for glow effect
465ec3fb4 Remove connected check on setScoreboard
f90ce621e Use one PermissibleBase for all command blocks
5876cca44 SPIGOT-7550: Fix creation of Arrow instances
f03fc3aa3 SPIGOT-7549: ServerTickManager#setTickRate incorrect Precondition
9d7f49b01 SPIGOT-7548: Fix wrong spawn location for experience orb and dropped item

Spigot Changes:
ed9ba9a4 Drop no longer required patch ignoring -o option
86b5dd6a SPIGOT-7546: Fix hardcoded check for outdated client message
aa7cde7a Remove obsolete APIs for per world view and simulation distances
6dff577e Remove obsolete patch preserving empty `ench` tags
a3bf95b8 Remove obsolete PlayerLoginEvent#getRealAddress
1b02f5d6 Remove obsolete connected check on setScoreboard patch
acf717eb Remove obsolete command block PermissibleBase patch
053fa2a9 Remove redundant patch dealing with null tile entities
2023-12-26 00:18:13 +01:00

99 lines
5.8 KiB
Diff

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
index c8c358531dbc167e249bac2af246c5e34fbdd4df..307854468ac985560b4c63b6e9897c444a7b8a3a 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(() -> {
return Component.translatable("commands.gamerule.set", key.getId(), t0.toString());
}, true);
diff --git a/src/main/java/net/minecraft/world/level/GameRules.java b/src/main/java/net/minecraft/world/level/GameRules.java
index 334001cb749600c973c82391e1c11f0e40bd2dfb..2a480026c3bfb06e6556fe5b11d9712c8e02debe 100644
--- a/src/main/java/net/minecraft/world/level/GameRules.java
+++ b/src/main/java/net/minecraft/world/level/GameRules.java
@@ -285,10 +285,10 @@ public class GameRules {
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());
}
@@ -346,8 +346,11 @@ public class GameRules {
}
@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() {
@@ -411,8 +414,11 @@ public class GameRules {
}
@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
index 37726d7bf6e179130e7ce4f28c2a5d9a26d13c09..69dfd085369bdf0c0bd12b4cb6aa043af0159352 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1927,8 +1927,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;
}
@@ -1964,8 +1969,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;
}