-
Notifications
You must be signed in to change notification settings - Fork 35
API Documentation v5 Events
Events handlers can be used to extend the functionality of Shoulder Surfing Reloaded or implement compatibility features.
They need be registered to the event bus in the register method of a Shoulder Surfing plugin (see Plugins).
The following example registers a new ComputePlayerAimStateEventHandler with priority 1000, which sets the aiming state to true when the camera entity is holding a stick:
import com.github.exopandora.shouldersurfing.api.client.event.ComputePlayerAimStateEvent;
import com.github.exopandora.shouldersurfing.api.event.IEventBus;
import com.github.exopandora.shouldersurfing.api.plugin.IShoulderSurfingPlugin;
public class ExamplePlugin implements IShoulderSurfingPlugin {
@Override
public void register(IEventBus eventBus) {
eventBus.register(1000, (ComputePlayerAimStateEvent event) -> {
if (!event.getResult()) {
event.setResult(event.getEntity().getMainHandItem().is(Items.STICK));
}
});
}
}The default priority for event handlers is 1000. Event handlers are sorted by natural order, meaning that event handlers with a lower priority will be called first. If two event handlers are registered with the same priority, the event handler who was registered first will be called first.
Some events are cancellable, allowing consumers to call event.cancel().
This stops the event from being processed by any subsequent event handlers.
A list of available event types can be found here.
Shoulder Surfing Reloaded internally uses the plugin system to implement core functionality. The implementation can be found here.