Skip to content

Commit ae9772c

Browse files
committed
Reimplement skipped Floodgate tasks
Due to a bug in ProtocolLib, Floodgate will never execute some of its tasks if an async listener is registered. Related: GeyserMC/Floodgate#143 Skipped code: https://github.com/GeyserMC/Floodgate/blob/5d5713ed9e9eeab0f4abdaa9cf5cd8619dc1909b/spigot/src/main/java/org/geysermc/floodgate/addon/data/SpigotDataHandler.java#L121-L175 Fixes #786 Fixes #703 Fixes #689 Fixes #647
1 parent 25e71e8 commit ae9772c

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

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

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@
6262
import javax.crypto.NoSuchPaddingException;
6363

6464
import io.netty.channel.Channel;
65+
import io.netty.util.AttributeKey;
6566
import lombok.val;
6667
import org.bukkit.entity.Player;
68+
import org.geysermc.floodgate.api.player.FloodgatePlayer;
6769

6870
import static com.comphenix.protocol.PacketType.Login.Client.ENCRYPTION_BEGIN;
6971
import static com.comphenix.protocol.PacketType.Login.Client.START;
@@ -115,6 +117,11 @@ public void onPacketReceiving(PacketEvent packetEvent) {
115117
Player sender = packetEvent.getPlayer();
116118
PacketType packetType = packetEvent.getPacketType();
117119
if (packetType == START) {
120+
121+
if (plugin.getFloodgateService() != null) {
122+
processFloodgateTasks(packetEvent);
123+
}
124+
118125
PacketContainer packet = packetEvent.getPacket();
119126

120127
InetSocketAddress address = sender.getAddress();
@@ -276,7 +283,45 @@ private static PlayerInjectionHandler getHandler() {
276283
}
277284
}
278285

279-
private Channel getChannel(Player player) {
280-
return handler.getChannel(player);
286+
private FloodgatePlayer getFloodgatePlayer(Player player) {
287+
Channel channel = handler.getChannel(player);
288+
AttributeKey<FloodgatePlayer> floodgateAttribute = AttributeKey.valueOf("floodgate-player");
289+
return channel.attr(floodgateAttribute).get();
290+
}
291+
292+
/**
293+
* Reimplementation of the tasks injected Floodgate in ProtocolLib that are not run due to a bug
294+
* @see <a href="https://github.com/GeyserMC/Floodgate/issues/143">Issue Floodgate#143</a>
295+
* @see <a href="https://github.com/GeyserMC/Floodgate/blob/5d5713ed9e9eeab0f4abdaa9cf5cd8619dc1909b/spigot/src/main/java/org/geysermc/floodgate/addon/data/SpigotDataHandler.java#L121-L175">Floodgate/SpigotDataHandler</a>
296+
* @param packetEvent the PacketEvent that won't be processed by Floodgate
297+
*/
298+
private void processFloodgateTasks(PacketEvent packetEvent) {
299+
PacketContainer packet = packetEvent.getPacket();
300+
Player player = packetEvent.getPlayer();
301+
FloodgatePlayer floodgatePlayer = getFloodgatePlayer(player);
302+
if (floodgatePlayer == null) {
303+
return;
304+
}
305+
306+
// kick the player, if necessary
307+
Channel channel = handler.getChannel(packetEvent.getPlayer());
308+
//todo: add kick attribute (I just randomly typed in something, becaues it can't be empty)
309+
AttributeKey<String> kickMessageAttribute = AttributeKey.valueOf("kick-message");
310+
String kickMessage = channel.attr(kickMessageAttribute).get();
311+
if (kickMessage != null) {
312+
packetEvent.getPlayer().kickPlayer(kickMessage);
313+
return;
314+
}
315+
316+
// add prefix
317+
String username = floodgatePlayer.getCorrectUsername();
318+
if (packet.getGameProfiles().size() > 0) {
319+
packet.getGameProfiles().write(0,
320+
new WrappedGameProfile(floodgatePlayer.getCorrectUniqueId(), username));
321+
} else {
322+
packet.getStrings().write(0, username);
323+
}
324+
325+
// todo: pipeline().remove(SpigotDataHadler);
281326
}
282327
}

0 commit comments

Comments
 (0)