Skip to content

Commit

Permalink
better serialisation of itemstacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokkonaut committed May 19, 2024
1 parent 0f73267 commit 9cd5e01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,12 @@ public ListIterator<ItemStack> iterator(int i) {
return null;
}

@Override
public InventoryHolder getHolder(boolean useSnapshot) {
return null;
}

@Override
public HashMap<Integer, ItemStack> removeItemAnySlot(ItemStack... items) throws IllegalArgumentException {
return new HashMap<Integer, ItemStack>();
}
Expand All @@ -182,4 +184,9 @@ public HashMap<Integer, ItemStack> removeItemAnySlot(ItemStack... items) throws
public boolean isEmpty() {
return false;
}

@Override
public int close() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public boolean canAccess(OfflinePlayer player) {

public boolean canAccess(UUID player) {

if (isOwner(player))
if (isOwner(player)) {
return true;
}

return isAccessor(player);
}
Expand Down Expand Up @@ -117,7 +118,7 @@ public Map<String, Object> serialize() {
data.put("amount", quantity);
data.put("buyPrice", buyPrice);
data.put("sellPrice", sellPrice);
data.put("itemStack", itemStack.serialize());
data.put("itemStack", itemStack == null ? null : itemStack.serializeAsBytes());
return data;
}

Expand All @@ -127,7 +128,8 @@ public static ChestShopMetaData deserialize(Map<String, Object> map) {
int amount = (int) map.get("amount");
double sellPrice = (double) map.get("sellPrice");
double buyPrice = (double) map.get("buyPrice");
ItemStack itemStack = ItemStack.deserialize((Map<String, Object>) map.get("itemStack"));
Object stackSerialized = map.get("itemStack");
ItemStack itemStack = stackSerialized instanceof Map<?, ?> stackMap ? ItemStack.deserialize((Map<String, Object>) stackMap) : stackSerialized instanceof byte[] bytes ? ItemStack.deserializeBytes(bytes) : null;

Set<String> accessorsString = (HashSet<String>) map.get("accessors");
Set<UUID> accessors = new HashSet<>();
Expand Down

0 comments on commit 9cd5e01

Please sign in to comment.