Hello folks!
This is a simple project of a packet listener.
This project uses Java 8 lambda syntax(if you want) to get more simplicity to the developer :D
-
Put
SimplePacketListener.jaron plugins folder and classpath of your IDE. -
On
onEnablemethod of your plugin register a packet listener using this example:
SimplePacketListener.registerPacketListener((packet, player) -> {
PacketStatusOutServerInfo packetStatus = (PacketStatusOutServerInfo) packet;
return Response.DEFAULT;
}, PacketStatusOutServerInfo.class);- Put on plugin.yml:
depend: [SimplePacketListener]- Compile and run your plugin
-
SimplePacketListener.registerPacketListenerwill register your packet listener to can be called when choosed packet get caught. -
(packet, player) -> {}is your packet listener.packetis the instance of the caught packet.playeris the player IF when the packet was caught has a player assigned with it. -
return Response.DEFAULTis the response, a class that will tell toSimplePacketListenerif you want to cancel the packet. TheDEFAULTresponse will not cancel and have a 0 priority. -
PacketStatusOutServerInfo.classis the class of the packet that you want to listen.
I've created a simple class called Util on the project, and you and use it.
-
void Util.setFieldValue(class, obj, name, value) -
Optional<Object> Util.getFieldValue(class, obj, name)