Moved getGeyserPlayer() to the only class it's used in

This commit is contained in:
Smart123s
2021-03-22 20:35:22 +01:00
parent f9992f1447
commit e2e4e76fd9
2 changed files with 22 additions and 22 deletions

View File

@ -5,7 +5,6 @@ import com.comphenix.protocol.events.PacketEvent;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent;
import com.github.games647.fastlogin.bukkit.task.FloodgateAuthTask;
import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.shared.JoinManagement;
import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
@ -13,8 +12,12 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
import java.security.PublicKey;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.network.session.GeyserSession;
public class NameCheckTask extends JoinManagement<Player, CommandSender, ProtocolLibLoginSource>
implements Runnable {
@ -45,7 +48,7 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
try {
// check if the player is connecting through Geyser
if (!plugin.getCore().getConfig().getString("allowFloodgateNameConflict").equalsIgnoreCase("false")
&& FloodgateAuthTask.getGeyserPlayer(username) != null) {
&& getGeyserPlayer(username) != null) {
plugin.getLog().info("Skipping name conflict checking for player {}", username);
return;
}
@ -93,4 +96,21 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
plugin.putSession(player.getAddress(), loginSession);
}
private static GeyserSession getGeyserPlayer(String username) {
if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate-bukkit") &&
Bukkit.getServer().getPluginManager().isPluginEnabled("Geyser-Spigot") &&
GeyserConnector.getInstance().getDefaultAuthType() == AuthType.FLOODGATE) {
// the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java
// the Floodgate API has a return value for Java (non-bedrock) players, if they
// are linked to a Bedrock account
// workaround: iterate over Geyser's player's usernames
for (GeyserSession geyserPlayer : GeyserConnector.getInstance().getPlayers()) {
if (geyserPlayer.getName().equals(username)) {
return geyserPlayer;
}
}
}
return null;
}
}

View File

@ -2,9 +2,6 @@ package com.github.games647.fastlogin.bukkit.task;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.floodgate.FloodgateAPI;
import org.geysermc.floodgate.FloodgatePlayer;
@ -86,21 +83,4 @@ public class FloodgateAuthTask implements Runnable {
Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask);
}
public static GeyserSession getGeyserPlayer(String username) {
if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate-bukkit") &&
Bukkit.getServer().getPluginManager().isPluginEnabled("Geyser-Spigot") &&
GeyserConnector.getInstance().getDefaultAuthType() == AuthType.FLOODGATE) {
// the Floodgate API requires UUID, which is inaccessible at NameCheckTask.java
// the Floodgate API has a return value for Java (non-bedrock) players, if they
// are linked to a Bedrock account
// workaround: iterate over Geyser's player's usernames
for (GeyserSession geyserPlayer : GeyserConnector.getInstance().getPlayers()) {
if (geyserPlayer.getName().equals(username)) {
return geyserPlayer;
}
}
}
return null;
}
}