|
62 | 62 | import javax.crypto.NoSuchPaddingException; |
63 | 63 |
|
64 | 64 | import io.netty.channel.Channel; |
| 65 | +import io.netty.util.AttributeKey; |
65 | 66 | import lombok.val; |
66 | 67 | import org.bukkit.entity.Player; |
| 68 | +import org.geysermc.floodgate.api.player.FloodgatePlayer; |
67 | 69 |
|
68 | 70 | import static com.comphenix.protocol.PacketType.Login.Client.ENCRYPTION_BEGIN; |
69 | 71 | import static com.comphenix.protocol.PacketType.Login.Client.START; |
@@ -115,6 +117,11 @@ public void onPacketReceiving(PacketEvent packetEvent) { |
115 | 117 | Player sender = packetEvent.getPlayer(); |
116 | 118 | PacketType packetType = packetEvent.getPacketType(); |
117 | 119 | if (packetType == START) { |
| 120 | + |
| 121 | + if (plugin.getFloodgateService() != null) { |
| 122 | + processFloodgateTasks(packetEvent); |
| 123 | + } |
| 124 | + |
118 | 125 | PacketContainer packet = packetEvent.getPacket(); |
119 | 126 |
|
120 | 127 | InetSocketAddress address = sender.getAddress(); |
@@ -276,7 +283,45 @@ private static PlayerInjectionHandler getHandler() { |
276 | 283 | } |
277 | 284 | } |
278 | 285 |
|
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); |
281 | 326 | } |
282 | 327 | } |
0 commit comments