Events - SpleefX/SpleefX GitHub Wiki
This page documents the built-in event API and how to use it.
Creating a listener
To create a listener, you have 3 choices:
- Extend
net.spleefx.event.listen.EventListenerAdapterand override the methods for the event you want to listen to.
Method names follow the convention void onXYZ(XYZEvent event).
import net.spleefx.event.arena.end.PostArenaEndEvent;
import net.spleefx.event.listen.EventListenerAdapter;
public class TestListener extends EventListenerAdapter {
@Override public void onPostArenaEnd(PostArenaEndEvent event) {
event.getGameSummary();
event.getArena();
event.getTrackedPlayers();
...
}
}
- Implement
net.spleefx.event.listen.EventListenerand override theonEvent(Event)method
import net.spleefx.event.SpleefXEvent;
import net.spleefx.event.arena.end.PostArenaEndEvent;
import net.spleefx.event.listen.EventListener;
import org.jetbrains.annotations.NotNull;
public class TestListener implements EventListener {
@Override public void onEvent(@NotNull SpleefXEvent e) {
if (!(e instanceof PostArenaEndEvent)) return;
PostArenaEndEvent event = (PostArenaEndEvent) e;
...
}
}
- Implement
net.spleefx.event.listen.EventListeneras a lambda
EventListener listener = ev -> {
if (!(ev instanceof PostArenaEndEvent)) return;
PostArenaEndEvent event = (PostArenaEndEvent) ev;
...
};
Registering a listener
To register a listener, use EventListener#register(listener) in your onEnable()
import net.spleefx.event.listen.EventListener;
import org.bukkit.plugin.java.JavaPlugin;
public class TestPlugin extends JavaPlugin {
@Override
public void onEnable() {
EventListener.register(new TestListener()); // or the lambda
}
}
Events list
All events extend net.spleefx.event.SpleefXEvent. Some events may also share a common abstract class, such as net.spleefx.event.arena.ArenaEvent.
Arena events
Common methods:
-
MatchArena getArena(): Returns the arena that the event occurred in. -
ReloadedArenaEngine getEngine(): Returns the engine of the arena (responsible for controlling arena stages, like starting, countdown, ending, etc.) -
MatchExtension getExtension(): Returns the extension/type of the arena.
ArenaRegenerateEvent
Fired when an arena finishes regenerating
TeamLoseEvent
Fired when a team has been eliminated
Methods:
ImmutableArenaTeam getTeam(): Returns the team that lost in the arena
TeamWinEvent
Fired when a team wins in the game
Methods:
ImmutableArenaTeam getTeam(): Returns the team that won in the game
PreArenaEndEvent
Fired before the arena is completely finished. As in, player stats, bets, abilities, and so are still stored and available to access.
Methods:
-
ImmutableList<MatchPlayer> getTrackedPlayers(): Returns an immutable list of the players that are still tracked by this arena. As in, the players that will receive the summary reports as well as other messages from the arena. -
GameSummary getGameSummary(): Returns the (immutable) summary of the arena. This contains lots of useful information such as the winners, the player stats, the survival times and such. -
boolean isForcibly(): Returns whether the arena was ended forcibly or not (i.e when the server is stopped while a game is active)
PostArenaEndEvent
Fired after the arena is finished. When fired, the arena no longer stores information about its previous game, and everything is summed up here.
Methods:
-
ImmutableList<MatchPlayer> getTrackedPlayers(): Returns an immutable list of the players that are still tracked by this arena. As in, the players that will receive the summary reports as well as other messages from the arena. -
GameSummary getGameSummary(): Returns the (immutable) summary of the arena. This contains lots of useful information such as the winners, the player stats, the survival times and such. -
boolean isForcibly(): Returns whether the arena was ended forcibly or not (i.e when the server is stopped while a game is active)
Player events
Common methods:
-
MatchArena getArena(): Returns the arena in which the event occurred in. -
MatchExtension getExtension(): Returns the extension of the arena. -
ReloadedArenaEngine getEngine(): Returns the engine of the arena (responsible for controlling arena stages, like starting, countdown, ending, etc.) -
MatchPlayer getPlayer(): Returns the player involved in the event
PlayerLoseEvent
Fired when a player is eliminated in the game (both FFA and teams).
PlayerWinEvent
Fired when a player wins. This triggers for both FFA winners and team winners.
PlayerPutInTeamEvent
Fired when the player is put in a team in a teams arena. This event is useful as it allows for manipulating the team in which the player is put in.
Methods:
-
ArenaTeam getTeam(): Returns the team the player was put in. -
void setTeam(@NotNull ArenaTeam team): Sets the team in which the player should be put in.
PlayerDestroyBlockInArenaEvent
Fired when a block is destroyed by a player in an arena. This is not restricted to physically breaking blocks; it will also include blocks broken by the projectiles in splegg and bow spleef.
Methods:
-
Block getLocation(): Returns the location of the block that was destroyed. -
BreakContext getContext(): Returns the context/type of the block break.
/**
* Represents how the block was broken
*/
public enum BreakContext {
/**
* The block was mined manually (e.g a tool) or in a spleef snowball
*/
MINED,
/**
* The block was shot by the splegg shooting tool
*/
SHOT_SPLEGG,
/**
* The block was shot by bow spleef's bow
*/
SHOT_BOW_SPLEEF,
/**
* The block was broken in an undefined context
*/
OTHER
}
PlayerDoubleJumpEvent
Fired when the player double-jumps in an arena.
Methods:
-
boolean isCancelled(): Returns whether was the double jump cancelled or not -
void setCancelled(boolean cancelled): Sets whether is the double jump cancelled or not -
int getDoubleJumpsLeft(): Returns the amount of double jumps left for the player
Booster events
Common methods:
BoosterInstance getBooster(): Returns the instance of the booster that was involved in the event
BoosterActivatedEvent
Fired when a player activates a booster
BoosterPausedEvent
Fired when a player pauses a booster