Class EventManager

java.lang.Object
dev.despical.whackme.api.EventManager

public final class EventManager extends Object
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 Details

    • EventManager

      public EventManager(WhackMe plugin)
      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

      public <T extends org.bukkit.event.Event> T callByType(EventType type, Supplier<T> supplier)
      Creates and dispatches an event while validating it against the expected EventType mapping.
      Type Parameters:
      T - concrete event type
      Parameters:
      type - expected logical event type
      supplier - 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

      public void gameStart(Game game)
      Announces that a game has entered active play.
      Parameters:
      game - game that has started
    • gameEnd

      public void gameEnd(Game game)
      Announces that a game has reached its normal ending phase.
      Parameters:
      game - game that has ended
    • gameStateChange

      public GameStateChangeEvent gameStateChange(Game game, GameState oldState, GameState newState)
      Fires the cancellable event raised before a game state transition.
      Parameters:
      game - game whose state is changing
      oldState - state currently assigned to the game
      newState - requested destination state
      Returns:
      processed state change event
    • gameStop

      public void gameStop(Game game, StopReason reason, List<UUID> stoppedPlayers)
      Announces that a game was forcefully stopped.
      Parameters:
      game - stopped game
      reason - reason that triggered the stop
      stoppedPlayers - immutable snapshot source of affected player UUIDs
    • playerJoinAttempt

      public PlayerJoinAttemptEvent playerJoinAttempt(org.bukkit.entity.Player player, Game game)
      Fires the cancellable event raised before a player is added to a game.
      Parameters:
      player - player attempting to join
      game - 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 game
      game - game the player is leaving
      reason - 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 changing
      stat - statistic definition being updated
      oldValue - value currently stored
      newValue - requested replacement value
      Returns:
      processed statistic change event