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:
@@ -524,8 +524,18 @@ public abstract class BukkitData implements Data {
|
|||||||
try {
|
try {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case UNTYPED -> player.setStatistic(stat, value);
|
case UNTYPED -> player.setStatistic(stat, value);
|
||||||
case BLOCK, ITEM -> player.setStatistic(stat, Objects.requireNonNull(matchMaterial(key[0])), value);
|
case BLOCK, ITEM -> {
|
||||||
case ENTITY -> player.setStatistic(stat, Objects.requireNonNull(matchEntityType(key[0])), value);
|
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) {
|
} catch (Throwable a) {
|
||||||
plugin.log(Level.WARNING, "Failed to apply statistic " + id, a);
|
plugin.log(Level.WARNING, "Failed to apply statistic " + id, a);
|
||||||
|
|||||||
Reference in New Issue
Block a user