Class PlayerStatisticChangeEvent<T>

java.lang.Object
org.bukkit.event.Event
dev.despical.whackme.api.event.WhackMeEvent
dev.despical.whackme.api.event.player.PlayerEvent
dev.despical.whackme.api.event.player.PlayerStatisticChangeEvent<T>
Type Parameters:
T - value type of the statistic requested through the user statistics API.
All Implemented Interfaces:
org.bukkit.event.Cancellable

public class PlayerStatisticChangeEvent<T> extends PlayerEvent implements org.bukkit.event.Cancellable
Called before a player's statistic value is stored in the Whack Me user model.

Listeners may cancel the update or replace getNewValue() through setNewValue(Object). The event covers both persistent statistics and temporary per-run statistics.

@EventHandler
public void onStatisticChange(PlayerStatisticChangeEvent<Integer> event) {
    if (event.getStatisticType() == Statistics.LOCAL_SCORE) {
        event.setNewValue(Math.max(0, event.getNewValue()));
    }
}
API Note: Database loading bypasses this event; it represents runtime changes
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.bukkit.event.Event

    org.bukkit.event.Event.Result
  • Constructor Summary

    Constructors
    Constructor
    Description
    PlayerStatisticChangeEvent(org.bukkit.entity.Player player, StatisticType<T> statisticType, T oldValue, T newValue)
    Creates a statistic change event.
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.bukkit.event.HandlerList
     
    @NotNull org.bukkit.event.HandlerList
    Returns the value that will be stored if the event is not cancelled.
    Returns the value stored before this update.
    Returns the statistic definition being updated.
    boolean
    Returns whether the statistic update has been cancelled.
    void
    setCancelled(boolean cancel)
    Sets whether the statistic update should be discarded.
    void
    setNewValue(T newValue)
    Replaces the value that will be stored.

    Methods inherited from class PlayerEvent

    getPlayer, getUser, toString

    Methods inherited from class org.bukkit.event.Event

    callEvent, getEventName, isAsynchronous

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PlayerStatisticChangeEvent

      public PlayerStatisticChangeEvent(org.bukkit.entity.Player player, StatisticType<T> statisticType, T oldValue, T newValue)
      Creates a statistic change event.
      Parameters:
      player - player whose statistic is changing
      statisticType - statistic definition being updated
      oldValue - value currently stored
      newValue - requested replacement value
  • Method Details

    • getStatisticType

      public StatisticType<T> getStatisticType()
      Returns the statistic definition being updated.
      Returns:
      statistic definition
    • getOldValue

      public T getOldValue()
      Returns the value stored before this update.
      Returns:
      previous statistic value
    • getNewValue

      public T getNewValue()
      Returns the value that will be stored if the event is not cancelled.
      Returns:
      proposed statistic value
    • setNewValue

      public void setNewValue(T newValue)
      Replaces the value that will be stored.
      Parameters:
      newValue - replacement statistic value
    • isCancelled

      public boolean isCancelled()
      Returns whether the statistic update has been cancelled.
      Specified by:
      isCancelled in interface org.bukkit.event.Cancellable
      Returns:
      true when the value must not be stored
    • setCancelled

      public void setCancelled(boolean cancel)
      Sets whether the statistic update should be discarded.
      Specified by:
      setCancelled in interface org.bukkit.event.Cancellable
      Parameters:
      cancel - true to reject the update
    • getHandlers

      @NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()
      Specified by:
      getHandlers in class org.bukkit.event.Event
    • getHandlerList

      public static org.bukkit.event.HandlerList getHandlerList()