crwdns148459:0crwdne148459:0

crwdns148461:0:javadoc:crwdne148461:0

import org.spongepowered.api.event.Listener;

@Listener
public void onSomeEvent(SomeEvent event) {
    // Do something with the event
}

crwdns148463:0crwdne148463:0

Tip

crwdns148465:0:javadoc:crwdne148465:0

Note

crwdns148467:0:javadoc:crwdnd148467:0:javadoc:crwdne148467:0

crwdns148469:0crwdne148469:0

crwdns148471:0:javadoc:crwdne148471:0

crwdns148473:0crwdne148473:0

import org.spongepowered.api.Sponge;

public class ExampleListener {

    @Listener
    public void onSomeEvent(SomeEvent event) {
        // Do something with the event
    }
}

Sponge.getEventManager().registerListeners(this, new ExampleListener());

crwdns148475:0crwdne148475:0

crwdns148477:0:javadoc:crwdne148477:0

crwdns148479:0crwdne148479:0

import org.spongepowered.api.event.EventListener;
import org.spongepowered.api.event.block.ChangeBlockEvent;

public class ExampleListener implements EventListener<ChangeBlockEvent.Break> {

    @Override
    public void handle(ChangeBlockEvent.Break event) throws Exception {
        ...
    }
}

crwdns148481:0crwdne148481:0

EventListener<ChangeBlockEvent.Break> listener = new ExampleListener();
Sponge.getEventManager().registerListener(this, ChangeBlockEvent.Break.class, listener);

Tip

crwdns148483:0crwdne148483:0

crwdns148485:0crwdne148485:0

crwdns148487:0:javadoc:crwdne148487:0

EventListener listener = ...
Sponge.getEventManager().unregisterListeners(listener);

crwdns148489:0:javadoc:crwdne148489:0

MyPlugin plugin = ...
Sponge.getEventManager().unregisterPluginListeners(plugin);

crwdns148491:0crwdne148491:0

crwdns148493:0crwdne148493:0

  • crwdns148495:0:javadoc:crwdne148495:0

  • crwdns148497:0crwdne148497:0

crwdns148499:0crwdne148499:0

crwdns148501:0crwdne148501:0

crwdns148503:0:javadoc:crwdne148503:0

import org.spongepowered.api.event.game.GameReloadEvent;

@Listener
public void reload(GameReloadEvent event) {
    // Do reload stuff
}

crwdns148505:0crwdne148505:0

crwdns148507:0crwdne148507:0

crwdns148509:0:javadoc:crwdne148509:0

crwdns148511:0:javadoc:crwdne148511:0

boolean cancelled = Sponge.getEventManager().post(theEventObject);

crwdns148513:0crwdne148513:0

crwdns148515:0crwdne148515:0

crwdns148517:0:javadoc:crwdne148517:0

crwdns148519:0crwdne148519:0

import org.spongepowered.api.event.SpongeEventFactory;
import org.spongepowered.api.event.action.LightningEvent;
import org.spongepowered.api.event.cause.Cause;

LightningEvent lightningEvent = SpongeEventFactory.createLightningEvent(Cause.source(plugin).build());
Sponge.getEventManager().post(lightningEvent);

Warning

crwdns148521:0:javadoc:crwdne148521:0