Allow packet modifications by other plugins

If we disable filters, other plugins are advised to only monitor
packets. Potential modifications can be allowed by enabling the filtering again, but adding our meta data to prevent duplicate
processing.
This commit is contained in:
games647
2021-06-22 11:15:21 +02:00
parent 496817afca
commit 1f4757669c
2 changed files with 9 additions and 1 deletions

View File

@ -43,6 +43,8 @@ import static com.comphenix.protocol.PacketType.Login.Client.START;
public class ProtocolLibListener extends PacketAdapter {
public static final String SOURCE_META_KEY = "source";
private final FastLoginBukkit plugin;
//just create a new once on plugin enable. This used for verify token generation
@ -77,6 +79,11 @@ public class ProtocolLibListener extends PacketAdapter {
return;
}
if (packetEvent.getPacket().getMeta(SOURCE_META_KEY).map(val -> val.equals(plugin.getName())).orElse(false)) {
// this is our own packet
return;
}
Player sender = packetEvent.getPlayer();
PacketType packetType = packetEvent.getPacketType();
if (packetType == START) {

View File

@ -285,7 +285,8 @@ public class VerifyResponseTask implements Runnable {
startPacket.getGameProfiles().write(0, fakeProfile);
try {
//we don't want to handle our own packets so ignore filters
ProtocolLibrary.getProtocolManager().recieveClientPacket(player, startPacket, false);
ProtocolLibrary.getProtocolManager().recieveClientPacket(player, startPacket, true);
startPacket.setMeta(ProtocolLibListener.SOURCE_META_KEY, plugin.getName());
} catch (InvocationTargetException | IllegalAccessException ex) {
plugin.getLog().warn("Failed to fake a new start packet for: {}", username, ex);
//cancel the event in order to prevent the server receiving an invalid packet