crwdns129233:0crwdne129233:0

crwdns129235:0:javadoc:crwdne129235:0

import org.spongepowered.api.event.Listener;

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

crwdns129237:0crwdne129237:0

Tip

crwdns129239:0:javadoc:crwdne129239:0

Note

crwdns129241:0:javadoc:crwdnd129241:0:javadoc:crwdne129241:0

crwdns129243:0crwdne129243:0

crwdns129245:0:javadoc:crwdne129245:0

crwdns129247:0crwdne129247: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());

crwdns129249:0crwdne129249:0

crwdns129251:0:javadoc:crwdne129251:0

crwdns129253:0crwdne129253: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 {
        ...
    }
}

crwdns129255:0crwdne129255:0

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

Tip

crwdns129257:0crwdne129257:0

crwdns129259:0crwdne129259:0

crwdns129261:0:javadoc:crwdne129261:0

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

crwdns129263:0:javadoc:crwdne129263:0

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

crwdns129265:0crwdne129265:0

crwdns129267:0crwdne129267:0

  • crwdns129269:0:javadoc:crwdne129269:0

  • crwdns129271:0crwdne129271:0

crwdns129273:0crwdne129273:0

crwdns129275:0crwdne129275:0

crwdns129277:0:javadoc:crwdne129277:0

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

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

crwdns129279:0crwdne129279:0

crwdns129281:0crwdne129281:0

crwdns129283:0:javadoc:crwdne129283:0

crwdns129285:0:javadoc:crwdne129285:0

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

crwdns129287:0crwdne129287:0

crwdns129289:0crwdne129289:0

crwdns129291:0:javadoc:crwdnd129291:0:javadoc:crwdne129291:0

crwdns129293:0crwdne129293: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

crwdns129295:0:javadoc:crwdne129295:0