Skip to content
This repository was archived by the owner on Aug 10, 2023. It is now read-only.
Findlay Richardson edited this page Jun 23, 2023 · 4 revisions

EventListener

Event listeners are annotated with a net.zenoc.gallium.api.annotations.EventListener

In this example, we will use a ServerStartEvent

The name of the method doesn't matter, as long as the parameters are correct.

package net.zenoc.gallium.test.listeners;

import net.zenoc.gallium.api.annotations.EventListener;
import net.zenoc.gallium.api.event.player.PlayerJoinEvent;
import net.zenoc.gallium.api.logging.LogManager;
import org.apache.logging.log4j.Logger;

public class TestListener {
    private static final Logger log = LogManager.getLogger();
    @EventListener
    public void playerJoinEvent(ServerStartEvent event) {
        log.info("Hello, world");
    }
}

Adding to the plugin

EventListeners have to be registered in your plugin like so

package net.zenoc.gallium.test;

import net.zenoc.gallium.api.annotations.PluginLifecycleListener;
import net.zenoc.gallium.plugin.PluginLifecycleState;
import net.zenoc.gallium.plugin.java.JavaPlugin;

public class GalliumPlugin extends JavaPlugin {
    @PluginLifecycleListener(PluginLifecycleState.ENABLED)
    public void onPluginEnable() {
        Gallium.getEventManager().registerEvent(new TestListener());
    }
}

Clone this wiki locally