From 734109809b3405a593cee6049a04b3886951c41c Mon Sep 17 00:00:00 2001 From: Maik E Date: Mon, 1 Jan 2024 13:40:09 +0100 Subject: [PATCH] Refactor serialization in ChestShopMetaData class The serialization and deserialization methods in the ChestShopMetaData class have been modified. UUID fields are now saved and reloaded as strings rather than as UUID objects to ensure correct data persistence. Alongside, necessary changes were addressed during the transformation to and from a string to UUID. --- .../ChestShop/Signs/ChestShopMetaData.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopMetaData.java b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopMetaData.java index 4d6ebf88c..ebf2008bc 100644 --- a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopMetaData.java +++ b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopMetaData.java @@ -88,8 +88,12 @@ public ItemStack getItemStack() { @Override public Map serialize() { Map data = new HashMap<>(); - data.put("owner", owner); - data.put("accessors", accessors); + data.put("owner", owner.toString()); + + Set accessorsStrings = new HashSet<>(); + this.accessors.forEach(uuid -> accessorsStrings.add(uuid.toString())); + data.put("accessors", accessorsStrings); + data.put("amount", quantity); data.put("buyPrice", buyPrice); data.put("sellPrice", sellPrice); @@ -99,12 +103,16 @@ public Map serialize() { public static ChestShopMetaData deserialize(Map map) { - UUID owner = (UUID) map.get("owner"); + UUID owner = UUID.fromString((String) map.get("owner")); int amount = (int) map.get("amount"); double sellPrice = (double) map.get("sellPrice"); double buyPrice = (double) map.get("buyPrice"); - ItemStack itemStack = (ItemStack) map.get("itemStack"); - Set accessors = new HashSet<>((HashSet) map.get("accessors")); + ItemStack itemStack = ItemStack.deserialize((Map) map.get("itemStack")); + + Set accessorsString = (HashSet) map.get("accessors"); + Set accessors = new HashSet<>(); + accessorsString.forEach(string -> accessors.add(UUID.fromString(string))); + return new ChestShopMetaData(owner, amount, sellPrice, buyPrice, itemStack, accessors); } }