Skip to content

Commit

Permalink
Fixed NotSerializableException when logging items containing attribut…
Browse files Browse the repository at this point in the history
…e data
  • Loading branch information
Intelli committed Dec 9, 2024
1 parent f729c8a commit b3db65d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/main/java/net/coreprotect/database/rollback/RollbackUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,17 @@ else if (mapData.get("modifiers") != null) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public static List<List<Map<String, Object>>> serialize(ItemStack item, Material

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);
}
}
Expand Down

0 comments on commit b3db65d

Please sign in to comment.