Apollo
Developers
Events

Events

Overview

Apollo provides its own listener based event system, similar to the existing event system found in Bukkit.

List of available Apollo events

ApolloRegisterPlayerEvent

ApolloRegisterPlayerEvent

Called when the player joins the server using Lunar Client.

FieldDescription
ApolloPlayer playerThe Apollo player that was registered.
ApolloUnregisterPlayerEvent

ApolloUnregisterPlayerEvent

Called when the player leaves the server using Lunar Client.

FieldDescription
ApolloPlayer playerThe Apollo player that was unregistered.
ApolloReceivePacketEvent

ApolloReceivePacketEvent

Called when the Apollo player receives an Apollo packet from Lunar Client.

FieldDescription
ApolloPlayer playerThe Apollo player that received the packet.
Any packetThe Apollo packet that was received.
ApolloSendPacketEvent

ApolloSendPacketEvent

Called when the Apollo player sends an Apollo packet to Lunar Client.

FieldDescription
ApolloPlayer playerThe Apollo player that sent the packet.
Any packetThe Apollo packet that was sent.
This event is cancellable.
ApolloUpdateOptionEvent

ApolloUpdateOptionEvent

Called when an option is updated.

FieldDescription
Options containerThe container that the option is in.
ApolloPlayer playerThe Apollo player the option was updated for, or null if it was a global option.
Option<?, ?, ?> optionThe option that was updated.
Object valueThe new value of the option.
This event is cancellable.

Integration

Sample Code (Method 1)

public class GeneralExample1 implements ApolloListener {
 
    public GeneralExample1() {
        EventBus.getBus().register(this);
    }
 
    @Listen
    public void onApolloRegister(ApolloRegisterPlayerEvent event) {
        ((Player) event.getPlayer()).sendMessage("You have joined using LunarClient!");
    }
}

Sample Code (Method 2)

public class GeneralExample2 implements ApolloListener {
 
    public GeneralExample2() {
        this.handle(ApolloRegisterPlayerEvent.class, this::onApolloRegister);
    }
 
    public void onApolloRegister(ApolloRegisterPlayerEvent event) {
        ((Player) event.getPlayer()).sendMessage("You have joined using LunarClient!");
    }
}

Creating Apollo events

Creating the event class

// Normal event
public class CoolApolloEvent implements Event {
 
    private final ApolloPlayer player;
 
    public CoolApolloEvent(ApolloPlayer player) {
        this.player = player;
    }
 
    public ApolloPlayer getPlayer() {
        return this.player;
    }
}
 
// Cancellable event
public class CoolApolloCancellableEvent implements EventCancellable {
 
    private final ApolloPlayer player;
 
    private boolean cancelled;
 
    public CoolApolloCancellableEvent(ApolloPlayer player) {
        this.player = player;
    }
 
    public ApolloPlayer getPlayer() {
        return this.player;
    }
 
    @Override
    public boolean isCancelled() {
        return this.cancelled;
    }
 
    @Override
    public void setCancelled(boolean cancel) {
        this.cancelled = cancel;
    }
}

Calling the created event

// Calling a normal event
public void callCoolApolloEvent(ApolloPlayer player) {
    CoolApolloEvent event = new CoolApolloEvent(player);
    EventBus.EventResult<CoolApolloEvent> result = EventBus.getBus().post(event);
 
    for (Throwable throwable : result.getThrowing()) {
        throwable.printStackTrace();
    }
}
 
// Calling a cancellable event
public void callCoolApolloCancellableEvent(ApolloPlayer player) {
    CoolApolloCancellableEvent event = new CoolApolloCancellableEvent(player);
    EventBus.EventResult<CoolApolloCancellableEvent> result = EventBus.getBus().post(event);
 
    if (!result.getEvent().isCancelled()) {
        // Do some action if the event is not cancelled
    }
 
    for (Throwable throwable : result.getThrowing()) {
        throwable.printStackTrace();
    }
}