Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spigot whitelist command on newer Paper versions #456

Merged
merged 5 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

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 @@ -122,11 +123,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 @@ -25,9 +25,9 @@

package org.geysermc.floodgate.util;

import org.bukkit.Bukkit;
import com.mojang.authlib.GameProfile;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
HideyBoi marked this conversation as resolved.
Show resolved Hide resolved

@SuppressWarnings("ConstantConditions")
Expand All @@ -36,11 +36,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 @@ -50,7 +51,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 @@ -59,10 +60,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 @@ -72,7 +74,18 @@ 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) {
Runnable runnable = new Runnable() {
@Override
public void run() {
player.setWhitelisted(whitelist);
}
};

versionSpecificMethods.maybeSchedule(runnable);
}
HideyBoi marked this conversation as resolved.
Show resolved Hide resolved
}
Loading