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 2 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,23 @@ 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, this);
}

@Override
public boolean removePlayerFromWhitelist(UUID uuid, String username) {
return WhitelistUtils.removePlayer(uuid, username);
return WhitelistUtils.removePlayer(uuid, username, this);
}

public void setWhitelist(Object offlinePlayer, Boolean isWhitelisted) {
Runnable runnable = new Runnable() {
@Override
public void run() {
OfflinePlayer player = (OfflinePlayer)offlinePlayer;
player.setWhitelisted(isWhitelisted);
}
};

versionSpecificMethods.maybeSchedule(runnable);
HideyBoi marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,64 @@

package org.geysermc.floodgate.util;

import static org.bukkit.Bukkit.getServer;
HideyBoi marked this conversation as resolved.
Show resolved Hide resolved

import com.mojang.authlib.GameProfile;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;



@SuppressWarnings("ConstantConditions")
HideyBoi marked this conversation as resolved.
Show resolved Hide resolved
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
* @param uuid the UUID of the Bedrock player to be whitelisted
* @param username the username of the Bedrock player to be whitelisted
* @param spigotCommandUtil
HideyBoi marked this conversation as resolved.
Show resolved Hide resolved
* @return true if the player has been whitelisted, false if the player is already whitelisted
*/
public static boolean addPlayer(UUID uuid, String username) {
public static boolean addPlayer(UUID uuid, String username, SpigotCommandUtil spigotCommandUtil) {
GameProfile profile = new GameProfile(uuid, username);

OfflinePlayer player = ReflectionUtils.newInstance(
ClassNames.CRAFT_OFFLINE_PLAYER_CONSTRUCTOR,
Bukkit.getServer(), profile
getServer(), profile
);
if (player.isWhitelisted()) {
return false;
}
player.setWhitelisted(true);

spigotCommandUtil.setWhitelist(player, true);

HideyBoi marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

/**
* Removes the given Bedrock player from the whitelist.
*
* @param uuid the UUID of the Bedrock player to be removed
* @param username the username of the Bedrock player to be removed
* @param uuid the UUID of the Bedrock player to be removed
* @param username the username of the Bedrock player to be removed
* @param spigotCommandUtil
HideyBoi marked this conversation as resolved.
Show resolved Hide resolved
* @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,
SpigotCommandUtil spigotCommandUtil) {
HideyBoi marked this conversation as resolved.
Show resolved Hide resolved
GameProfile profile = new GameProfile(uuid, username);

OfflinePlayer player = ReflectionUtils.newInstance(
ClassNames.CRAFT_OFFLINE_PLAYER_CONSTRUCTOR,
Bukkit.getServer(), profile
getServer(), profile
);
if (!player.isWhitelisted()) {
return false;
}
player.setWhitelisted(false);

spigotCommandUtil.setWhitelist(player, false);

HideyBoi marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
}