From 1f3cd5fa5b6a2d94106ef6c90af8fa92fb5ef36c Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 22 May 2021 11:42:08 +0200 Subject: [PATCH 1/8] Share Floodgate name conflict check between Protocol Plugins Added a shared class for Floodgate name conflict checking that can be used by both ProtocolLib and ProtocolSupport Rebased on Sat May 22 11:42:08 2021 +0200 Added access modifier to "FastLoginBukkit plugin;" in FloodgateHook.java Rebased on Sat May 22 11:42:08 2021 +0200 Initialize FloogateHook in ProtocolLib's class --- .../bukkit/hook/floodgate/FloodgateHook.java | 81 +++++++++++++++++++ .../listener/protocollib/NameCheckTask.java | 37 ++++----- .../protocollib/ProtocolLibListener.java | 6 +- 3 files changed, 102 insertions(+), 22 deletions(-) create mode 100644 bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/floodgate/FloodgateHook.java 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 new file mode 100644 index 00000000..c29fa10a --- /dev/null +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/floodgate/FloodgateHook.java @@ -0,0 +1,81 @@ +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 conflict's 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(); + if (allowConflict.equals("false")) { + + // check for conflicting Premium Java name + Optional premiumUUID = Optional.empty(); + try { + premiumUUID = plugin.getCore().getResolver().findProfile(username); + } catch (IOException | RateLimitException e) { + e.printStackTrace(); + plugin.getLog().error( + "Could not check wether Floodgate Player {}'s name conflits a premium Java player's name.", + username); + } + + if (premiumUUID.isPresent()) { + plugin.getLog().info("Bedrock Player {}'s name conflits an existing Java Premium Player's name", + username); + try { + source.kick("Your name conflits an existing Java Premium Player's name"); + } catch (Exception e) { + e.printStackTrace(); + plugin.getLog().error("Could not kick Player {}", username); + } + } + } else { + plugin.getLog().info("Skipping name conflict checking for player {}", username); + } + } + + /** + * The FloodgateApi does not support querying players by name, so this function + * iterates over every online FloodgatePlayer and checks if the requested + * username can be found + * + * @param username the name of the player + * @return FloodgatePlayer if found, null otherwise + */ + public FloodgatePlayer getFloodgatePlayer(String username) { + if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate")) { + for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) { + if (floodgatePlayer.getUsername().equals(username)) { + return floodgatePlayer; + } + } + } + return null; + } + +} 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 ee6ba69b..db375059 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 @@ -30,6 +30,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.hook.floodgate.FloodgateHook; import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.shared.JoinManagement; import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; @@ -37,10 +38,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.floodgate.api.FloodgateApi; import org.geysermc.floodgate.api.player.FloodgatePlayer; public class NameCheckTask extends JoinManagement @@ -55,8 +54,10 @@ public class NameCheckTask extends JoinManagement Date: Sat, 22 May 2021 11:42:34 +0200 Subject: [PATCH 2/8] Made ProtocolSupport check for Floodgate name conflicts Rebased on Sat May 22 11:42:34 2021 +0200 Initialize FloodgateHook in constructor This way, it won't have to be initialized whenever a player joins --- .../ProtocolSupportListener.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java index 6b3826b8..24a3553c 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java @@ -29,6 +29,7 @@ import com.github.games647.craftapi.UUIDAdapter; 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.hook.floodgate.FloodgateHook; import com.github.games647.fastlogin.core.RateLimiter; import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.shared.JoinManagement; @@ -37,11 +38,12 @@ import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; import java.net.InetSocketAddress; import java.util.Optional; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.geysermc.floodgate.api.player.FloodgatePlayer; + import protocolsupport.api.events.ConnectionCloseEvent; import protocolsupport.api.events.PlayerLoginStartEvent; import protocolsupport.api.events.PlayerProfileCompleteEvent; @@ -51,12 +53,14 @@ public class ProtocolSupportListener extends JoinManagement Date: Sat, 22 May 2021 13:48:29 +0200 Subject: [PATCH 3/8] Kick player if Floodgate name conflict checking fails Rebased on Sat May 22 13:48:29 2021 +0200 Fixed typos in strings --- .../bukkit/hook/floodgate/FloodgateHook.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 c29fa10a..00dd537b 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 @@ -21,7 +21,7 @@ public class FloodgateHook { } /** - * Check if the player's name conflict's an existing Java player's name, and + * Check if the player's name conflicts an existing Java player's name, and * kick them if it does * * @param core the FastLoginCore @@ -40,15 +40,20 @@ public class FloodgateHook { } catch (IOException | RateLimitException e) { e.printStackTrace(); plugin.getLog().error( - "Could not check wether Floodgate Player {}'s name conflits a premium Java player's name.", + "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 conflits an existing Java Premium Player's name", + plugin.getLog().info("Bedrock Player {}'s name conflicts an existing Java Premium Player's name", username); try { - source.kick("Your name conflits an existing Java Premium Player's name"); + source.kick("Your name conflicts an existing Java Premium Player's name"); } catch (Exception e) { e.printStackTrace(); plugin.getLog().error("Could not kick Player {}", username); From 757d0ef99140f04b3e69c3f8c01bd05b6ef15320 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 22 May 2021 17:06:16 +0200 Subject: [PATCH 4/8] Fix & Move allowFloodgateNameConflict=linked --- .../bukkit/hook/floodgate/FloodgateHook.java | 9 ++++++--- .../bukkit/task/FloodgateAuthTask.java | 17 +---------------- 2 files changed, 7 insertions(+), 19 deletions(-) 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 00dd537b..d95345bb 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 @@ -31,14 +31,18 @@ public class FloodgateHook { */ public void checkNameConflict(String username, LoginSource source, FloodgatePlayer floodgatePlayer) { String allowConflict = plugin.getCore().getConfig().get("allowFloodgateNameConflict").toString().toLowerCase(); - if (allowConflict.equals("false")) { + + // 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) { - e.printStackTrace(); plugin.getLog().error( "Could not check wether Floodgate Player {}'s name conflicts a premium Java player's name.", username); @@ -55,7 +59,6 @@ public class FloodgateHook { try { source.kick("Your name conflicts an existing Java Premium Player's name"); } catch (Exception e) { - e.printStackTrace(); plugin.getLog().error("Could not kick Player {}", username); } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java index d833fd66..c2b6d48f 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/task/FloodgateAuthTask.java @@ -26,25 +26,10 @@ public class FloodgateAuthTask implements Runnable { plugin.getLog().info( "Player {} is connecting through Geyser Floodgate.", player.getName()); - String allowNameConflict = plugin.getCore().getConfig().get("allowFloodgateNameConflict").toString().toLowerCase(); + // check if the Bedrock player is linked to a Java account boolean isLinked = floodgatePlayer.getLinkedPlayer() != null; - if (allowNameConflict.equals("linked") && !isLinked) { - plugin.getLog().info( - "Bedrock Player {}'s name conflits an existing Java Premium Player's name", - player.getName()); - - // kicking must be synchronous - // https://www.spigotmc.org/threads/asynchronous-player-kick-problem.168580/ - Bukkit.getScheduler().runTask(plugin, new Runnable() { - public void run() { - player.kickPlayer("This name is allready in use by a Premium Java Player"); - } - }); - return; - } - AuthPlugin authPlugin = plugin.getCore().getAuthPluginHook(); String autoLoginFloodgate = plugin.getCore().getConfig().get("autoLoginFloodgate").toString().toLowerCase(); From 0e8ad6e318147d3bb1d5e2374430df25ab4aa7a5 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sat, 12 Jun 2021 19:56:36 +0200 Subject: [PATCH 5/8] Add license header to FloodgateHook.java --- .../bukkit/hook/floodgate/FloodgateHook.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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 d95345bb..336cf4b7 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 @@ -1,3 +1,28 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package com.github.games647.fastlogin.bukkit.hook.floodgate; import java.io.IOException; From ee2b3a37f8b0dc260bd5399e846f8e6c98a94f54 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 7 Jun 2021 18:50:38 +0200 Subject: [PATCH 6/8] Move Floodgate name conflict check to Core --- .../bukkit/hook/floodgate/FloodgateHook.java | 61 +----------------- .../listener/protocollib/NameCheckTask.java | 20 +++--- .../protocollib/ProtocolLibListener.java | 2 +- .../ProtocolSupportListener.java | 21 +++--- .../bungee/task/AsyncPremiumCheck.java | 8 +++ core/pom.xml | 13 ++++ .../fastlogin/core/shared/JoinManagement.java | 64 +++++++++++++++++++ 7 files changed, 106 insertions(+), 83 deletions(-) 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); From af0ef2aed970ebc3e171ae96ddbba8d65d636fdc Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Mon, 7 Jun 2021 19:45:27 +0200 Subject: [PATCH 7/8] Stop ProtocolSupport from crying If I ever tried to either cast or use FloodgatePlayer as a return type when Floodgate was not installed in the server, I got this error: [19:37:46 ERROR]: [FastLogin] Plugin FastLogin v1.11-SNAPSHOT-744264d has failed to register events for class com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener because org/geysermc/floodgate/api/player/FloodgatePlayer does not exist. ProtocolLib doen't have this problem. --- .../ProtocolSupportListener.java | 3 +-- .../fastlogin/core/shared/JoinManagement.java | 18 +++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java index f9af6f0e..abed0370 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java @@ -42,7 +42,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.geysermc.floodgate.api.player.FloodgatePlayer; import protocolsupport.api.events.ConnectionCloseEvent; import protocolsupport.api.events.PlayerLoginStartEvent; @@ -132,7 +131,7 @@ public class ProtocolSupportListener extends JoinManagement { } //check if the player is connecting through Floodgate - FloodgatePlayer floodgatePlayer = getFloodgatePlayer(username); + Object floodgatePlayer = getFloodgatePlayer(username); if (floodgatePlayer != null) { checkFloodgateNameConflict(username, source, floodgatePlayer); @@ -149,11 +149,11 @@ public abstract class JoinManagement

{ * @param username the name of the player * @param source an instance of LoginSource */ - public void checkFloodgateNameConflict(String username, LoginSource source, FloodgatePlayer floodgatePlayer) { + public void checkFloodgateNameConflict(String username, LoginSource source, Object 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; + boolean isLinked = ((FloodgatePlayer) floodgatePlayer).getLinkedPlayer() != null; if (allowConflict.equals("false") || allowConflict.equals("linked") && !isLinked) { @@ -188,12 +188,16 @@ public abstract class JoinManagement

{ } /** - * Check if a player is connecting through Floodgate + * Gets a FloodgatePlayer based on name or UUID Note: Don't change the return + * type from Object to FloodgatePlayer, unless you want ProtocolSupport to throw + * an error if Floodgate is not installed + * * @param id UUID for BungeeCord, username for Bukkit - * @return true if the player is connecting through Floodgate - *
null if Floodgate is unavailable + * @return an instance of FloodgatePlayer, if Floodgate is installed and a + * player is found
+ * null if Floodgate is unavailable */ - protected abstract FloodgatePlayer getFloodgatePlayer(Object id); + protected abstract Object getFloodgatePlayer(Object id); public abstract FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, S source, StoredProfile profile); From 411148b560983a61be51f0ad44aff21f12f516bd Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Sun, 13 Jun 2021 14:24:14 +0200 Subject: [PATCH 8/8] No longer reference 'Floodgate' in JoinManagement Referencing 'FloodgatePlayer' in JoinManagement.java and it's subclasses has cause ProtocolLib to fail to register an event when Floodgate was not installed. --- .../fastlogin/bukkit/FastLoginBukkit.java | 2 +- .../bukkit/hook/floodgate/FloodgateHook.java | 55 --------- .../listener/protocollib/NameCheckTask.java | 15 +-- .../protocollib/ProtocolLibListener.java | 6 +- .../ProtocolSupportListener.java | 11 -- .../fastlogin/bungee/FastLoginBungee.java | 6 + .../bungee/task/AsyncPremiumCheck.java | 8 -- .../fastlogin/core/hooks/FloodgateHook.java | 111 ++++++++++++++++++ .../fastlogin/core/shared/JoinManagement.java | 66 +---------- .../fastlogin/core/shared/PlatformPlugin.java | 2 + 10 files changed, 127 insertions(+), 155 deletions(-) delete mode 100644 bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/floodgate/FloodgateHook.java create mode 100644 core/src/main/java/com/github/games647/fastlogin/core/hooks/FloodgateHook.java diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index 067bd9b6..8277b231 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -278,7 +278,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.github.games647.fastlogin.bukkit.hook.floodgate; - -import org.bukkit.Bukkit; -import org.geysermc.floodgate.api.FloodgateApi; -import org.geysermc.floodgate.api.player.FloodgatePlayer; - -public class FloodgateHook { - - public FloodgateHook() { } - - /** - * The FloodgateApi does not support querying players by name, so this function - * iterates over every online FloodgatePlayer and checks if the requested - * username can be found - * - * @param username the name of the player - * @return FloodgatePlayer if found, null otherwise - */ - public FloodgatePlayer getFloodgatePlayer(String username) { - if (Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate")) { - for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) { - if (floodgatePlayer.getUsername().equals(username)) { - return floodgatePlayer; - } - } - } - return null; - } - -} 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 e1e1bbe6..fcd47edf 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 @@ -30,7 +30,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.hook.floodgate.FloodgateHook; import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.shared.JoinManagement; import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; @@ -40,7 +39,6 @@ import java.util.Random; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.geysermc.floodgate.api.player.FloodgatePlayer; public class NameCheckTask extends JoinManagement implements Runnable { @@ -54,10 +52,9 @@ public class NameCheckTask extends JoinManagement + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.github.games647.fastlogin.core.hooks; + +import java.io.IOException; +import java.util.Optional; + +import com.github.games647.craftapi.model.Profile; +import com.github.games647.craftapi.resolver.RateLimitException; +import com.github.games647.fastlogin.core.shared.FastLoginCore; +import com.github.games647.fastlogin.core.shared.LoginSource; + +import org.geysermc.floodgate.api.FloodgateApi; +import org.geysermc.floodgate.api.player.FloodgatePlayer; + +public class FloodgateHook

{ + + private final FastLoginCore core; + + public FloodgateHook(FastLoginCore core) { + this.core = core; + } + + /** + * Check if the player's name conflicts an existing Java player's name, and + * kick them if it does + * + * @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) 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); + } + } + + /** + * The FloodgateApi does not support querying players by name, so this function + * iterates over every online FloodgatePlayer and checks if the requested + * username can be found + * + * @param username the name of the player + * @return FloodgatePlayer if found, null otherwise + */ + public FloodgatePlayer getFloodgatePlayer(String username) { + if (core.getPlugin().isPluginInstalled("floodgate")) { + for (FloodgatePlayer floodgatePlayer : FloodgateApi.getInstance().getPlayers()) { + if (floodgatePlayer.getUsername().equals(username)) { + return floodgatePlayer; + } + } + } + return null; + } + +} 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 2528ff7b..ec129a8d 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 @@ -29,9 +29,9 @@ import com.github.games647.craftapi.model.Profile; import com.github.games647.craftapi.resolver.RateLimitException; import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.hooks.AuthPlugin; +import com.github.games647.fastlogin.core.hooks.FloodgateHook; import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; -import java.io.IOException; import java.util.Optional; import org.geysermc.floodgate.api.player.FloodgatePlayer; @@ -42,10 +42,12 @@ public abstract class JoinManagement

{ protected final FastLoginCore core; protected final AuthPlugin

authHook; + private final FloodgateHook floodgateHook; public JoinManagement(FastLoginCore core, AuthPlugin

authHook) { this.core = core; this.authHook = authHook; + this.floodgateHook = new FloodgateHook<>(core); } public void onLogin(String username, S source) { @@ -56,10 +58,10 @@ public abstract class JoinManagement

{ } //check if the player is connecting through Floodgate - Object floodgatePlayer = getFloodgatePlayer(username); + FloodgatePlayer floodgatePlayer = floodgateHook.getFloodgatePlayer(username); if (floodgatePlayer != null) { - checkFloodgateNameConflict(username, source, floodgatePlayer); + floodgateHook.checkFloodgateNameConflict(username, source, floodgatePlayer); return; } callFastLoginPreLoginEvent(username, source, profile); @@ -141,64 +143,6 @@ 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, Object floodgatePlayer) { - String allowConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase(); - - // check if the Bedrock player is linked to a Java account - boolean isLinked = ((FloodgatePlayer) 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); - } - } - - /** - * Gets a FloodgatePlayer based on name or UUID Note: Don't change the return - * type from Object to FloodgatePlayer, unless you want ProtocolSupport to throw - * an error if Floodgate is not installed - * - * @param id UUID for BungeeCord, username for Bukkit - * @return an instance of FloodgatePlayer, if Floodgate is installed and a - * player is found
- * null if Floodgate is unavailable - */ - protected abstract Object 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); diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java index 5761359e..11971e45 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java @@ -45,6 +45,8 @@ public interface PlatformPlugin { AsyncScheduler getScheduler(); + boolean isPluginInstalled(String name); + default void sendMultiLineMessage(C receiver, String message) { for (String line : message.split("%nl%")) { sendMessage(receiver, line);