crwdns137875:0crwdne137875:0

crwdns137877:0:javadoc:crwdne137877:0

import org.spongepowered.api.event.Listener;

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

crwdns137879:0crwdne137879:0

Tip

crwdns137881:0:javadoc:crwdne137881:0

Note

crwdns137883:0:javadoc:crwdnd137883:0:javadoc:crwdne137883:0

crwdns137885:0crwdne137885:0

crwdns156859:0:javadoc:crwdne156859:0

crwdns137889:0crwdne137889:0

import org.spongepowered.api.Sponge;

public class ExampleListener {

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

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

crwdns137891:0crwdne137891:0

crwdns137893:0:javadoc:crwdne137893:0

crwdns137895:0crwdne137895:0

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

public class ExampleListener implements EventListener<ChangeBlockEvent.All> {

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

crwdns137897:0crwdne137897:0

EventListener<ChangeBlockEvent.All> listener = new ExampleListener();
EventListenerRegistration registeration = EventListenerRegistration
    .builder(ChangeBlockEvent.All.class)
    .listener(listener)
    .plugin(pluginContainer)
    .build();
Sponge.eventManager().registerListener(registeration);

Tip

crwdns137899:0crwdne137899:0

crwdns137901:0crwdne137901:0

crwdns137903:0:javadoc:crwdne137903:0

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

crwdns137905:0:javadoc:crwdne137905:0

PluginContainer plugin = ...;
Sponge.eventManager().unregisterListeners(plugin);

crwdns137907:0crwdne137907:0

crwdns137909:0crwdne137909:0

  • crwdns137911:0:javadoc:crwdne137911:0

  • crwdns137913:0crwdne137913:0

crwdns137915:0crwdne137915:0

crwdns156861:0crwdne156861:0

crwdns156863:0:javadoc:crwdne156863:0

import org.spongepowered.api.event.lifecycle.RefreshGameEvent;

@Listener
public void refresh(GameRefreshEvent event) {
    // Do refresh stuff
}

crwdns137921:0crwdne137921:0

crwdns137923:0crwdne137923:0

crwdns137925:0:javadoc:crwdne137925:0

crwdns137927:0:javadoc:crwdne137927:0

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

crwdns137929:0crwdne137929:0