diff --git a/src/main/java/net/momirealms/customfishing/utils/ItemUtil.java b/src/main/java/net/momirealms/customfishing/utils/ItemUtil.java index bd0c8d26..30440909 100644 --- a/src/main/java/net/momirealms/customfishing/utils/ItemUtil.java +++ b/src/main/java/net/momirealms/customfishing/utils/ItemUtil.java @@ -25,6 +25,7 @@ import org.bukkit.Material; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; import java.io.File; @@ -88,6 +89,13 @@ public class ItemUtil { }); yamlConfiguration.createSection(fileName + ".enchantments", map); } + if (itemMeta instanceof EnchantmentStorageMeta enchantmentStorageMeta){ + Map map = new HashMap<>(); + enchantmentStorageMeta.getStoredEnchants().forEach(((enchantment, level) -> { + map.put(String.valueOf(enchantment.getKey()), level); + })); + yamlConfiguration.createSection(fileName + ".enchantments", map); + } if (itemMeta.getItemFlags().size() > 0){ ArrayList itemFlags = new ArrayList<>(); itemStack.getItemFlags().forEach(itemFlag -> { @@ -99,7 +107,9 @@ public class ItemUtil { NBTItem nbtItem = new NBTItem(itemStack); Map map0 = compoundToMap(nbtItem); - yamlConfiguration.createSection(fileName + ".nbt", map0); + if (map0.size() != 0){ + yamlConfiguration.createSection(fileName + ".nbt", map0); + } File file = new File(CustomFishing.instance.getDataFolder(), File.separator + "loots" + File.separator + fileName + ".yml"); @@ -119,6 +129,7 @@ public class ItemUtil { || key.equals("Lore") || key.equals("HideFlags") || key.equals("CustomModelData") + || key.equals("StoredEnchantments") || key.equals("Unbreakable")) return; switch (nbtCompound.getType(key)){ case NBTTagByte -> map.put(key, "(Byte) " + nbtCompound.getByte(key)); diff --git a/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java b/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java index b3184167..33fb2d42 100644 --- a/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java +++ b/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java @@ -86,7 +86,7 @@ public class NBTUtil { nbtCompound.setLong(key, Long.valueOf(string.substring(7))); }else if (string.startsWith("(Float) ")){ nbtCompound.setFloat(key, Float.valueOf(string.substring(8))); - } else if (string.startsWith("(Double) ")){ + }else if (string.startsWith("(Double) ")){ nbtCompound.setDouble(key, Double.valueOf(string.substring(9))); }else if (string.startsWith("(Short) ")){ nbtCompound.setShort(key, Short.valueOf(string.substring(8))); diff --git a/src/main/resources/loots/example.yml b/src/main/resources/loots/example.yml index 1152fe80..3e0551c2 100644 --- a/src/main/resources/loots/example.yml +++ b/src/main/resources/loots/example.yml @@ -35,7 +35,7 @@ rainbow_fish: custom-model-data: 1 # Custom NBT tags - # If you are not sure about the NBT tag. You can use command '/customfishing export xxx' and get it in 'CustomFishing/export' folder + # If you are not sure about the NBT tag. You can use command '/cfishing import xxx' and get it in 'CustomFishing/export' folder # (Int) (Byte) (String) (Float) (String) (Double) (Short) (Long) (UUID) (Boolean) (IntArray) (ByteArray) nbt: itemsadder: