1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-19 14:59:20 +00:00

Fix /fwhitelist on 1.21.9

This commit is contained in:
Aurora
2025-10-03 17:05:00 +01:00
parent bc3e8f54c4
commit 06bb54395f
2 changed files with 37 additions and 9 deletions

View File

@@ -60,7 +60,9 @@ public class ClassNames {
public static final Class<?> LOGIN_LISTENER; public static final Class<?> LOGIN_LISTENER;
@Nullable public static final Class<?> CLIENT_INTENT; @Nullable public static final Class<?> CLIENT_INTENT;
public static final Constructor<OfflinePlayer> CRAFT_OFFLINE_PLAYER_CONSTRUCTOR; @Nullable public static final Constructor<OfflinePlayer> CRAFT_OFFLINE_PLAYER_CONSTRUCTOR;
@Nullable public static final Constructor<OfflinePlayer> CRAFT_NEW_OFFLINE_PLAYER_CONSTRUCTOR;
@Nullable public static final Constructor<?> NAME_AND_ID_CONSTRUCTOR;
@Nullable public static final Constructor<?> LOGIN_HANDLER_CONSTRUCTOR; @Nullable public static final Constructor<?> LOGIN_HANDLER_CONSTRUCTOR;
@Nullable public static final Constructor<?> HANDSHAKE_PACKET_CONSTRUCTOR; @Nullable public static final Constructor<?> HANDSHAKE_PACKET_CONSTRUCTOR;
@@ -159,6 +161,18 @@ public class ClassNames {
CRAFT_OFFLINE_PLAYER_CONSTRUCTOR = ReflectionUtils.getConstructor( CRAFT_OFFLINE_PLAYER_CONSTRUCTOR = ReflectionUtils.getConstructor(
craftOfflinePlayerClass, true, craftServerClass, GameProfile.class); craftOfflinePlayerClass, true, craftServerClass, GameProfile.class);
if (CRAFT_OFFLINE_PLAYER_CONSTRUCTOR == null) { // Changed in 1.21.9
Class<?> nameAndIdClass = getClassSilently("net.minecraft.server.players.NameAndId");
CRAFT_NEW_OFFLINE_PLAYER_CONSTRUCTOR = ReflectionUtils.getConstructor(
craftOfflinePlayerClass, true, craftServerClass, nameAndIdClass);
NAME_AND_ID_CONSTRUCTOR = ReflectionUtils.getConstructor(nameAndIdClass, true, GameProfile.class);
} else {
CRAFT_NEW_OFFLINE_PLAYER_CONSTRUCTOR = null;
NAME_AND_ID_CONSTRUCTOR = null;
}
// SpigotDataHandler // SpigotDataHandler
Class<?> networkManager = getClassOrFallback( Class<?> networkManager = getClassOrFallback(
"net.minecraft.network.Connection", "net.minecraft.network.Connection",

View File

@@ -29,6 +29,7 @@ import com.mojang.authlib.GameProfile;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public final class WhitelistUtils { public final class WhitelistUtils {
@@ -44,10 +45,7 @@ public final class WhitelistUtils {
public static boolean addPlayer(UUID uuid, String username, SpigotVersionSpecificMethods versionSpecificMethods) { public static boolean addPlayer(UUID uuid, String username, SpigotVersionSpecificMethods versionSpecificMethods) {
GameProfile profile = new GameProfile(uuid, username); GameProfile profile = new GameProfile(uuid, username);
OfflinePlayer player = ReflectionUtils.newInstance( OfflinePlayer player = getOfflinePlayer(profile);
ClassNames.CRAFT_OFFLINE_PLAYER_CONSTRUCTOR,
Bukkit.getServer(), profile
);
if (player.isWhitelisted()) { if (player.isWhitelisted()) {
return false; return false;
} }
@@ -67,10 +65,7 @@ public final class WhitelistUtils {
public static boolean removePlayer(UUID uuid, String username, SpigotVersionSpecificMethods versionSpecificMethods) { public static boolean removePlayer(UUID uuid, String username, SpigotVersionSpecificMethods versionSpecificMethods) {
GameProfile profile = new GameProfile(uuid, username); GameProfile profile = new GameProfile(uuid, username);
OfflinePlayer player = ReflectionUtils.newInstance( OfflinePlayer player = getOfflinePlayer(profile);
ClassNames.CRAFT_OFFLINE_PLAYER_CONSTRUCTOR,
Bukkit.getServer(), profile
);
if (!player.isWhitelisted()) { if (!player.isWhitelisted()) {
return false; return false;
} }
@@ -81,4 +76,23 @@ public final class WhitelistUtils {
static void setWhitelist(OfflinePlayer player, boolean whitelist, SpigotVersionSpecificMethods versionSpecificMethods) { static void setWhitelist(OfflinePlayer player, boolean whitelist, SpigotVersionSpecificMethods versionSpecificMethods) {
versionSpecificMethods.maybeSchedule(() -> player.setWhitelisted(whitelist), true); // Whitelisting is on the global thread versionSpecificMethods.maybeSchedule(() -> player.setWhitelisted(whitelist), true); // Whitelisting is on the global thread
} }
static OfflinePlayer getOfflinePlayer(GameProfile profile) {
if (ClassNames.CRAFT_NEW_OFFLINE_PLAYER_CONSTRUCTOR != null) {
Object nameAndId = ReflectionUtils.newInstance(
ClassNames.NAME_AND_ID_CONSTRUCTOR,
profile
);
return ReflectionUtils.newInstance(
ClassNames.CRAFT_NEW_OFFLINE_PLAYER_CONSTRUCTOR,
Bukkit.getServer(), nameAndId
);
} else {
return ReflectionUtils.newInstance(
ClassNames.CRAFT_OFFLINE_PLAYER_CONSTRUCTOR,
Bukkit.getServer(), profile
);
}
}
} }