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
ConstructorsConstructorDescriptionPlayerStatisticChangeEvent(org.bukkit.entity.Player player, StatisticType<T> statisticType, T oldValue, T newValue) Creates a statistic change event. -
Method Summary
Modifier and TypeMethodDescriptionstatic org.bukkit.event.HandlerList@NotNull org.bukkit.event.HandlerListReturns 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.booleanReturns whether the statistic update has been cancelled.voidsetCancelled(boolean cancel) Sets whether the statistic update should be discarded.voidsetNewValue(T newValue) Replaces the value that will be stored.Methods inherited from class PlayerEvent
getPlayer, getUser, toStringMethods inherited from class org.bukkit.event.Event
callEvent, getEventName, isAsynchronous
-
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 changingstatisticType- statistic definition being updatedoldValue- value currently storednewValue- requested replacement value
-
-
Method Details
-
getStatisticType
Returns the statistic definition being updated.- Returns:
- statistic definition
-
getOldValue
Returns the value stored before this update.- Returns:
- previous statistic value
-
getNewValue
Returns the value that will be stored if the event is not cancelled.- Returns:
- proposed statistic value
-
setNewValue
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:
isCancelledin interfaceorg.bukkit.event.Cancellable- Returns:
truewhen the value must not be stored
-
setCancelled
public void setCancelled(boolean cancel) Sets whether the statistic update should be discarded.- Specified by:
setCancelledin interfaceorg.bukkit.event.Cancellable- Parameters:
cancel-trueto reject the update
-
getHandlers
@NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()- Specified by:
getHandlersin classorg.bukkit.event.Event
-
getHandlerList
public static org.bukkit.event.HandlerList getHandlerList()
-