#1004: Improve field rename handling and centralize conversion between bukkit and string more

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
Bukkit/Spigot
2024-05-04 08:19:04 +10:00
parent a3c30e3ee2
commit 92293c1b89
5 changed files with 44 additions and 6 deletions

View File

@@ -3,9 +3,12 @@ package org.bukkit.inventory;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.Translatable;
import org.bukkit.Utility;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
@@ -530,7 +533,11 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
Map<?, ?> map = (Map<?, ?>) raw;
for (Map.Entry<?, ?> entry : map.entrySet()) {
Enchantment enchantment = Enchantment.getByName(entry.getKey().toString());
String stringKey = entry.getKey().toString();
stringKey = Bukkit.getUnsafe().get(Enchantment.class, stringKey);
NamespacedKey key = NamespacedKey.fromString(stringKey.toLowerCase(Locale.ROOT));
Enchantment enchantment = Bukkit.getUnsafe().get(Registry.ENCHANTMENT, key);
if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());