Skip to content

Commit

Permalink
Fix spigot whitelist command on newer Paper versions (#456)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
(cherry picked from commit 7b88918)
  • Loading branch information
HideyBoi authored and Tim203 committed Oct 13, 2023
1 parent b153d20 commit 112eeac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -127,11 +128,11 @@ public void kickPlayer(Object player, String message) {

@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -51,7 +52,7 @@ public static boolean addPlayer(UUID uuid, String username) {
if (player.isWhitelisted()) {
return false;
}
player.setWhitelisted(true);
setWhitelist(player, true, versionSpecificMethods);
return true;
}

Expand All @@ -60,10 +61,11 @@ public static boolean addPlayer(UUID uuid, String username) {
*
* @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(
Expand All @@ -73,7 +75,11 @@ public static boolean removePlayer(UUID uuid, String username) {
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));
}
}

0 comments on commit 112eeac

Please sign in to comment.