Class EventManager
java.lang.Object
dev.despical.whackme.api.EventManager
Central dispatcher for every Bukkit event emitted by Whack Me.
Besides invoking Bukkit's plugin manager, the dispatcher records event timings when profiling is enabled and offers typed convenience methods for the plugin's game lifecycle.
External plugins usually consume this API through Bukkit listeners:
@EventHandler
public void onJoinAttempt(PlayerJoinAttemptEvent event) {
if (!event.getPlayer().hasPermission("whackme.play")) {
event.setCancelled(true);
}
}
API Note: Event dispatch must occur on a thread accepted by the relevant Bukkit event. Whack Me lifecycle helpers are intended to be called from the server thread.
-
Constructor Summary
ConstructorsConstructorDescriptionEventManager(WhackMe plugin) Creates the dispatcher and its profiler using the current configuration. -
Method Summary
Modifier and TypeMethodDescription<T extends org.bukkit.event.Event>
Tcall(T event) Dispatches an event through Bukkit and records its listener execution duration when profiling is enabled.<T extends org.bukkit.event.Event>
TcallByType(EventType type, Supplier<T> supplier) Creates and dispatches an event while validating it against the expectedEventTypemapping.voidAnnounces that a game has reached its normal ending phase.voidAnnounces that a game has entered active play.gameStateChange(Game game, GameState oldState, GameState newState) Fires the cancellable event raised before a game state transition.voidgameStop(Game game, StopReason reason, List<UUID> stoppedPlayers) Announces that a game was forcefully stopped.playerJoinAttempt(org.bukkit.entity.Player player, Game game) Fires the cancellable event raised before a player is added to a game.voidplayerLeave(org.bukkit.entity.Player player, Game game, PlayerLeaveGameEvent.LeaveReason reason) Announces that a player is about to be removed from a game.voidreload()Reloads event profiling flags from the plugin configuration.voidsendTimingsReport(org.bukkit.command.CommandSender sender) Sends the currently collected event timing report to a command sender.<T> PlayerStatisticChangeEvent<T> statChange(org.bukkit.entity.Player player, StatisticType<T> stat, T oldValue, T newValue) Fires the cancellable event raised before a statistic value is stored.
-
Constructor Details
-
EventManager
Creates the dispatcher and its profiler using the current configuration.- Parameters:
plugin- active Whack Me plugin instance
-
-
Method Details
-
call
public <T extends org.bukkit.event.Event> T call(T event) Dispatches an event through Bukkit and records its listener execution duration when profiling is enabled.- Type Parameters:
T- concrete event type- Parameters:
event- event instance to dispatch- Returns:
- the same event instance after listeners have processed it
-
callByType
Creates and dispatches an event while validating it against the expectedEventTypemapping.- Type Parameters:
T- concrete event type- Parameters:
type- expected logical event typesupplier- supplier that creates the event to dispatch- Returns:
- the dispatched event after listener processing
- Throws:
IllegalArgumentException- if the supplied event does not match the mapped class
-
sendTimingsReport
public void sendTimingsReport(org.bukkit.command.CommandSender sender) Sends the currently collected event timing report to a command sender.- Parameters:
sender- recipient of the formatted report
-
reload
public void reload()Reloads event profiling flags from the plugin configuration. -
gameStart
Announces that a game has entered active play.- Parameters:
game- game that has started
-
gameEnd
Announces that a game has reached its normal ending phase.- Parameters:
game- game that has ended
-
gameStateChange
Fires the cancellable event raised before a game state transition.- Parameters:
game- game whose state is changingoldState- state currently assigned to the gamenewState- requested destination state- Returns:
- processed state change event
-
gameStop
Announces that a game was forcefully stopped.- Parameters:
game- stopped gamereason- reason that triggered the stopstoppedPlayers- immutable snapshot source of affected player UUIDs
-
playerJoinAttempt
Fires the cancellable event raised before a player is added to a game.- Parameters:
player- player attempting to joingame- target game- Returns:
- processed join attempt event
-
playerLeave
public void playerLeave(org.bukkit.entity.Player player, Game game, PlayerLeaveGameEvent.LeaveReason reason) Announces that a player is about to be removed from a game.- Parameters:
player- player leaving the gamegame- game the player is leavingreason- reason for the departure
-
statChange
public <T> PlayerStatisticChangeEvent<T> statChange(org.bukkit.entity.Player player, StatisticType<T> stat, T oldValue, T newValue) Fires the cancellable event raised before a statistic value is stored.- Type Parameters:
T- statistic value type- Parameters:
player- player whose statistic is changingstat- statistic definition being updatedoldValue- value currently storednewValue- requested replacement value- Returns:
- processed statistic change event
-