-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
StoredShops.java
61 lines (49 loc) · 1.65 KB
/
StoredShops.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
package net.citizensnpcs.trait.shop;
import java.util.Map;
import com.google.common.collect.Maps;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.persistence.PersistenceLoader;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.api.util.Storage;
import net.citizensnpcs.api.util.YamlStorage;
import net.citizensnpcs.trait.ShopTrait.NPCShop;
public class StoredShops {
@Persist(value = "global", reify = true)
public Map<String, NPCShop> globalShops = Maps.newHashMap();
@Persist(value = "npc", reify = true)
public Map<String, NPCShop> npcShops = Maps.newHashMap();
private final Storage storage;
public StoredShops(YamlStorage storage) {
this.storage = storage;
}
public void deleteShop(NPCShop shop) {
if (Messaging.isDebugging()) {
Messaging.debug("Deleting shop", shop.getName());
}
if (npcShops.values().contains(shop)) {
npcShops.values().remove(shop);
} else {
globalShops.values().remove(shop);
}
}
public NPCShop getGlobalShop(String name) {
return globalShops.computeIfAbsent(name, NPCShop::new);
}
public NPCShop getShop(String name) {
if (npcShops.containsKey(name))
return npcShops.get(name);
return getGlobalShop(name);
}
public void load() {
PersistenceLoader.load(this, storage.getKey(""));
}
public boolean loadFromDisk() {
return storage.load();
}
public void saveToDisk() {
storage.save();
}
public void storeShops() {
PersistenceLoader.save(this, storage.getKey(""));
}
}