Listening to events
banco-api provides an easy way to integrate events by using its built-in event system. Let's start by implementing BancoEventListener
into our DemoListener
:
import ovh.mythmc.banco.api.event.BancoEvent;
import ovh.mythmc.banco.api.event.BancoEventListener;
public final class DemoListener implements BancoEventListener {
@Override
public void handle(final BancoEvent Event event) {
// This code will run every time a BancoEvent is triggered
}
}
We can then check for the event we want to listen to:
import ovh.mythmc.banco.api.event.BancoEvent;
import ovh.mythmc.banco.api.event.BancoEventListener;
import ovh.mythmc.banco.api.event.impl.BancoTransactionEvent;
public final class DemoListener implements BancoEventListener {
@Override
public void handle(final BancoEvent event) {
// We want to check for BancoTransactionEvent
if(event instanceof BancoTransactionEvent transactionEvent) {
// This code will run every time a BancoTransactionEvent is triggered
System.out.println(transactionEvent);
}
}
}
Last but not least, we will register our DemoListener
using the banco API:
Banco.get().getEventManager().registerListener(new DemoListener());
Last updated