aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0799-Pass-ServerLevel-for-gamerule-callbacks.patch
blob: aaf785c1073b8d4f2ef61b64e07d2dda6676a4a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Sun, 27 Mar 2022 13:51:09 -0400
Subject: [PATCH] Pass ServerLevel for gamerule callbacks


diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index c7894892afe97eb3cb453c37a2d9a23d811d70b8..2d06a8f85c5e29688aa0fd4726fd576721535384 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -304,7 +304,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
 
             //DedicatedServer.LOGGER.info("Done ({})! For help, type \"help\"", s); // Paper moved to after init
             if (dedicatedserverproperties.announcePlayerAchievements != null) {
-                ((GameRules.BooleanValue) this.getGameRules().getRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)).set(dedicatedserverproperties.announcePlayerAchievements, this);
+                ((GameRules.BooleanValue) this.getGameRules().getRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)).set(dedicatedserverproperties.announcePlayerAchievements, null); // Paper
             }
 
             if (dedicatedserverproperties.enableQuery) {
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 43ee0a36ace19a29f4e63133462ffc63a88b38e4..bea158416ed6c13db633efb742153f7813df5540 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2751,7 +2751,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
                     this.player = this.server.getPlayerList().respawn(this.player, false, RespawnReason.DEATH);
                     if (this.server.isHardcore()) {
                         this.player.setGameMode(GameType.SPECTATOR, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.HARDCORE_DEATH, null); // Paper
-                        ((GameRules.BooleanValue) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server);
+                        ((GameRules.BooleanValue) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.player.serverLevel()); // Paper
                     }
                 }
                 break;
diff --git a/src/main/java/net/minecraft/world/level/GameRules.java b/src/main/java/net/minecraft/world/level/GameRules.java
index 2e240ad721928a9a68370114ba61c21884ef1472..1a72fc5368731be617f9cab72e9e756d5b2a27ee 100644
--- a/src/main/java/net/minecraft/world/level/GameRules.java
+++ b/src/main/java/net/minecraft/world/level/GameRules.java
@@ -51,7 +51,7 @@ public class GameRules {
     public static final GameRules.Key<GameRules.BooleanValue> RULE_SENDCOMMANDFEEDBACK = GameRules.register("sendCommandFeedback", GameRules.Category.CHAT, GameRules.BooleanValue.create(true));
     public static final GameRules.Key<GameRules.BooleanValue> RULE_REDUCEDDEBUGINFO = GameRules.register("reducedDebugInfo", GameRules.Category.MISC, GameRules.BooleanValue.create(false, (minecraftserver, gamerules_gameruleboolean) -> {
         int i = gamerules_gameruleboolean.get() ? 22 : 23;
-        Iterator iterator = minecraftserver.getPlayerList().getPlayers().iterator();
+        Iterator iterator = minecraftserver.players().iterator(); // Paper
 
         while (iterator.hasNext()) {
             ServerPlayer entityplayer = (ServerPlayer) iterator.next();
@@ -66,7 +66,7 @@ public class GameRules {
     public static final GameRules.Key<GameRules.IntegerValue> RULE_MAX_ENTITY_CRAMMING = GameRules.register("maxEntityCramming", GameRules.Category.MOBS, GameRules.IntegerValue.create(24));
     public static final GameRules.Key<GameRules.BooleanValue> RULE_WEATHER_CYCLE = GameRules.register("doWeatherCycle", GameRules.Category.UPDATES, GameRules.BooleanValue.create(true));
     public static final GameRules.Key<GameRules.BooleanValue> RULE_LIMITED_CRAFTING = GameRules.register("doLimitedCrafting", GameRules.Category.PLAYER, GameRules.BooleanValue.create(false, (minecraftserver, gamerules_gameruleboolean) -> {
-        Iterator iterator = minecraftserver.getPlayerList().getPlayers().iterator();
+        Iterator iterator = minecraftserver.players().iterator(); // Paper
 
         while (iterator.hasNext()) {
             ServerPlayer entityplayer = (ServerPlayer) iterator.next();
@@ -81,7 +81,7 @@ public class GameRules {
     public static final GameRules.Key<GameRules.BooleanValue> RULE_DISABLE_RAIDS = GameRules.register("disableRaids", GameRules.Category.MOBS, GameRules.BooleanValue.create(false));
     public static final GameRules.Key<GameRules.BooleanValue> RULE_DOINSOMNIA = GameRules.register("doInsomnia", GameRules.Category.SPAWNING, GameRules.BooleanValue.create(true));
     public static final GameRules.Key<GameRules.BooleanValue> RULE_DO_IMMEDIATE_RESPAWN = GameRules.register("doImmediateRespawn", GameRules.Category.PLAYER, GameRules.BooleanValue.create(false, (minecraftserver, gamerules_gameruleboolean) -> {
-        Iterator iterator = minecraftserver.getPlayerList().getPlayers().iterator();
+        Iterator iterator = minecraftserver.players().iterator(); // Paper
 
         while (iterator.hasNext()) {
             ServerPlayer entityplayer = (ServerPlayer) iterator.next();
@@ -176,13 +176,13 @@ public class GameRules {
         ((GameRules.Type<T>) type).callVisitor(consumer, (GameRules.Key<T>) key); // CraftBukkit - decompile error
     }
 
-    public void assignFrom(GameRules rules, @Nullable MinecraftServer server) {
+    public void assignFrom(GameRules rules, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper
         rules.rules.keySet().forEach((gamerules_gamerulekey) -> {
             this.assignCap(gamerules_gamerulekey, rules, server);
         });
     }
 
-    private <T extends GameRules.Value<T>> void assignCap(GameRules.Key<T> key, GameRules rules, @Nullable MinecraftServer server) {
+    private <T extends GameRules.Value<T>> void assignCap(GameRules.Key<T> key, GameRules rules, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper
         T t0 = rules.getRule(key);
 
         this.getRule(key).setFrom(t0, server);
@@ -250,10 +250,10 @@ public class GameRules {
 
         private final Supplier<ArgumentType<?>> argument;
         private final Function<GameRules.Type<T>, T> constructor;
-        final BiConsumer<MinecraftServer, T> callback;
+        final BiConsumer<net.minecraft.server.level.ServerLevel, T> callback; // Paper
         private final GameRules.VisitorCaller<T> visitorCaller;
 
-        Type(Supplier<ArgumentType<?>> argumentType, Function<GameRules.Type<T>, T> ruleFactory, BiConsumer<MinecraftServer, T> changeCallback, GameRules.VisitorCaller<T> ruleAcceptor) {
+        Type(Supplier<ArgumentType<?>> argumentType, Function<GameRules.Type<T>, T> ruleFactory, BiConsumer<net.minecraft.server.level.ServerLevel, T> changeCallback, GameRules.VisitorCaller<T> ruleAcceptor) { // Paper
             this.argument = argumentType;
             this.constructor = ruleFactory;
             this.callback = changeCallback;
@@ -285,10 +285,10 @@ public class GameRules {
 
         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());
+            this.onChanged(((CommandSourceStack) context.getSource()).getLevel()); // Paper
         }
 
-        public void onChanged(@Nullable MinecraftServer server) {
+        public void onChanged(@Nullable net.minecraft.server.level.ServerLevel server) { // Paper
             if (server != null) {
                 this.type.callback.accept(server, this.getSelf());
             }
@@ -309,7 +309,7 @@ public class GameRules {
 
         protected abstract T copy();
 
-        public abstract void setFrom(T rule, @Nullable MinecraftServer server);
+        public abstract void setFrom(T rule, @Nullable net.minecraft.server.level.ServerLevel level); // Paper
     }
 
     public interface GameRuleTypeVisitor {
@@ -325,7 +325,7 @@ public class GameRules {
 
         private boolean value;
 
-        static GameRules.Type<GameRules.BooleanValue> create(boolean initialValue, BiConsumer<MinecraftServer, GameRules.BooleanValue> changeCallback) {
+        static GameRules.Type<GameRules.BooleanValue> create(boolean initialValue, BiConsumer<net.minecraft.server.level.ServerLevel, GameRules.BooleanValue> changeCallback) { // Paper
             return new GameRules.Type<>(BoolArgumentType::bool, (gamerules_gameruledefinition) -> {
                 return new GameRules.BooleanValue(gamerules_gameruledefinition, initialValue);
             }, changeCallback, GameRules.GameRuleTypeVisitor::visitBoolean);
@@ -353,7 +353,7 @@ public class GameRules {
             return this.value;
         }
 
-        public void set(boolean value, @Nullable MinecraftServer server) {
+        public void set(boolean value, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper
             this.value = value;
             this.onChanged(server);
         }
@@ -383,7 +383,7 @@ public class GameRules {
             return new GameRules.BooleanValue(this.type, this.value);
         }
 
-        public void setFrom(GameRules.BooleanValue rule, @Nullable MinecraftServer server) {
+        public void setFrom(GameRules.BooleanValue rule, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper
             this.value = rule.value;
             this.onChanged(server);
         }
@@ -393,7 +393,7 @@ public class GameRules {
 
         private int value;
 
-        private static GameRules.Type<GameRules.IntegerValue> create(int initialValue, BiConsumer<MinecraftServer, GameRules.IntegerValue> changeCallback) {
+        private static GameRules.Type<GameRules.IntegerValue> create(int initialValue, BiConsumer<net.minecraft.server.level.ServerLevel, GameRules.IntegerValue> changeCallback) { // Paper
             return new GameRules.Type<>(IntegerArgumentType::integer, (gamerules_gameruledefinition) -> {
                 return new GameRules.IntegerValue(gamerules_gameruledefinition, initialValue);
             }, changeCallback, GameRules.GameRuleTypeVisitor::visitInteger);
@@ -421,7 +421,7 @@ public class GameRules {
             return this.value;
         }
 
-        public void set(int value, @Nullable MinecraftServer server) {
+        public void set(int value, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper
             this.value = value;
             this.onChanged(server);
         }
@@ -472,7 +472,7 @@ public class GameRules {
             return new GameRules.IntegerValue(this.type, this.value);
         }
 
-        public void setFrom(GameRules.IntegerValue rule, @Nullable MinecraftServer server) {
+        public void setFrom(GameRules.IntegerValue rule, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper
             this.value = rule.value;
             this.onChanged(server);
         }
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index b964c5e81422a90f605191e2822ece425679396b..c5b6957aca67739a2d265ca985a0cc5b35c9c1e6 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1950,7 +1950,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
         // Paper end
         GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule));
         handle.deserialize(event.getValue()); // Paper
-        handle.onChanged(this.getHandle().getServer());
+        handle.onChanged(this.getHandle()); // Paper
         return true;
     }
 
@@ -1991,7 +1991,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
         // Paper end
         GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule.getName()));
         handle.deserialize(event.getValue()); // Paper
-        handle.onChanged(this.getHandle().getServer());
+        handle.onChanged(this.getHandle()); // Paper
         return true;
     }