Fixed NotSerializableException when logging items containing attribute data

This commit is contained in:
Intelli 2024-12-09 16:37:29 -07:00
parent f729c8a126
commit b3db65d07d
2 changed files with 12 additions and 5 deletions

View file

@ -346,10 +346,17 @@ public class RollbackUtil extends Lookup {
List<Object> modifiers = (List<Object>) mapData.get("modifiers");
for (Object item : modifiers) {
Map<Attribute, Map<String, Object>> modifiersMap = (Map<Attribute, Map<String, Object>>) item;
for (Map.Entry<Attribute, Map<String, Object>> entry : modifiersMap.entrySet()) {
Map<Object, Map<String, Object>> modifiersMap = (Map<Object, Map<String, Object>>) item;
for (Map.Entry<Object, Map<String, Object>> entry : modifiersMap.entrySet()) {
try {
Attribute attribute = entry.getKey();
Attribute attribute = null;
if (entry.getKey() instanceof Attribute) {
attribute = (Attribute) entry.getKey();
}
else {
attribute = (Attribute) BukkitAdapter.ADAPTER.getRegistryValue((String) entry.getKey(), Attribute.class);
}
AttributeModifier modifier = AttributeModifier.deserialize(entry.getValue());
itemMeta.addAttributeModifier(attribute, modifier);
}

View file

@ -125,12 +125,12 @@ public class ItemMetaHandler {
if (itemMeta.hasAttributeModifiers()) {
for (Map.Entry<Attribute, AttributeModifier> entry : itemMeta.getAttributeModifiers().entries()) {
Map<Attribute, Map<String, Object>> attributeList = new HashMap<>();
Map<Object, Map<String, Object>> attributeList = new HashMap<>();
Attribute attribute = entry.getKey();
AttributeModifier modifier = entry.getValue();
itemMeta.removeAttributeModifier(attribute, modifier);
attributeList.put(attribute, modifier.serialize());
attributeList.put(BukkitAdapter.ADAPTER.getRegistryKey(attribute), modifier.serialize());
modifiers.add(attributeList);
}
}