diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java index 50599ff8..de0ad78e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java @@ -21,11 +21,13 @@ package de.steamwar.bausystem.configplayer.serializer; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerialization; +import yapion.hierarchy.api.groups.YAPIONAnyType; import yapion.hierarchy.types.YAPIONObject; import yapion.serializing.api.SerializerObject; import yapion.serializing.data.DeserializeData; import yapion.serializing.data.SerializeData; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -49,7 +51,14 @@ public class ConfigurationSerializableSerializer extends SerializerObject serializeDataMap = serializeData.object.serialize(); serializeDataMap.forEach((s, o) -> { - yapionObject.add(s, serializeData.serialize(o)); + YAPIONAnyType yapionAnyType = serializeData.serialize(o); + if (yapionAnyType instanceof YAPIONObject) { + YAPIONObject object = (YAPIONObject) yapionAnyType; + if (object.containsKey(TYPE_IDENTIFIER) && object.getPlainValue(TYPE_IDENTIFIER).equals("com.google.common.collect.RegularImmutableList")) { + object.put(TYPE_IDENTIFIER, ArrayList.class.getTypeName()); + } + } + yapionObject.add(s, yapionAnyType); }); return yapionObject; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java index abbec165..23ed1665 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java @@ -20,71 +20,57 @@ package de.steamwar.bausystem.features.hotbar; import de.steamwar.bausystem.configplayer.Config; -import org.bukkit.configuration.file.YamlConfiguration; +import lombok.experimental.UtilityClass; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import yapion.hierarchy.types.YAPIONArray; +import yapion.hierarchy.types.YAPIONObject; +import yapion.hierarchy.types.YAPIONValue; +import yapion.parser.YAPIONParser; +import yapion.serializing.YAPIONDeserializer; +import yapion.serializing.YAPIONSerializer; -import java.io.StringReader; - -// TODO: 16.05.2021 @Yoyo muss mal was Fixen, dann Item Save auf Yapion umstellen +@UtilityClass public class DefaultHotbar { - public static void updateHotbar(Player p) { + private final YAPIONArray DEFAULT_HOTBAR = YAPIONParser.parse("{[{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)v(2230)type(WOODEN_AXE)meta{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)meta-type(UNSPECIFIC)display-name(WorldEdit Wand)lore{@type(java.util.ArrayList)values[Left click: select pos #1,Right click: select pos #2]}}},{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)v(2230)type(COMPASS)meta{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)meta-type(UNSPECIFIC)display-name(Navigation Wand)lore{@type(java.util.ArrayList)values[Left click: jump to location,Right click: pass through walls]}}},null,null,null,null,null,null,{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)v(2230)type(NETHER_STAR)meta{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)meta-type(UNSPECIFIC)display-name(§eBau GUI)}}]}").getArray(""); + + public void updateHotbar(Player p) { ItemStack[] hotbar = new ItemStack[9]; System.arraycopy(p.getInventory().getContents(), 0, hotbar, 0, 9); - YamlConfiguration configuration = new YamlConfiguration(); - configuration.set("Items", hotbar); - Config.getInstance().get(p).add("hotbar", configuration.saveToString()); + YAPIONArray yapionArray = new YAPIONArray(); + for (ItemStack itemStack : hotbar) { + if (itemStack != null) { + yapionArray.add(YAPIONSerializer.serialize(itemStack)); + } else { + yapionArray.add(new YAPIONValue<>(null)); + } + } + Config.getInstance().get(p).add("hotbar", yapionArray); Config.getInstance().save(p); } - public static void setHotbar(Player p) { + public void setHotbar(Player p) { ItemStack[] hotbar = getItems(p); ItemStack[] inv = p.getInventory().getContents(); System.arraycopy(hotbar, 0, inv, 0, 9); p.getInventory().setContents(inv); } - public static ItemStack[] getItems(Player p) { - YamlConfiguration hb = YamlConfiguration.loadConfiguration(new StringReader(Config.getInstance().get(p).getPlainValueOrDefault("hotbar", defaultHotbar()))); - ItemStack[] hotbar = hb.getList("Items").toArray(new ItemStack[9]); + public ItemStack[] getItems(Player p) { + YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar", defaultHotbar());; + ItemStack[] hotbar = new ItemStack[9]; + yapionArray.forEach((integer, yapionAnyType) -> { + if (yapionAnyType instanceof YAPIONValue) { + hotbar[integer] = null; + } else { + hotbar[integer] = (ItemStack) YAPIONDeserializer.deserialize((YAPIONObject) yapionAnyType); + } + }); return hotbar; } - public static String defaultHotbar() { - return "Items:\n" + - "- ==: org.bukkit.inventory.ItemStack\n" + - " v: 2230\n" + - " type: WOODEN_AXE\n" + - " meta:\n" + - " ==: ItemMeta\n" + - " meta-type: UNSPECIFIC\n" + - " display-name: WorldEdit Wand\n" + - " lore:\n" + - " - 'Left click: select pos #1'\n" + - " - 'Right click: select pos #2'\n" + - "- ==: org.bukkit.inventory.ItemStack\n" + - " v: 2230\n" + - " type: COMPASS\n" + - " meta:\n" + - " ==: ItemMeta\n" + - " meta-type: UNSPECIFIC\n" + - " display-name: Navigation Wand\n" + - " lore:\n" + - " - 'Left click: jump to location'\n" + - " - 'Right click: pass through walls'\n" + - "- null\n" + - "- null\n" + - "- null\n" + - "- null\n" + - "- null\n" + - "- null\n" + - "- ==: org.bukkit.inventory.ItemStack\n" + - " v: 2230\n" + - " type: NETHER_STAR\n" + - " meta:\n" + - " ==: ItemMeta\n" + - " meta-type: UNSPECIFIC\n" + - " display-name: §eBau GUI\n"; + public YAPIONArray defaultHotbar() { + return DEFAULT_HOTBAR; } }