Fix NullPointerException from SkullMeta

This commit is contained in:
Heliosares
2023-11-03 16:11:06 -04:00
parent 4d588d7512
commit 8c51a790b8
2 changed files with 12 additions and 2 deletions

View File

@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>AuxProtect</groupId>
<artifactId>AuxProtect</artifactId>
<version>1.2.10</version>
<version>1.2.11-pre1</version>
<name>AuxProtect</name>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>

View File

@@ -6,6 +6,7 @@ import dev.heliosares.auxprotect.utils.InvSerialization;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.SkullMeta;
import javax.annotation.Nullable;
import java.io.IOException;
@@ -27,7 +28,16 @@ public class SingleItemEntry extends DbEntry {
if (item.hasItemMeta() && item.getItemMeta() instanceof Damageable meta) {
damage = meta.getDamage();
meta.setDamage(0);
item.setItemMeta(meta);
try {
item.setItemMeta(meta);
} catch (NullPointerException e) {
if (!(meta instanceof SkullMeta)) {
throw e;
}
// For some reason, SkullMeta is throwing a null pointer randomly. Shouldn't affect
// anything because setting the damage to 0 is only done to reduce the number of blobs
// stored in the database.
}
} else damage = 0;
this.item = item;
try {