Here's how you can create the PacketEvents Instance.
Here is an example of a class that initializes and terminates a PacketEvents instance on Bukkit.
importcom.github.retrooper.packetevents.PacketEvents;importcom.github.retrooper.packetevents.event.PacketListenerPriority;importio.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;importorg.bukkit.plugin.java.JavaPlugin;publicclassMainextendsJavaPlugin { @OverridepublicvoidonLoad() {PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));//On Bukkit, calling this here is essential, hence the name "load"PacketEvents.getAPI().load(); } @OverridepublicvoidonEnable() {//Initialize!PacketEvents.getAPI().init(); } @OverridepublicvoidonDisable() {//Terminate the instance (clean up process)PacketEvents.getAPI().terminate(); }}
More examples are available on our examples repository