Add support for deserializing manually deserialized items, also add caller note

This commit is contained in:
Shane Freeder 2025-04-15 09:30:44 +01:00
parent c0bd5688b5
commit a55345f991
No known key found for this signature in database
GPG Key ID: A3F61EA5A085289C
2 changed files with 17 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package org.bukkit.configuration.serialization;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
@ -30,8 +31,12 @@ public interface ConfigurationSerializable {
* This class must provide a method to restore this class, as defined in
* the {@link ConfigurationSerializable} interface javadocs.
*
* nb: It is not intended for this method to be called directly, this will
* be called by the {@link ConfigurationSerialization} class.
*
* @return Map containing the current state of this class
*/
@NotNull
@ApiStatus.OverrideOnly
public Map<String, Object> serialize();
}

View File

@ -60,6 +60,7 @@ import org.bukkit.advancement.Advancement;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.MemorySection;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
@ -565,7 +566,17 @@ public final class CraftMagicNumbers implements UnsafeValues {
}
case "components" -> {
if (version == 1) {
final Map<String, String> componentMap = (Map<String, String>) value;
Map<String, String> componentMap;
if (value instanceof Map) {
componentMap = (Map<String, String>) value;
} else if (value instanceof MemorySection memory) {
componentMap = new HashMap<>();
for (final String memoryKey : memory.getKeys(false)) {
componentMap.put(memoryKey, memory.getString(memoryKey));
}
} else {
throw new IllegalArgumentException("components must be a Map");
}
final CompoundTag componentsTag = new CompoundTag();
componentMap.forEach((componentKey, componentString) -> {
final Tag componentTag;