1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2026-01-03 14:12:25 +00:00

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 <HideyBoi@users.noreply.github.com>
(cherry picked from commit 7b889180e0)
This commit is contained in:
Hidey Boi
2023-10-10 13:22:20 -05:00
committed by Tim203
parent b153d20b16
commit 112eeac014
2 changed files with 16 additions and 9 deletions

View File

@@ -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);
}
}

View File

@@ -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));
}
}