-
Notifications
You must be signed in to change notification settings - Fork 4
Initializing & Registering a Listener
Due to the way PacketEntityAPI supports shading, you must call a static initializer function in your #onEnable to get an instance. The method accepts a plugin object and a function to run once the API is complete. This function is where you should register listeners and store a copy of the API for later use. For example:
public void onEnable() {
PacketEntityAPI.initialize(this, api -> api.addListener(new ExampleListener()));
}To register a listener, use the IPacketEntityAPI#addListener(IListener) method. Pass in an instance of your class which overrides the default interface implementations
Here is an example listener:
public class ExampleListener implements IListener {
@Override
public ListenerPriority getPriority() { return ListenerPriority.NORMAL; }
@Override
public void onEvent(IEntityPacketEvent e) {
System.out.println("A packet event was fired!");
}
@Override
public EntityType[] getTargets() { return new EntityType[]{ EntityType.SHEEP }; }
}For more information about the overrideable methods, click here.
If you would like to fire the listener for fake entities (entities which do not actually exist server-side), then override IListener#shouldFireForFake.
If you would like to fire the listener for click events on custom entity hitboxes (note: special cases exist. See Javadocs for IFakeEntity#setHitbox for more information.), then override IListener#requiresCollidable.