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.
Technical Overview
Section titled “Technical Overview”- Package:
io.greenmc.santasays.api.event.player - Parent Class:
PlayerEvent - Cancellable: Yes
Methods
Section titled “Methods”In addition to getPlayer() and getUser() from the base class, this event provides:
| Method | Return Type | Description |
|---|---|---|
getStat() | StatisticType | Returns the type of statistic being modified. |
getOldValue() | int | Returns the value of the statistic before this change. |
getNewValue() | int | Returns the proposed new value. |
setNewValue(int) | void | Overrides the final value to be saved. |
setCancelled(boolean) | void | If set to true, the statistic update is completely ignored. |
Example Use Cases
Section titled “Example Use Cases”Apply a 2x Win Booster
Section titled “Apply a 2x Win Booster”You can check for specific permissions to reward certain players with double progress.
@EventHandlerpublic 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)); }}Capping a Statistic
Section titled “Capping a Statistic”Prevent a statistic from exceeding a certain limit.
@EventHandlerpublic void onStatChange(PlayerStatisticChangeEvent event) { int maxCap = 5000; if (event.getNewValue() > maxCap) { event.setNewValue(maxCap); }}Basic Anti-Cheat
Section titled “Basic Anti-Cheat”Block suspicious spikes in statistics (e.g., gaining too many points at once).
@EventHandlerpublic void onStatChange(PlayerStatisticChangeEvent event) { int difference = event.getNewValue() - event.getOldValue();
// Cancel if the increase is impossibly high if (difference > 100) { event.setCancelled(true); }}