2022-04-18 11:46:21 +02:00
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
2024-01-24 15:57:53 +01:00
index c39b19bee3aca093a2087e19875a50ff21cf1ab3..8d7d5cadbd65833d46dce71609e938290c81f772 100644
2022-04-18 11:46:21 +02:00
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2022-12-07 22:35:34 +01:00
@@ -304,7 +304,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2022-04-18 11:46:21 +02:00
2024-01-23 12:06:27 +01:00
DedicatedServer.LOGGER.info("Done ({})! For help, type \"help\"", s);
2022-04-18 11:46:21 +02:00
if (dedicatedserverproperties.announcePlayerAchievements != null) {
- ((GameRules.BooleanValue) this.getGameRules().getRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)).set(dedicatedserverproperties.announcePlayerAchievements, this);
2024-01-18 18:52:00 +01:00
+ ((GameRules.BooleanValue) this.getGameRules().getRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)).set(dedicatedserverproperties.announcePlayerAchievements, null); // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
}
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
2024-01-24 15:57:53 +01:00
index ff3fc822898a6a9d1eb15be3881faab8a1d9016e..b84d748953e03f1852c4edf3d8d9466f2bce67c6 100644
2022-04-18 11:46:21 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-01-24 15:57:53 +01:00
@@ -2675,7 +2675,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-04-10 10:03:36 +02:00
this.player = this.server.getPlayerList().respawn(this.player, false, RespawnReason.DEATH);
2022-04-18 11:46:21 +02:00
if (this.server.isHardcore()) {
2024-01-19 17:54:05 +01:00
this.player.setGameMode(GameType.SPECTATOR, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.HARDCORE_DEATH, null); // Paper - Expand PlayerGameModeChangeEvent
2023-06-08 10:47:19 +02:00
- ((GameRules.BooleanValue) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server);
2024-01-18 18:52:00 +01:00
+ ((GameRules.BooleanValue) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.player.serverLevel()); // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
}
}
break;
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 f3cdf1fa7731eb7bb1cb89aa6a37204d81257cb0..0112ef51815c4fab38b95d5e917d335eeaaa21cd 100644
2022-04-18 11:46:21 +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 17:00:26 +01:00
@@ -52,7 +52,7 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
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();
2024-01-18 18:52:00 +01:00
+ Iterator iterator = minecraftserver.players().iterator(); // Paper - Pass ServerLevel for gamerule callbacks
2023-09-22 19:43:52 +02:00
while (iterator.hasNext()) {
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
2023-12-06 17:00:26 +01:00
@@ -67,7 +67,7 @@ public class GameRules {
2023-09-22 19:43:52 +02:00
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();
2024-01-18 18:52:00 +01:00
+ Iterator iterator = minecraftserver.players().iterator(); // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
while (iterator.hasNext()) {
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
2023-12-06 17:00:26 +01:00
@@ -83,7 +83,7 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
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();
2024-01-18 18:52:00 +01:00
+ Iterator iterator = minecraftserver.players().iterator(); // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
while (iterator.hasNext()) {
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
2023-12-06 17:00:26 +01:00
@@ -180,13 +180,13 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
((GameRules.Type<T>) type).callVisitor(consumer, (GameRules.Key<T>) key); // CraftBukkit - decompile error
}
- public void assignFrom(GameRules rules, @Nullable MinecraftServer server) {
2024-01-18 18:52:00 +01:00
+ public void assignFrom(GameRules rules, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
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) {
2024-01-18 18:52:00 +01:00
+ private <T extends GameRules.Value<T>> void assignCap(GameRules.Key<T> key, GameRules rules, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
T t0 = rules.getRule(key);
this.getRule(key).setFrom(t0, server);
2023-12-06 17:00:26 +01:00
@@ -254,10 +254,10 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
private final Supplier<ArgumentType<?>> argument;
private final Function<GameRules.Type<T>, T> constructor;
- final BiConsumer<MinecraftServer, T> callback;
2024-01-18 18:52:00 +01:00
+ final BiConsumer<net.minecraft.server.level.ServerLevel, T> callback; // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
private final GameRules.VisitorCaller<T> visitorCaller;
- Type(Supplier<ArgumentType<?>> argumentType, Function<GameRules.Type<T>, T> ruleFactory, BiConsumer<MinecraftServer, T> changeCallback, GameRules.VisitorCaller<T> ruleAcceptor) {
2024-01-18 18:52:00 +01:00
+ Type(Supplier<ArgumentType<?>> argumentType, Function<GameRules.Type<T>, T> ruleFactory, BiConsumer<net.minecraft.server.level.ServerLevel, T> changeCallback, GameRules.VisitorCaller<T> ruleAcceptor) { // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
this.argument = argumentType;
this.constructor = ruleFactory;
this.callback = changeCallback;
2023-12-06 17:00:26 +01:00
@@ -289,10 +289,10 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
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
2022-04-18 11:46:21 +02:00
- this.onChanged(((CommandSourceStack) context.getSource()).getServer());
2024-01-18 18:52:00 +01:00
+ this.onChanged(((CommandSourceStack) context.getSource()).getLevel()); // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
}
- public void onChanged(@Nullable MinecraftServer server) {
2024-01-18 18:52:00 +01:00
+ public void onChanged(@Nullable net.minecraft.server.level.ServerLevel server) { // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
if (server != null) {
this.type.callback.accept(server, this.getSelf());
}
2023-12-06 17:00:26 +01:00
@@ -313,7 +313,7 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
protected abstract T copy();
- public abstract void setFrom(T rule, @Nullable MinecraftServer server);
2024-01-18 18:52:00 +01:00
+ public abstract void setFrom(T rule, @Nullable net.minecraft.server.level.ServerLevel level); // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
}
public interface GameRuleTypeVisitor {
2023-12-06 17:00:26 +01:00
@@ -329,7 +329,7 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
private boolean value;
- static GameRules.Type<GameRules.BooleanValue> create(boolean initialValue, BiConsumer<MinecraftServer, GameRules.BooleanValue> changeCallback) {
2024-01-18 18:52:00 +01:00
+ static GameRules.Type<GameRules.BooleanValue> create(boolean initialValue, BiConsumer<net.minecraft.server.level.ServerLevel, GameRules.BooleanValue> changeCallback) { // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
return new GameRules.Type<>(BoolArgumentType::bool, (gamerules_gameruledefinition) -> {
return new GameRules.BooleanValue(gamerules_gameruledefinition, initialValue);
}, changeCallback, GameRules.GameRuleTypeVisitor::visitBoolean);
2023-12-06 17:00:26 +01:00
@@ -357,7 +357,7 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
return this.value;
}
- public void set(boolean value, @Nullable MinecraftServer server) {
2024-01-18 18:52:00 +01:00
+ public void set(boolean value, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
this.value = value;
this.onChanged(server);
}
2023-12-06 17:00:26 +01:00
@@ -387,7 +387,7 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
return new GameRules.BooleanValue(this.type, this.value);
}
- public void setFrom(GameRules.BooleanValue rule, @Nullable MinecraftServer server) {
2024-01-18 18:52:00 +01:00
+ public void setFrom(GameRules.BooleanValue rule, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
this.value = rule.value;
this.onChanged(server);
}
2023-12-06 17:00:26 +01:00
@@ -397,7 +397,7 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
private int value;
- private static GameRules.Type<GameRules.IntegerValue> create(int initialValue, BiConsumer<MinecraftServer, GameRules.IntegerValue> changeCallback) {
2024-01-18 18:52:00 +01:00
+ private static GameRules.Type<GameRules.IntegerValue> create(int initialValue, BiConsumer<net.minecraft.server.level.ServerLevel, GameRules.IntegerValue> changeCallback) { // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
return new GameRules.Type<>(IntegerArgumentType::integer, (gamerules_gameruledefinition) -> {
return new GameRules.IntegerValue(gamerules_gameruledefinition, initialValue);
}, changeCallback, GameRules.GameRuleTypeVisitor::visitInteger);
2023-12-06 17:00:26 +01:00
@@ -425,7 +425,7 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
return this.value;
}
- public void set(int value, @Nullable MinecraftServer server) {
2024-01-18 18:52:00 +01:00
+ public void set(int value, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
this.value = value;
this.onChanged(server);
}
2023-12-06 17:00:26 +01:00
@@ -476,7 +476,7 @@ public class GameRules {
2022-04-18 11:46:21 +02:00
return new GameRules.IntegerValue(this.type, this.value);
}
- public void setFrom(GameRules.IntegerValue rule, @Nullable MinecraftServer server) {
2024-01-18 18:52:00 +01:00
+ public void setFrom(GameRules.IntegerValue rule, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
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
2024-01-25 10:54:46 +01:00
index 5e2a1a4bd047b6eb1581ce6e6d9b0f78be64c448..12013237e7b00f47d2a8660fd09ee3d52fdf084c 100644
2022-04-18 11:46:21 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2024-01-25 10:54:46 +01:00
@@ -1966,7 +1966,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
2024-01-19 22:13:42 +01:00
// Paper end - Add WorldGameRuleChangeEvent
2022-04-18 11:46:21 +02:00
GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule));
2024-01-19 22:13:42 +01:00
handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent
2022-04-18 11:46:21 +02:00
- handle.onChanged(this.getHandle().getServer());
2024-01-18 18:52:00 +01:00
+ handle.onChanged(this.getHandle()); // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
return true;
}
2024-01-25 10:54:46 +01:00
@@ -2007,7 +2007,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
2024-01-19 22:13:42 +01:00
// Paper end - Add WorldGameRuleChangeEvent
2022-04-18 11:46:21 +02:00
GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule.getName()));
2024-01-19 22:13:42 +01:00
handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent
2022-04-18 11:46:21 +02:00
- handle.onChanged(this.getHandle().getServer());
2024-01-18 18:52:00 +01:00
+ handle.onChanged(this.getHandle()); // Paper - Pass ServerLevel for gamerule callbacks
2022-04-18 11:46:21 +02:00
return true;
}