Skip to content

PlayerStatisticChangeEvent

The PlayerStatisticChangeEvent is triggered whenever a player’s persistent statistic (such as wins, losses, or streaks) is about to be updated. This event is fired before the new value is applied to the database or cache, allowing developers to intercept, modify, or cancel the change.


  • Package: io.greenmc.santasays.api.event.player
  • Parent Class: PlayerEvent
  • Cancellable: Yes

In addition to getPlayer() and getUser() from the base class, this event provides:

MethodReturn TypeDescription
getStat()StatisticTypeReturns the type of statistic being modified.
getOldValue()intReturns the value of the statistic before this change.
getNewValue()intReturns the proposed new value.
setNewValue(int)voidOverrides the final value to be saved.
setCancelled(boolean)voidIf set to true, the statistic update is completely ignored.


You can check for specific permissions to reward certain players with double progress.

@EventHandler
public void onStatChange(PlayerStatisticChangeEvent event) {
// Apply a 2x multiplier for wins if the player is a VIP
if (event.getStat() == Statistic.WIN && event.getPlayer().hasPermission("vip.booster")) {
int currentGain = event.getNewValue() - event.getOldValue();
event.setNewValue(event.getOldValue() + (currentGain * 2));
}
}

Prevent a statistic from exceeding a certain limit.

@EventHandler
public void onStatChange(PlayerStatisticChangeEvent event) {
int maxCap = 5000;
if (event.getNewValue() > maxCap) {
event.setNewValue(maxCap);
}
}

Block suspicious spikes in statistics (e.g., gaining too many points at once).

@EventHandler
public void onStatChange(PlayerStatisticChangeEvent event) {
int difference = event.getNewValue() - event.getOldValue();
// Cancel if the increase is impossibly high
if (difference > 100) {
event.setCancelled(true);
}
}