From 2780a9af278e0da9432600ba22c50ed9d4afdcf4 Mon Sep 17 00:00:00 2001 From: Intelli Date: Mon, 4 Nov 2024 14:31:00 -0700 Subject: [PATCH] Fixed NotSerializableException when sacrificing entities (fixes #666) --- .../coreprotect/listener/entity/EntityDeathListener.java | 2 +- .../java/net/coreprotect/utility/entity/EntityUtil.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/coreprotect/listener/entity/EntityDeathListener.java b/src/main/java/net/coreprotect/listener/entity/EntityDeathListener.java index 8a9ac74..0883812 100644 --- a/src/main/java/net/coreprotect/listener/entity/EntityDeathListener.java +++ b/src/main/java/net/coreprotect/listener/entity/EntityDeathListener.java @@ -289,7 +289,7 @@ public final class EntityDeathListener extends Queue implements Listener { if (attributeInstance != null) { List attributeData = new ArrayList<>(); List attributeModifiers = new ArrayList<>(); - attributeData.add(attributeInstance.getAttribute()); + attributeData.add(BukkitAdapter.ADAPTER.getRegistryKey(attributeInstance.getAttribute())); attributeData.add(attributeInstance.getBaseValue()); for (AttributeModifier modifier : attributeInstance.getModifiers()) { diff --git a/src/main/java/net/coreprotect/utility/entity/EntityUtil.java b/src/main/java/net/coreprotect/utility/entity/EntityUtil.java index 98f8fe7..8d7b886 100644 --- a/src/main/java/net/coreprotect/utility/entity/EntityUtil.java +++ b/src/main/java/net/coreprotect/utility/entity/EntityUtil.java @@ -166,7 +166,13 @@ public class EntityUtil { for (Object value : attributes) { @SuppressWarnings("unchecked") List attributeData = (List) value; - Attribute attribute = (Attribute) attributeData.get(0); + Attribute attribute = null; + if (attributeData.get(0) instanceof Attribute) { + attribute = (Attribute) attributeData.get(0); + } + else { + attribute = (Attribute) BukkitAdapter.ADAPTER.getRegistryValue((String) attributeData.get(0), Attribute.class); + } Double baseValue = (Double) attributeData.get(1); @SuppressWarnings("unchecked") List attributeModifiers = (List) attributeData.get(2);