From 112eeac014e8aee178c0fcebe82780ac3b440b5e Mon Sep 17 00:00:00 2001 From: Hidey Boi <62223632+HideyBoi@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:22:20 -0500 Subject: [PATCH] Fix spigot whitelist command on newer Paper versions (#456) * Jank Fix for #444 * Move Scheduler to WhitelistUtils Also stopped using the Bukkit scheduler and am now scheduling via SpigotVersionSpecificMethods.maybeSchedule * Move setWhitelist to WhitelistUtils Includes requested formatting changes. * switch from runnables to using an lambda expression * Made lambda a single line --------- Co-authored-by: Hidey Boi (cherry picked from commit 7b889180e0664873934fa85c7a2f2ef2d563c960) --- .../spigot/util/SpigotCommandUtil.java | 5 +++-- .../floodgate/spigot/util/WhitelistUtils.java | 20 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/spigot/base/src/main/java/org/geysermc/floodgate/spigot/util/SpigotCommandUtil.java b/spigot/base/src/main/java/org/geysermc/floodgate/spigot/util/SpigotCommandUtil.java index 17219b3f..abf0df5a 100644 --- a/spigot/base/src/main/java/org/geysermc/floodgate/spigot/util/SpigotCommandUtil.java +++ b/spigot/base/src/main/java/org/geysermc/floodgate/spigot/util/SpigotCommandUtil.java @@ -29,6 +29,7 @@ import jakarta.inject.Inject; import jakarta.inject.Singleton; import java.util.Collection; import java.util.UUID; +import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -127,11 +128,11 @@ public final class SpigotCommandUtil extends CommandUtil { @Override public boolean whitelistPlayer(UUID uuid, String username) { - return WhitelistUtils.addPlayer(uuid, username); + return WhitelistUtils.addPlayer(uuid, username, versionSpecificMethods); } @Override public boolean removePlayerFromWhitelist(UUID uuid, String username) { - return WhitelistUtils.removePlayer(uuid, username); + return WhitelistUtils.removePlayer(uuid, username, versionSpecificMethods); } } diff --git a/spigot/base/src/main/java/org/geysermc/floodgate/spigot/util/WhitelistUtils.java b/spigot/base/src/main/java/org/geysermc/floodgate/spigot/util/WhitelistUtils.java index 0092943e..7a233af1 100644 --- a/spigot/base/src/main/java/org/geysermc/floodgate/spigot/util/WhitelistUtils.java +++ b/spigot/base/src/main/java/org/geysermc/floodgate/spigot/util/WhitelistUtils.java @@ -37,11 +37,12 @@ public final class WhitelistUtils { /** * Whitelist the given Bedrock player. * - * @param uuid the UUID of the Bedrock player to be whitelisted - * @param username the username of the Bedrock player to be whitelisted - * @return true if the player has been whitelisted, false if the player is already whitelisted + * @param uuid the UUID of the Bedrock player to be removed + * @param username the username of the Bedrock player to be removed + * @param versionSpecificMethods a reference to the SpigotVersionSpecificMethods used in SpigotCommandUtil + * @return true if the player has been removed from the whitelist, false if the player wasn't */ - public static boolean addPlayer(UUID uuid, String username) { + public static boolean addPlayer(UUID uuid, String username, SpigotVersionSpecificMethods versionSpecificMethods) { GameProfile profile = new GameProfile(uuid, username); OfflinePlayer player = ReflectionUtils.newInstance( @@ -51,7 +52,7 @@ public final class WhitelistUtils { if (player.isWhitelisted()) { return false; } - player.setWhitelisted(true); + setWhitelist(player, true, versionSpecificMethods); return true; } @@ -60,10 +61,11 @@ public final class WhitelistUtils { * * @param uuid the UUID of the Bedrock player to be removed * @param username the username of the Bedrock player to be removed + * @param versionSpecificMethods a reference to the SpigotVersionSpecificMethods used in SpigotCommandUtil * @return true if the player has been removed from the whitelist, false if the player wasn't * whitelisted */ - public static boolean removePlayer(UUID uuid, String username) { + public static boolean removePlayer(UUID uuid, String username, SpigotVersionSpecificMethods versionSpecificMethods) { GameProfile profile = new GameProfile(uuid, username); OfflinePlayer player = ReflectionUtils.newInstance( @@ -73,7 +75,11 @@ public final class WhitelistUtils { if (!player.isWhitelisted()) { return false; } - player.setWhitelisted(false); + setWhitelist(player, false, versionSpecificMethods); return true; } + + static void setWhitelist(OfflinePlayer player, boolean whitelist, SpigotVersionSpecificMethods versionSpecificMethods) { + versionSpecificMethods.maybeSchedule(() -> player.setWhitelisted(whitelist)); + } }