9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-19 14:59:21 +00:00

Fix: added null-checks for Material and EntityType in applyStat to avoid NPE (#589)

This commit is contained in:
Heriptik
2025-10-03 08:56:15 +02:00
committed by GitHub
parent fe0bdccf40
commit 4e75b5ca1d

View File

@@ -524,8 +524,18 @@ public abstract class BukkitData implements Data {
try {
switch (type) {
case UNTYPED -> player.setStatistic(stat, value);
case BLOCK, ITEM -> player.setStatistic(stat, Objects.requireNonNull(matchMaterial(key[0])), value);
case ENTITY -> player.setStatistic(stat, Objects.requireNonNull(matchEntityType(key[0])), value);
case BLOCK, ITEM -> {
Material material = matchMaterial(key.length > 0 ? key[0] : null);
if (material != null) {
player.setStatistic(stat, material, value);
}
}
case ENTITY -> {
EntityType entity = matchEntityType(key.length > 0 ? key[0] : null);
if (entity != null) {
player.setStatistic(stat, entity, value);
}
}
}
} catch (Throwable a) {
plugin.log(Level.WARNING, "Failed to apply statistic " + id, a);