Update DefaultHotbar from YAML to YAPION
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
2165682234
Commit
3ce014b267
@ -21,6 +21,8 @@ package de.steamwar.bausystem.configplayer.serializer;
|
|||||||
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
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.api.groups.YAPIONAnyType;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
import yapion.serializing.api.SerializerObject;
|
import yapion.serializing.api.SerializerObject;
|
||||||
@ -48,7 +50,13 @@ public class ConfigurationSerializableSerializer extends SerializerObject<Config
|
|||||||
@Override
|
@Override
|
||||||
public YAPIONObject serialize(SerializeData<ConfigurationSerializable> serializeData) {
|
public YAPIONObject serialize(SerializeData<ConfigurationSerializable> serializeData) {
|
||||||
YAPIONObject yapionObject = new YAPIONObject();
|
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<String, Object> serializeDataMap = serializeData.object.serialize();
|
Map<String, Object> serializeDataMap = serializeData.object.serialize();
|
||||||
serializeDataMap.forEach((s, o) -> {
|
serializeDataMap.forEach((s, o) -> {
|
||||||
YAPIONAnyType yapionAnyType = serializeData.serialize(o);
|
YAPIONAnyType yapionAnyType = serializeData.serialize(o);
|
||||||
@ -67,7 +75,14 @@ public class ConfigurationSerializableSerializer extends SerializerObject<Config
|
|||||||
public ConfigurationSerializable deserialize(DeserializeData<YAPIONObject> deserializeData) {
|
public ConfigurationSerializable deserialize(DeserializeData<YAPIONObject> deserializeData) {
|
||||||
Map<String, Object> deserializeDataMap = new HashMap<>();
|
Map<String, Object> deserializeDataMap = new HashMap<>();
|
||||||
deserializeData.object.forEach((s, yapionAnyType) -> {
|
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));
|
deserializeDataMap.put(s, deserializeData.deserialize(yapionAnyType));
|
||||||
});
|
});
|
||||||
return ConfigurationSerialization.deserializeObject(deserializeDataMap);
|
return ConfigurationSerialization.deserializeObject(deserializeDataMap);
|
||||||
|
@ -33,7 +33,7 @@ import yapion.serializing.YAPIONSerializer;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class DefaultHotbar {
|
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) {
|
public void updateHotbar(Player p) {
|
||||||
ItemStack[] hotbar = new ItemStack[9];
|
ItemStack[] hotbar = new ItemStack[9];
|
||||||
@ -58,7 +58,7 @@ public class DefaultHotbar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getItems(Player p) {
|
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];
|
ItemStack[] hotbar = new ItemStack[9];
|
||||||
yapionArray.forEach((integer, yapionAnyType) -> {
|
yapionArray.forEach((integer, yapionAnyType) -> {
|
||||||
if (yapionAnyType instanceof YAPIONValue) {
|
if (yapionAnyType instanceof YAPIONValue) {
|
||||||
|
@ -31,7 +31,6 @@ public class HotbarListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
System.out.println(event.getPlayer().getInventory().getContents());
|
|
||||||
if (allNull(event.getPlayer().getInventory().getContents())) {
|
if (allNull(event.getPlayer().getInventory().getContents())) {
|
||||||
DefaultHotbar.setHotbar(event.getPlayer());
|
DefaultHotbar.setHotbar(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren