Skip to content

Commit

Permalink
Refactor serialization in ChestShopMetaData class
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Feli499 committed Jan 1, 2024
1 parent c0d7234 commit 7341098
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/com/Acrobot/ChestShop/Signs/ChestShopMetaData.java
Expand Up @@ -88,8 +88,12 @@ public ItemStack getItemStack() {
@Override
public Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<>();
data.put("owner", owner);
data.put("accessors", accessors);
data.put("owner", owner.toString());

Set<String> 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);
Expand All @@ -99,12 +103,16 @@ public Map<String, Object> serialize() {

public static ChestShopMetaData deserialize(Map<String, Object> 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<UUID> accessors = new HashSet<>((HashSet<UUID>) map.get("accessors"));
ItemStack itemStack = ItemStack.deserialize((Map<String, Object>) map.get("itemStack"));

Set<String> accessorsString = (HashSet<String>) map.get("accessors");
Set<UUID> accessors = new HashSet<>();
accessorsString.forEach(string -> accessors.add(UUID.fromString(string)));

return new ChestShopMetaData(owner, amount, sellPrice, buyPrice, itemStack, accessors);
}
}

0 comments on commit 7341098

Please sign in to comment.