Skip to content

PlayerStatisticChangeEvent

PlayerStatisticChangeEvent<T> lets integrations observe, replace, or cancel runtime statistic updates.


MethodReturn typeDescription
getStatisticType()StatisticType<T>Statistic definition being changed.
getOldValue()TCurrently stored value.
getNewValue()TValue that will be stored.
setNewValue(T)voidReplace the pending value.
isCancelled()booleanWhether the update will be discarded.
setCancelled(boolean)voidCancel or restore the update.
getPlayer()PlayerAffected Bukkit player.
getUser()UserAffected Whack Me user.

The event covers both persistent statistics and temporary local_* run values. Database loading bypasses it; it represents changes requested through the runtime user statistics API.


import dev.despical.whackme.api.event.player.PlayerStatisticChangeEvent;
import dev.despical.whackme.stats.Statistics;
@EventHandler
public void onStatisticChange(PlayerStatisticChangeEvent<Integer> event) {
if (event.getStatisticType() == Statistics.LOCAL_SCORE) {
event.setNewValue(Math.max(0, event.getNewValue()));
}
}

Because the event is generic, a handler may receive different statistic value types in future versions. Check getStatisticType() before assuming the value type in shared listeners.