-
Notifications
You must be signed in to change notification settings - Fork 8
Events
Angelia provides an event API to let you react to your surrounding and whatever is happening. You simply create an event listener for an event of your choice and Angelia will automatically notify your listener when the event happens.
For example this eventhandler will print out any chat messages you receive:
public class ExampleHandler implements AngeliaListener {
@AngeliaEventHandler
public void handleChat(ChatMessageReceivedEvent e) {
System.out.println(e.getMessage());
}
}
When creating an event listener, the class containing the event handling method must implement AngeliaListener. The listener method must be annotated with @AngeliaEventHandler. Additionally to start listening you have to register the event listener. A complete example would be:
public class ExampleHandler implements AngeliaListener {
public ExampleHandler(ServerConnection connection) {
connection.getEventHandler().registerListener(this);
}
@AngeliaEventHandler
public void handleChat(ChatMessageReceivedEvent e) {
System.out.println(e.getMessage());
}
}
You can also unregister a listener to keep it from receiving further broadcasts, for example
public void stopListening(ServerConnection connection) {
connection.getEventHandler().unregisterListener(this);
}
For a full list of currently supported events see here or here. If you need an event that currently does not exist, feel free to make a pull request or bother me to add it.