forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ChestShopMetaData.java
100 lines (77 loc) · 2.67 KB
/
ChestShopMetaData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.Acrobot.ChestShop.Signs;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.inventory.ItemStack;
public class ChestShopMetaData implements ConfigurationSerializable {
private UUID owner;
private Set<UUID> accessors;
private int quantity;
private double buyPrice;
private double sellPrice;
private ItemStack itemStack;
public ChestShopMetaData(UUID owner, int quantity, double sellPrice, double buyPrice, ItemStack itemStack) {
this(owner, quantity, sellPrice, buyPrice, itemStack, new HashSet<>());
}
private ChestShopMetaData(UUID owner, int quantity, double sellPrice, double buyPrice, ItemStack itemStack, Set<UUID> accessors) {
this.owner = owner;
this.quantity = quantity;
this.sellPrice = sellPrice;
this.buyPrice = buyPrice;
this.itemStack = itemStack;
this.accessors = accessors;
}
public HashSet<UUID> getAccessors() {
return new HashSet<>(accessors);
}
public void addAccessor(UUID uuid) {
accessors.add(uuid);
}
public void removeAccessor(UUID uuid) {
accessors.remove(uuid);
}
public boolean isAccessor(UUID uuid) {
return accessors.contains(uuid);
}
public UUID getOwner() {
return owner;
}
public boolean isOwner(UUID uuid) {
return owner.equals(uuid);
}
public int getQuantity() {
return quantity;
}
public double getBuyPrice() {
return buyPrice;
}
public double getSellPrice() {
return sellPrice;
}
public ItemStack getItemStack() {
return itemStack;
}
@Override
public Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<>();
data.put("owner", owner);
data.put("accessors", accessors);
data.put("amount", quantity);
data.put("buyPrice", buyPrice);
data.put("sellPrice", sellPrice);
data.put("itemStack", itemStack.serialize());
return data;
}
public static ChestShopMetaData deserialize(Map<String, Object> map) {
UUID owner = (UUID) 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"));
return new ChestShopMetaData(owner, amount, sellPrice, buyPrice, itemStack, accessors);
}
}