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.jar
on plugins folder and classpath of your IDE. -
On
onEnable
method 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.registerPacketListener
will register your packet listener to can be called when choosed packet get caught. -
(packet, player) -> {}
is your packet listener.packet
is the instance of the caught packet.player
is the player IF when the packet was caught has a player assigned with it. -
return Response.DEFAULT
is the response, a class that will tell toSimplePacketListener
if you want to cancel the packet. TheDEFAULT
response will not cancel and have a 0 priority. -
PacketStatusOutServerInfo.class
is 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)