Skip to content

PlayerStatisticChangeEvent

PlayerStatisticChangeEvent<T> fires before a runtime statistic update is written. A listener may inspect the statistic definition and old value, replace the proposed value, or cancel the update.

Statistics loaded from persistent storage do not fire this event.

  • Package: dev.despical.snake.api.event.player
  • Parent Class: SnakeEvent
  • Cancellable: Yes
MethodReturn TypeDescription
getPlayer()PlayerBukkit player whose statistic is changing.
getStatistic()StatisticType<T>Statistic definition being updated.
getOldValue()TValue stored before this update.
getNewValue()TValue that will be stored if the event continues.
setNewValue(T)voidReplaces the value that will be stored.
isCancelled()booleanWhether the update is rejected.
setCancelled(boolean)voidRejects or restores the requested update.
@EventHandler
public void onSnakeStatistic(PlayerStatisticChangeEvent<Integer> event) {
if (event.getStatistic() == Statistics.TOTAL_SCORE) {
event.setNewValue(Math.max(0, event.getNewValue()));
}
}

Common uses include applying multipliers, clamping values, rejecting changes, and mirroring updates to another service.