9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-29 11:59:11 +00:00
This commit is contained in:
Xiao-MoMi
2022-08-28 16:11:03 +08:00
parent 193876c05c
commit 4da269680b
3 changed files with 14 additions and 3 deletions

View File

@@ -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<String, Integer> 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<String> itemFlags = new ArrayList<>();
itemStack.getItemFlags().forEach(itemFlag -> {
@@ -99,7 +107,9 @@ public class ItemUtil {
NBTItem nbtItem = new NBTItem(itemStack);
Map<String, Object> 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));

View File

@@ -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)));