From 3ce014b2673f5387a6ac31419d9706c3fcc2aa0e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 13:10:03 +0200 Subject: [PATCH] Update DefaultHotbar from YAML to YAPION Signed-off-by: yoyosource --- .../ConfigurationSerializableSerializer.java | 19 +++++++++++++++++-- .../features/hotbar/DefaultHotbar.java | 4 ++-- .../features/hotbar/HotbarListener.java | 1 - 3 files changed, 19 insertions(+), 5 deletions(-) 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 de0ad78e..eecd1ef1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java @@ -21,6 +21,8 @@ package de.steamwar.bausystem.configplayer.serializer; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerialization; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import yapion.hierarchy.api.groups.YAPIONAnyType; import yapion.hierarchy.types.YAPIONObject; import yapion.serializing.api.SerializerObject; @@ -48,7 +50,13 @@ public class ConfigurationSerializableSerializer extends SerializerObject serializeData) { YAPIONObject yapionObject = new YAPIONObject(); - yapionObject.add(TYPE_IDENTIFIER, type().getTypeName()); + yapionObject.add(TYPE_IDENTIFIER, serializeData.object.getClass().getTypeName()); + if (serializeData.object instanceof ItemStack) { + yapionObject.add(TYPE_IDENTIFIER, ItemStack.class.getTypeName()); + } + if (serializeData.object instanceof ItemMeta) { + yapionObject.add(TYPE_IDENTIFIER, ItemMeta.class.getTypeName()); + } Map serializeDataMap = serializeData.object.serialize(); serializeDataMap.forEach((s, o) -> { YAPIONAnyType yapionAnyType = serializeData.serialize(o); @@ -67,7 +75,14 @@ public class ConfigurationSerializableSerializer extends SerializerObject deserializeData) { Map deserializeDataMap = new HashMap<>(); deserializeData.object.forEach((s, yapionAnyType) -> { - if (s.equals(TYPE_IDENTIFIER)) return; + if (s.equals(TYPE_IDENTIFIER)) { + if (yapionAnyType.toString().equals("(org.bukkit.inventory.meta.ItemMeta)")) { + deserializeDataMap.put("==", "ItemMeta"); + } else { + deserializeDataMap.put("==", deserializeData.deserialize(yapionAnyType)); + } + return; + } deserializeDataMap.put(s, deserializeData.deserialize(yapionAnyType)); }); return ConfigurationSerialization.deserializeObject(deserializeDataMap); 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 23ed1665..e0808857 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java @@ -33,7 +33,7 @@ import yapion.serializing.YAPIONSerializer; @UtilityClass public class DefaultHotbar { - 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(""); + private final YAPIONArray DEFAULT_HOTBAR = YAPIONParser.parse("{[{@type(org.bukkit.inventory.ItemStack)v(2230)type(WOODEN_AXE)meta{@type(org.bukkit.inventory.meta.ItemMeta)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.inventory.ItemStack)v(2230)type(COMPASS)meta{@type(org.bukkit.inventory.meta.ItemMeta)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.inventory.ItemStack)v(2230)type(NETHER_STAR)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(§eBau GUI)}}]}").getArray(""); public void updateHotbar(Player p) { ItemStack[] hotbar = new ItemStack[9]; @@ -58,7 +58,7 @@ public class DefaultHotbar { } public ItemStack[] getItems(Player p) { - YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar", defaultHotbar());; + YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar", defaultHotbar()); ItemStack[] hotbar = new ItemStack[9]; yapionArray.forEach((integer, yapionAnyType) -> { if (yapionAnyType instanceof YAPIONValue) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java index 5772c878..afd1fb02 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java @@ -31,7 +31,6 @@ public class HotbarListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(PlayerJoinEvent event) { - System.out.println(event.getPlayer().getInventory().getContents()); if (allNull(event.getPlayer().getInventory().getContents())) { DefaultHotbar.setHotbar(event.getPlayer()); }