crwdns118311:0crwdne118311:0

crwdns118313:0:javadoc:crwdne118313:0

import org.spongepowered.api.event.Listener;

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

crwdns118315:0crwdne118315:0

Tip

crwdns118317:0:javadoc:crwdne118317:0

Note

crwdns118319:0:javadoc:crwdnd118319:0:javadoc:crwdne118319:0

crwdns118321:0crwdne118321:0

crwdns118323:0:javadoc:crwdne118323:0

crwdns118325:0crwdne118325: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());

crwdns118327:0crwdne118327:0

crwdns118329:0:javadoc:crwdne118329:0

crwdns118331:0crwdne118331: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 {
        [...]
    }
}

crwdns118333:0crwdne118333:0

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

Tip

crwdns118335:0crwdne118335:0

crwdns118337:0crwdne118337:0

crwdns118339:0:javadoc:crwdne118339:0

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

crwdns118341:0:javadoc:crwdne118341:0

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

crwdns118343:0crwdne118343:0

crwdns118345:0crwdne118345:0

  • crwdns118347:0:javadoc:crwdne118347:0

  • crwdns118349:0crwdne118349:0

crwdns118351:0crwdne118351:0

crwdns118353:0crwdne118353:0

crwdns118355:0:javadoc:crwdne118355:0

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

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

crwdns118357:0crwdne118357:0

crwdns118359:0crwdne118359:0

crwdns118361:0:javadoc:crwdne118361:0

crwdns118363:0:javadoc:crwdne118363:0

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

crwdns118365:0crwdne118365:0

crwdns118367:0crwdne118367:0

crwdns118369:0:javadoc:crwdne118369:0

crwdns118371:0crwdne118371:0

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

PluginContainer plugin = ...;
EventContext eventContext = EventContext.builder().add(EventContextKeys.PLUGIN, plugin).build();

LightningEvent lightningEvent = SpongeEventFactory.createLightningEventPre(Cause.of(eventContext, plugin));
Sponge.getEventManager().post(lightningEvent);

Warning

crwdns118373:0:javadoc:crwdne118373:0