diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/floodgate/FloodgateHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/floodgate/FloodgateHook.java index 336cf4b7..fdc37837 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/floodgate/FloodgateHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/floodgate/FloodgateHook.java @@ -25,72 +25,13 @@ */ package com.github.games647.fastlogin.bukkit.hook.floodgate; -import java.io.IOException; -import java.util.Optional; - import org.bukkit.Bukkit; import org.geysermc.floodgate.api.FloodgateApi; import org.geysermc.floodgate.api.player.FloodgatePlayer; -import com.github.games647.craftapi.model.Profile; -import com.github.games647.craftapi.resolver.RateLimitException; -import com.github.games647.fastlogin.bukkit.FastLoginBukkit; -import com.github.games647.fastlogin.core.shared.LoginSource; - public class FloodgateHook { - private final FastLoginBukkit plugin; - - public FloodgateHook(FastLoginBukkit plugin) { - this.plugin = plugin; - } - - /** - * Check if the player's name conflicts an existing Java player's name, and - * kick them if it does - * - * @param core the FastLoginCore - * @param username the name of the player - * @param source an instance of LoginSource - * @param plugin the FastLoginBukkit plugin - */ - public void checkNameConflict(String username, LoginSource source, FloodgatePlayer floodgatePlayer) { - String allowConflict = plugin.getCore().getConfig().get("allowFloodgateNameConflict").toString().toLowerCase(); - - // check if the Bedrock player is linked to a Java account - boolean isLinked = floodgatePlayer.getLinkedPlayer() != null; - - if (allowConflict.equals("false") - || allowConflict.equals("linked") && !isLinked) { - - // check for conflicting Premium Java name - Optional premiumUUID = Optional.empty(); - try { - premiumUUID = plugin.getCore().getResolver().findProfile(username); - } catch (IOException | RateLimitException e) { - plugin.getLog().error( - "Could not check wether Floodgate Player {}'s name conflicts a premium Java player's name.", - username); - try { - source.kick("Could not check if your name conflicts an existing Java Premium Player's name"); - } catch (Exception e1) { - plugin.getLog().error("Could not kick Player {}", username); - } - } - - if (premiumUUID.isPresent()) { - plugin.getLog().info("Bedrock Player {}'s name conflicts an existing Java Premium Player's name", - username); - try { - source.kick("Your name conflicts an existing Java Premium Player's name"); - } catch (Exception e) { - plugin.getLog().error("Could not kick Player {}", username); - } - } - } else { - plugin.getLog().info("Skipping name conflict checking for player {}", username); - } - } + public FloodgateHook() { } /** * The FloodgateApi does not support querying players by name, so this function 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 db375059..e1e1bbe6 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 @@ -72,17 +72,7 @@ public class NameCheckTask extends JoinManagementcodemc-repo https://repo.codemc.io/repository/maven-public/ + + + nukkitx-snapshot + https://repo.nukkitx.com/maven-snapshots/ + @@ -85,6 +90,14 @@ + + + org.geysermc.floodgate + api + 2.0-SNAPSHOT + provided + + com.github.games647 diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java index e337462c..a28e3d4c 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java @@ -31,8 +31,11 @@ import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; +import java.io.IOException; import java.util.Optional; +import org.geysermc.floodgate.api.player.FloodgatePlayer; + import net.md_5.bungee.config.Configuration; public abstract class JoinManagement

{ @@ -52,6 +55,13 @@ public abstract class JoinManagement

{ return; } + //check if the player is connecting through Floodgate + FloodgatePlayer floodgatePlayer = getFloodgatePlayer(username); + + if (floodgatePlayer != null) { + checkFloodgateNameConflict(username, source, floodgatePlayer); + return; + } callFastLoginPreLoginEvent(username, source, profile); Configuration config = core.getConfig(); @@ -131,6 +141,60 @@ public abstract class JoinManagement

{ return false; } + /** + * Check if the player's name conflicts an existing Java player's name, and + * kick them if it does + * + * @param core the FastLoginCore + * @param username the name of the player + * @param source an instance of LoginSource + */ + public void checkFloodgateNameConflict(String username, LoginSource source, FloodgatePlayer floodgatePlayer) { + String allowConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase(); + + // check if the Bedrock player is linked to a Java account + boolean isLinked = floodgatePlayer.getLinkedPlayer() != null; + + if (allowConflict.equals("false") + || allowConflict.equals("linked") && !isLinked) { + + // check for conflicting Premium Java name + Optional premiumUUID = Optional.empty(); + try { + premiumUUID = core.getResolver().findProfile(username); + } catch (IOException | RateLimitException e) { + core.getPlugin().getLog().error( + "Could not check wether Floodgate Player {}'s name conflicts a premium Java player's name.", + username); + try { + source.kick("Could not check if your name conflicts an existing Java Premium Player's name"); + } catch (Exception e1) { + core.getPlugin().getLog().error("Could not kick Player {}", username); + } + } + + if (premiumUUID.isPresent()) { + core.getPlugin().getLog().info("Bedrock Player {}'s name conflicts an existing Java Premium Player's name", + username); + try { + source.kick("Your name conflicts an existing Java Premium Player's name"); + } catch (Exception e) { + core.getPlugin().getLog().error("Could not kick Player {}", username); + } + } + } else { + core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); + } + } + + /** + * Check if a player is connecting through Floodgate + * @param id UUID for BungeeCord, username for Bukkit + * @return true if the player is connecting through Floodgate + *
null if Floodgate is unavailable + */ + protected abstract FloodgatePlayer getFloodgatePlayer(Object id); + public abstract FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, S source, StoredProfile profile); public abstract void requestPremiumLogin(S source, StoredProfile profile, String username, boolean registered);