LogoLogo
LogoLogo
  • What is PacketEvents?
  • Prerequisites
  • Getting Started
  • The PacketEvents Instance
  • Creating Your PacketEvents Instance
    • (Optional) Configuring PacketEvents
  • What is a PacketEvents Listener
  • Creating Your First Listener
  • Registering a Packet Listener
  • Sending and Simulating Packets
  • Advanced PacketEvents Example: Combining our Knowledge
  • FAQ (WIP)
Powered by GitBook
On this page

Was this helpful?

Creating Your PacketEvents Instance

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.

import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketListenerPriority;
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin {

    @Override
    public void onLoad() {
        PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
        //On Bukkit, calling this here is essential, hence the name "load"
        PacketEvents.getAPI().load();
    }

    @Override
    public void onEnable() {
        //Initialize!
        PacketEvents.getAPI().init();
    }

    @Override
    public void onDisable() {
        //Terminate the instance (clean up process)
        PacketEvents.getAPI().terminate();
    }
}

More examples are available on our examples repository

PreviousThe PacketEvents InstanceNext(Optional) Configuring PacketEvents

Last updated 11 months ago

Was this helpful?

GitHub - retrooper/packetevents-example: Official PacketEvents example repository.GitHub
Logo