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 3cc0aa9fa1ba11d85ce07013de86ad6f89c52f67..46708de7fac39928f52119343fc05cb877235b05 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); 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 - Pass ServerLevel for gamerule callbacks } 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 a5f4bc0160b073c0551107b382889031fed24d52..a08cf32d56b6f5491d2f2e8e9486a5d65ec9a825 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -2682,7 +2682,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 - Expand PlayerGameModeChangeEvent - ((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 - Pass ServerLevel for gamerule callbacks } } break; diff --git a/src/main/java/net/minecraft/world/level/GameRules.java b/src/main/java/net/minecraft/world/level/GameRules.java index f3cdf1fa7731eb7bb1cb89aa6a37204d81257cb0..0112ef51815c4fab38b95d5e917d335eeaaa21cd 100644 --- a/src/main/java/net/minecraft/world/level/GameRules.java +++ b/src/main/java/net/minecraft/world/level/GameRules.java @@ -52,7 +52,7 @@ public class GameRules { public static final GameRules.Key RULE_SENDCOMMANDFEEDBACK = GameRules.register("sendCommandFeedback", GameRules.Category.CHAT, GameRules.BooleanValue.create(true)); public static final GameRules.Key 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 - Pass ServerLevel for gamerule callbacks while (iterator.hasNext()) { ServerPlayer entityplayer = (ServerPlayer) iterator.next(); @@ -67,7 +67,7 @@ public class GameRules { public static final GameRules.Key RULE_MAX_ENTITY_CRAMMING = GameRules.register("maxEntityCramming", GameRules.Category.MOBS, GameRules.IntegerValue.create(24)); public static final GameRules.Key RULE_WEATHER_CYCLE = GameRules.register("doWeatherCycle", GameRules.Category.UPDATES, GameRules.BooleanValue.create(true)); public static final GameRules.Key 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 - Pass ServerLevel for gamerule callbacks while (iterator.hasNext()) { ServerPlayer entityplayer = (ServerPlayer) iterator.next(); @@ -83,7 +83,7 @@ public class GameRules { public static final GameRules.Key RULE_DISABLE_RAIDS = GameRules.register("disableRaids", GameRules.Category.MOBS, GameRules.BooleanValue.create(false)); public static final GameRules.Key RULE_DOINSOMNIA = GameRules.register("doInsomnia", GameRules.Category.SPAWNING, GameRules.BooleanValue.create(true)); public static final GameRules.Key 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 - Pass ServerLevel for gamerule callbacks while (iterator.hasNext()) { ServerPlayer entityplayer = (ServerPlayer) iterator.next(); @@ -180,13 +180,13 @@ public class GameRules { ((GameRules.Type) type).callVisitor(consumer, (GameRules.Key) 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 - Pass ServerLevel for gamerule callbacks rules.rules.keySet().forEach((gamerules_gamerulekey) -> { this.assignCap(gamerules_gamerulekey, rules, server); }); } - private > void assignCap(GameRules.Key key, GameRules rules, @Nullable MinecraftServer server) { + private > void assignCap(GameRules.Key key, GameRules rules, @Nullable net.minecraft.server.level.ServerLevel server) { // Paper - Pass ServerLevel for gamerule callbacks T t0 = rules.getRule(key); this.getRule(key).setFrom(t0, server); @@ -254,10 +254,10 @@ public class GameRules { private final Supplier> argument; private final Function, T> constructor; - final BiConsumer callback; + final BiConsumer callback; // Paper - Pass ServerLevel for gamerule callbacks private final GameRules.VisitorCaller visitorCaller; - Type(Supplier> argumentType, Function, T> ruleFactory, BiConsumer changeCallback, GameRules.VisitorCaller ruleAcceptor) { + Type(Supplier> argumentType, Function, T> ruleFactory, BiConsumer changeCallback, GameRules.VisitorCaller ruleAcceptor) { // Paper - Pass ServerLevel for gamerule callbacks this.argument = argumentType; this.constructor = ruleFactory; this.callback = changeCallback; @@ -289,10 +289,10 @@ public class GameRules { public void setFromArgument(CommandContext context, String name, GameRules.Key gameRuleKey) { // Paper - Add WorldGameRuleChangeEvent this.updateFromArgument(context, name, gameRuleKey); // Paper - Add WorldGameRuleChangeEvent - this.onChanged(((CommandSourceStack) context.getSource()).getServer()); + this.onChanged(((CommandSourceStack) context.getSource()).getLevel()); // Paper - Pass ServerLevel for gamerule callbacks } - public void onChanged(@Nullable MinecraftServer server) { + public void onChanged(@Nullable net.minecraft.server.level.ServerLevel server) { // Paper - Pass ServerLevel for gamerule callbacks if (server != null) { this.type.callback.accept(server, this.getSelf()); } @@ -313,7 +313,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 - Pass ServerLevel for gamerule callbacks } public interface GameRuleTypeVisitor { @@ -329,7 +329,7 @@ public class GameRules { private boolean value; - static GameRules.Type create(boolean initialValue, BiConsumer changeCallback) { + static GameRules.Type create(boolean initialValue, BiConsumer changeCallback) { // Paper - Pass ServerLevel for gamerule callbacks return new GameRules.Type<>(BoolArgumentType::bool, (gamerules_gameruledefinition) -> { return new GameRules.BooleanValue(gamerules_gameruledefinition, initialValue); }, changeCallback, GameRules.GameRuleTypeVisitor::visitBoolean); @@ -357,7 +357,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 - Pass ServerLevel for gamerule callbacks this.value = value; this.onChanged(server); } @@ -387,7 +387,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 - Pass ServerLevel for gamerule callbacks this.value = rule.value; this.onChanged(server); } @@ -397,7 +397,7 @@ public class GameRules { private int value; - private static GameRules.Type create(int initialValue, BiConsumer changeCallback) { + private static GameRules.Type create(int initialValue, BiConsumer changeCallback) { // Paper - Pass ServerLevel for gamerule callbacks return new GameRules.Type<>(IntegerArgumentType::integer, (gamerules_gameruledefinition) -> { return new GameRules.IntegerValue(gamerules_gameruledefinition, initialValue); }, changeCallback, GameRules.GameRuleTypeVisitor::visitInteger); @@ -425,7 +425,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 - Pass ServerLevel for gamerule callbacks this.value = value; this.onChanged(server); } @@ -476,7 +476,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 - Pass ServerLevel for gamerule callbacks 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 98a32754545bc8d27f3a10e8509c529e02bedee9..561ed3b93ba09f17f0f263b90993a7b13ce3f468 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1988,7 +1988,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { // Paper end - Add WorldGameRuleChangeEvent GameRules.Value handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule)); handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent - handle.onChanged(this.getHandle().getServer()); + handle.onChanged(this.getHandle()); // Paper - Pass ServerLevel for gamerule callbacks return true; } @@ -2029,7 +2029,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { // Paper end - Add WorldGameRuleChangeEvent GameRules.Value handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule.getName())); handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent - handle.onChanged(this.getHandle().getServer()); + handle.onChanged(this.getHandle()); // Paper - Pass ServerLevel for gamerule callbacks return true; }