From c2e2e77733b48dcb75015056ef1be20fcfe8ebcb Mon Sep 17 00:00:00 2001 From: rikka0w0 <929513338@qq.com> Date: Tue, 31 Dec 2024 22:08:59 +1100 Subject: [PATCH] /forceoffline add and remote are now effective immediately Previously, a server restart is required to update the list. Now, it works immediately, but only applicable to newly joined players. --- .../io/github/satxm/mcwifipnp/Config.java | 5 ++-- .../commands/ForceOfflineCommand.java | 27 +++++++++---------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/github/satxm/mcwifipnp/Config.java b/src/main/java/io/github/satxm/mcwifipnp/Config.java index fdea649..04570e9 100644 --- a/src/main/java/io/github/satxm/mcwifipnp/Config.java +++ b/src/main/java/io/github/satxm/mcwifipnp/Config.java @@ -22,7 +22,6 @@ import com.google.gson.annotations.SerializedName; import io.github.satxm.mcwifipnp.mixin.PlayerListAccessor; -import net.minecraft.client.server.IntegratedServer; import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; import net.minecraft.server.players.PlayerList; @@ -142,7 +141,7 @@ public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext } } - public void readFromRunningServer(IntegratedServer server) { + public void readFromRunningServer(MinecraftServer server) { PlayerList playerList = server.getPlayerList(); this.port = server.getPort(); @@ -160,7 +159,7 @@ public void readFromRunningServer(IntegratedServer server) { this.forcedOfflinePlayers = UUIDFixer.alwaysOfflinePlayers; } - public void applyTo(IntegratedServer server) { + public void applyTo(MinecraftServer server) { PlayerList playerList = server.getPlayerList(); server.setDefaultGameType(this.gameType); playerList.setAllowCommandsForAllPlayers(this.allowEveryoneCheat); diff --git a/src/main/java/io/github/satxm/mcwifipnp/commands/ForceOfflineCommand.java b/src/main/java/io/github/satxm/mcwifipnp/commands/ForceOfflineCommand.java index 430cca1..6b7cb61 100644 --- a/src/main/java/io/github/satxm/mcwifipnp/commands/ForceOfflineCommand.java +++ b/src/main/java/io/github/satxm/mcwifipnp/commands/ForceOfflineCommand.java @@ -14,6 +14,7 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import io.github.satxm.mcwifipnp.Config; +import io.github.satxm.mcwifipnp.UUIDFixer; import java.util.Collection; @@ -42,10 +43,9 @@ public static void register(CommandDispatcher commandDispatc .suggests((commandContext, suggestionsBuilder) -> { MinecraftServer server = ((CommandSourceStack) commandContext.getSource()).getServer(); PlayerList playerList = server.getPlayerList(); - Config cfg = Config.read(server); return SharedSuggestionProvider.suggest(playerList.getPlayers().stream() .filter( - (serverPlayer) -> !cfg.forcedOfflinePlayers.contains(serverPlayer.getGameProfile().getName()) + (serverPlayer) -> !UUIDFixer.alwaysOfflinePlayers.contains(serverPlayer.getGameProfile().getName()) ).map( (serverPlayer) -> serverPlayer.getGameProfile().getName() ), suggestionsBuilder); @@ -58,9 +58,7 @@ public static void register(CommandDispatcher commandDispatc RequiredArgumentBuilder removeCmdTargets = Commands.argument("targets", GameProfileArgument.gameProfile()) .suggests((commandContext, suggestionsBuilder) -> { - MinecraftServer server = ((CommandSourceStack) commandContext.getSource()).getServer(); - Config cfg = Config.read(server); - return SharedSuggestionProvider.suggest(cfg.forcedOfflinePlayers.stream(), suggestionsBuilder); + return SharedSuggestionProvider.suggest(UUIDFixer.alwaysOfflinePlayers.stream(), suggestionsBuilder); }).executes((commandContext) -> { return removePlayers((CommandSourceStack) commandContext.getSource(), GameProfileArgument.getGameProfiles(commandContext, "targets")); @@ -75,11 +73,12 @@ private static int addPlayers(CommandSourceStack commandSourceStack, Collection< MinecraftServer server = commandSourceStack.getServer(); Config cfg = Config.read(server); + cfg.readFromRunningServer(server); int added = 0; for (GameProfile gameProfile : collection) { - if (!cfg.forcedOfflinePlayers.contains(gameProfile.getName())) { - cfg.forcedOfflinePlayers.add(gameProfile.getName()); + if (!UUIDFixer.alwaysOfflinePlayers.contains(gameProfile.getName())) { + UUIDFixer.alwaysOfflinePlayers.add(gameProfile.getName()); commandSourceStack.sendSuccess(() -> { return Component.translatable("mcwifipnp.commands.forceoffline.add.success", Component.literal(gameProfile.getName())); @@ -101,11 +100,12 @@ private static int removePlayers(CommandSourceStack commandSourceStack, Collecti MinecraftServer server = commandSourceStack.getServer(); Config cfg = Config.read(server); + cfg.readFromRunningServer(server); int removed = 0; for (GameProfile gameProfile: collection) { - if (cfg.forcedOfflinePlayers.contains(gameProfile.getName())) { - cfg.forcedOfflinePlayers.remove(gameProfile.getName()); + if (UUIDFixer.alwaysOfflinePlayers.contains(gameProfile.getName())) { + UUIDFixer.alwaysOfflinePlayers.remove(gameProfile.getName()); commandSourceStack.sendSuccess(() -> { return Component.translatable("mcwifipnp.commands.forceoffline.remove.success", Component.literal(gameProfile.getName())); @@ -124,20 +124,17 @@ private static int removePlayers(CommandSourceStack commandSourceStack, Collecti } private static int showList(CommandSourceStack commandSourceStack) { - MinecraftServer server = commandSourceStack.getServer(); - Config cfg = Config.read(server); - - if (cfg.forcedOfflinePlayers.size() == 0) { + if (UUIDFixer.alwaysOfflinePlayers.size() == 0) { commandSourceStack.sendSuccess(() -> { return Component.translatable("mcwifipnp.commands.forceoffline.none"); }, false); } else { commandSourceStack.sendSuccess(() -> { return Component.translatable("mcwifipnp.commands.forceoffline.list", - cfg.forcedOfflinePlayers.size(), StringUtils.join(cfg.forcedOfflinePlayers, ", ")); + UUIDFixer.alwaysOfflinePlayers.size(), StringUtils.join(UUIDFixer.alwaysOfflinePlayers, ", ")); }, false); } - return cfg.forcedOfflinePlayers.size(); + return UUIDFixer.alwaysOfflinePlayers.size(); } }