diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index 98693da5..e31cedf9 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -2,9 +2,8 @@ package com.github.games647.fastlogin.bukkit.listener; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; +import com.github.games647.fastlogin.bukkit.task.FloodgateAuthTask; import com.github.games647.fastlogin.bukkit.task.ForceLoginTask; -import com.github.games647.fastlogin.core.hooks.AuthPlugin; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -14,10 +13,6 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerQuitEvent; -import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.floodgate.FloodgateAPI; -import org.geysermc.floodgate.FloodgatePlayer; /** * This listener tells authentication plugins if the player has a premium account and we checked it successfully. So the @@ -51,64 +46,10 @@ public class ConnectionListener implements Listener { // having the login session from the login process BukkitLoginSession session = plugin.getSession(player.getAddress()); - if (Bukkit.getServer().getPluginManager().isPluginEnabled("Geyser-Spigot") && - Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate-bukkit")) { - FloodgatePlayer floodgatePlayer = null; - - // check if the player is really connected through Geyser - for (GeyserSession geyserPlayer : GeyserConnector.getInstance().getPlayers()) { - if (geyserPlayer.getName().equals(player.getName())) { - // this also returns a floodgatePlayer for linked Java accounts - // that's why the Geyser Server's player list also has to be checked - //TODO: does this return null if a player is connected through Geyser Offline mode? - floodgatePlayer = FloodgateAPI.getPlayer(player.getUniqueId()); - break; - } - } - - if (floodgatePlayer != null) { - plugin.getLog().info( - "Player {} is connecting through Geyser Floodgate.", - player.getName()); - String allowNameConflict = plugin.getCore().getConfig().getString("allowFloodgateNameConflict"); - // check if the Bedrock player is linked to a Java account - boolean isLinked = floodgatePlayer.fetchLinkedPlayer() != null; - if (allowNameConflict.equalsIgnoreCase("linked") && !isLinked) { - plugin.getLog().info( - "Bedrock Player {}'s name conflits an existing Java Premium Player's name", - player.getName()); - player.kickPlayer("This name is allready in use by a Premium Java Player"); - - } - if (!allowNameConflict.equalsIgnoreCase("true") && !allowNameConflict.equalsIgnoreCase("linked")) { - plugin.getLog().error( - "Invalid value detected for 'allowNameConflict' in FasttLogin/config.yml. Aborting login of Player {}", - player.getName()); - return; - } - - AuthPlugin authPlugin = plugin.getCore().getAuthPluginHook(); - - String autoLoginFloodgate = plugin.getCore().getConfig().getString("autoLoginFloodgate"); - boolean autoRegisterFloodgate = plugin.getCore().getConfig().getBoolean("autoRegisterFloodgate"); - - // create fake session to make auto login work - // the player should only be registered (=> parm. registered = false) if - // the player is not registered and autoRegister is enabled in the config - try { - session = new BukkitLoginSession(player.getName(), authPlugin.isRegistered(player.getName()) || !autoRegisterFloodgate); - // enable auto login based on the value of 'autoLoginFloodgate' in config.yml - session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") - || (autoLoginFloodgate.equalsIgnoreCase("linked") && isLinked)); - } catch (Exception e) { - plugin.getLog().error( - "An error has occured while checking if player {} is registered", - player.getName()); - return; - } - } - } - if (session == null) { + if (FloodgateAuthTask.getGeyserPlayer(player.getName()) != null) { + Runnable floodgateAuthTask = new FloodgateAuthTask(plugin, player); + Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask); + } else if (session == null) { String sessionId = plugin.getSessionId(player.getAddress()); plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId); } else { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index 140cb705..4508501e 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -5,6 +5,7 @@ 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; @@ -12,12 +13,8 @@ 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 implements Runnable { @@ -47,19 +44,10 @@ public class NameCheckTask extends JoinManagement authPlugin = plugin.getCore().getAuthPluginHook(); + + String autoLoginFloodgate = plugin.getCore().getConfig().getString("autoLoginFloodgate"); + boolean autoRegisterFloodgate = plugin.getCore().getConfig().getBoolean("autoRegisterFloodgate"); + + // create fake session to make auto login work + // the player should only be registered (=> parm. registered = false) if + // the player is not registered and autoRegister is enabled in the config + try { + BukkitLoginSession session = new BukkitLoginSession(player.getName(), authPlugin.isRegistered(player.getName()) || !autoRegisterFloodgate); + // enable auto login based on the value of 'autoLoginFloodgate' in config.yml + session.setVerified(autoLoginFloodgate.equalsIgnoreCase("true") + || (autoLoginFloodgate.equalsIgnoreCase("linked") && isLinked)); + + //run login task + Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); + Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); + } catch (Exception e) { + plugin.getLog().error( + "An error has occured while checking if player {} is registered", + player.getName()); + return; + } + } + + 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; + } + +}