PacketInjectorAPI uses
LightInjector to inject packets. Therefore, it allows to intercept every packet intercepted by LightInjector, which are every game packet and some login packets. For the latter, a Player instance might not be always available. In this case, calling
event.getPlayer() will return
null.
See LightInjector javadoc for more information.
Code (Java):
Player player
= event.
getPlayer();// Might be null (see above) Object packet
= event.
getPacket(); String packetClassName
= event.
getPacketName(); event.
setCancelled(true);// Stops the packet event.
setPacket(newPacket
); Object value
= event.
getValue("fieldName"); event.
setValue("fieldName", value
);
You can also register send and receive events separately (even using lambdas):
Commands: The plugin comes with a packet logger which can print every packet (or only certain packets) to the console. It is managed using the following commands:
Code (YAML):
# Starts the packet logger /packetinjectorapi packetlogger start
# Stops the packet logger /packetinjectorapi packetlogger stop
# Prints a message with the status of the packet logger (enabled|disabled) /packetinjectorapi packetlogger status
# The filter subcommand allows to select the packets to be printed # More on this down below /packetinjectorapi packetlogger filter <allow|deny|list|reset|clear>
...
The filter gives you the power to exclude or to include only certain packets from being print. The filter subcommands are the following:
Code (YAML):
# Add, remove, clear or reset to default the list of allowed packets # Allowed packets are the only ones to be printed to the console, except when they are also denied /packetinjectorapi packetlogger filter allow <add|remove|clear|reset>
...
# Add, remove, clear or reset to default the list of denied packets # Denied packets are not printed to the console # By default, the deny list contains some packets to prevent the flooding of the console, run the "clear" subcommand if you need those packets # The list of default denied packets can be seen using the "list" filter subcommand or can be found at this link: # https://github.com/frengor/PacketInjectorAPI/blob/main/src/main/java/com/fren_gor/packetInjectorAPI/Commands.java#L50 /packetinjectorapi packetlogger filter deny <add|remove|clear|reset>
...
# Lists the allowed and denied packets /packetinjectorapi packetlogger filter list
# Resets the allowed and denied lists to their default values /packetinjectorapi packetlogger filter reset
# Clears the allow and deny lists /packetinjectorapi packetlogger filter clear