From 8859ebb454e29db6a1c6839ca967ab761ddf1a6c Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Tue, 29 Jun 2021 15:10:15 +0200 Subject: [PATCH 1/3] Manually append Floodgate Prefixes This can be used as a workaround for #493 This will leave https://github.com/GeyserMC/Floodgate/blob/821be02bdb179f7d4ba7b0ec79bbc721c28105f5/spigot/src/main/java/org/geysermc/floodgate/addon/data/SpigotDataHandler.java in a limbo state, but it shouldn't have a noticable impact on neither performance nor stability. This commit will try append prefixes to every player, even if it's not needed of if Floodgate isn't installed. --- .../fastlogin/bukkit/FastLoginBukkit.java | 4 ++ .../protocollib/ManualNameChange.java | 65 +++++++++++++++++++ .../protocollib/ProtocolLibListener.java | 6 ++ 3 files changed, 75 insertions(+) create mode 100644 bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ManualNameChange.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 28a4f3d6..19e0043c 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 @@ -25,10 +25,12 @@ */ package com.github.games647.fastlogin.bukkit; +import com.comphenix.protocol.ProtocolLibrary; import com.github.games647.fastlogin.bukkit.command.CrackedCommand; import com.github.games647.fastlogin.bukkit.command.PremiumCommand; import com.github.games647.fastlogin.bukkit.listener.ConnectionListener; import com.github.games647.fastlogin.bukkit.listener.PaperCacheListener; +import com.github.games647.fastlogin.bukkit.listener.protocollib.ManualNameChange; import com.github.games647.fastlogin.bukkit.listener.protocollib.ProtocolLibListener; import com.github.games647.fastlogin.bukkit.listener.protocollib.SkinApplyListener; import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener; @@ -115,6 +117,8 @@ 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.listener.protocollib; + +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.wrappers.WrappedGameProfile; +import com.github.games647.fastlogin.bukkit.FastLoginBukkit; + +import org.geysermc.floodgate.api.FloodgateApi; + +import static com.comphenix.protocol.PacketType.Login.Client.START; + +/** + * Manually inject Floodgate player name prefixes. + *
+ * This is used as a workaround, because Floodgate fails to inject + * the prefixes when it's used together with ProtocolLib and FastLogin. + *
+ * For more information visit: https://github.com/games647/FastLogin/issues/493 + */ +public class ManualNameChange extends PacketAdapter { + + public ManualNameChange(FastLoginBukkit plugin) { + super(params() + .plugin(plugin) + .types(START)); + + this.plugin = plugin; + } + + @Override + public void onPacketReceiving(PacketEvent packetEvent) { + PacketContainer packet = packetEvent.getPacket(); + WrappedGameProfile originalProfile = packet.getGameProfiles().read(0); + packet.setMeta("original_name", originalProfile.getName()); + String prefixedName = FloodgateApi.getInstance().getPlayerPrefix() + originalProfile.getName(); + WrappedGameProfile updatedProfile = originalProfile.withName(prefixedName); + packet.getGameProfiles().write(0, updatedProfile); + } +} diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java index 11218623..1cb68105 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java @@ -124,6 +124,12 @@ public class ProtocolLibListener extends PacketAdapter { PacketContainer packet = packetEvent.getPacket(); String username = packet.getGameProfiles().read(0).getName(); + + if (packetEvent.getPacket().getMeta("original_name").isPresent()) { + //username has been injected by ManualNameChange.java + username = (String) packetEvent.getPacket().getMeta("original_name").get(); + } + plugin.getLog().trace("GameProfile {} with {} connecting", sessionKey, username); packetEvent.getAsyncMarker().incrementProcessingDelay(); From b92911bf267a0809bf0d5fa8af2d55f49714c834 Mon Sep 17 00:00:00 2001 From: Smart123s <28480228+Smart123s@users.noreply.github.com> Date: Tue, 29 Jun 2021 15:30:11 +0200 Subject: [PATCH 2/3] Made floodgatePrefixWorkaround configurable --- .../fastlogin/bukkit/FastLoginBukkit.java | 24 ++++++++++++------- core/src/main/resources/config.yml | 13 +++++++--- 2 files changed, 25 insertions(+), 12 deletions(-) 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 19e0043c..3a2ff8db 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 @@ -117,8 +117,21 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin Date: Tue, 29 Jun 2021 15:57:44 +0200 Subject: [PATCH 3/3] Only add Floodgate prefixes if they are needed Without this patch, Java players would also get a prefix. --- .../games647/fastlogin/bukkit/FastLoginBukkit.java | 2 +- .../listener/protocollib/ManualNameChange.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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 3a2ff8db..98b3b353 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 @@ -120,7 +120,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin