Skip to content

Commit 8859ebb

Browse files
committed
Manually append Floodgate Prefixes
This can be used as a workaround for TuxCoding#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.
1 parent 06a8d6c commit 8859ebb

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
*/
2626
package com.github.games647.fastlogin.bukkit;
2727

28+
import com.comphenix.protocol.ProtocolLibrary;
2829
import com.github.games647.fastlogin.bukkit.command.CrackedCommand;
2930
import com.github.games647.fastlogin.bukkit.command.PremiumCommand;
3031
import com.github.games647.fastlogin.bukkit.listener.ConnectionListener;
3132
import com.github.games647.fastlogin.bukkit.listener.PaperCacheListener;
33+
import com.github.games647.fastlogin.bukkit.listener.protocollib.ManualNameChange;
3234
import com.github.games647.fastlogin.bukkit.listener.protocollib.ProtocolLibListener;
3335
import com.github.games647.fastlogin.bukkit.listener.protocollib.SkinApplyListener;
3436
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
@@ -115,6 +117,8 @@ public void onEnable() {
115117
pluginManager.registerEvents(new ProtocolSupportListener(this, core.getRateLimiter()), this);
116118
} else if (pluginManager.isPluginEnabled("ProtocolLib")) {
117119
ProtocolLibListener.register(this, core.getRateLimiter());
120+
//TODO: make configurable & check if it's needed
121+
ProtocolLibrary.getProtocolManager().addPacketListener(new ManualNameChange(this));
118122

119123
//if server is using paper - we need to set the skin at pre login anyway, so no need for this listener
120124
if (!PaperLib.isPaper() && getConfig().getBoolean("forwardSkin")) {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2015-2021 <Your name and contributors>
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*/
26+
package com.github.games647.fastlogin.bukkit.listener.protocollib;
27+
28+
import com.comphenix.protocol.events.PacketAdapter;
29+
import com.comphenix.protocol.events.PacketContainer;
30+
import com.comphenix.protocol.events.PacketEvent;
31+
import com.comphenix.protocol.wrappers.WrappedGameProfile;
32+
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
33+
34+
import org.geysermc.floodgate.api.FloodgateApi;
35+
36+
import static com.comphenix.protocol.PacketType.Login.Client.START;
37+
38+
/**
39+
* Manually inject Floodgate player name prefixes.
40+
* <br>
41+
* This is used as a workaround, because Floodgate fails to inject
42+
* the prefixes when it's used together with ProtocolLib and FastLogin.
43+
* <br>
44+
* For more information visit: https://github.com/games647/FastLogin/issues/493
45+
*/
46+
public class ManualNameChange extends PacketAdapter {
47+
48+
public ManualNameChange(FastLoginBukkit plugin) {
49+
super(params()
50+
.plugin(plugin)
51+
.types(START));
52+
53+
this.plugin = plugin;
54+
}
55+
56+
@Override
57+
public void onPacketReceiving(PacketEvent packetEvent) {
58+
PacketContainer packet = packetEvent.getPacket();
59+
WrappedGameProfile originalProfile = packet.getGameProfiles().read(0);
60+
packet.setMeta("original_name", originalProfile.getName());
61+
String prefixedName = FloodgateApi.getInstance().getPlayerPrefix() + originalProfile.getName();
62+
WrappedGameProfile updatedProfile = originalProfile.withName(prefixedName);
63+
packet.getGameProfiles().write(0, updatedProfile);
64+
}
65+
}

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ private void onLogin(PacketEvent packetEvent, Player player) {
124124
PacketContainer packet = packetEvent.getPacket();
125125

126126
String username = packet.getGameProfiles().read(0).getName();
127+
128+
if (packetEvent.getPacket().getMeta("original_name").isPresent()) {
129+
//username has been injected by ManualNameChange.java
130+
username = (String) packetEvent.getPacket().getMeta("original_name").get();
131+
}
132+
127133
plugin.getLog().trace("GameProfile {} with {} connecting", sessionKey, username);
128134

129135
packetEvent.getAsyncMarker().incrementProcessingDelay();

0 commit comments

Comments
 (0)