|
@@ -0,0 +1,47 @@
|
|
|
+package dev.sammko.onepunch;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+import org.bukkit.entity.Player;
|
|
|
+import org.bukkit.configuration.MemorySection;
|
|
|
+import org.bukkit.configuration.file.FileConfiguration;
|
|
|
+
|
|
|
+public class PlayerInfoManager {
|
|
|
+ private HashMap<UUID, PlayerInfo> infomap;
|
|
|
+ private boolean loaded = false;
|
|
|
+
|
|
|
+ public PlayerInfoManager() {
|
|
|
+ this.infomap = new HashMap<UUID, PlayerInfo>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public PlayerInfo getPlayerInfo(Player p) {
|
|
|
+ PlayerInfo pi = infomap.get(p.getUniqueId());
|
|
|
+ if (pi == null) {
|
|
|
+ pi = new PlayerInfo();
|
|
|
+ infomap.put(p.getUniqueId(), pi);
|
|
|
+ }
|
|
|
+ return pi;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void loadFromConfig(FileConfiguration conf) {
|
|
|
+ assert !loaded;
|
|
|
+ MemorySection root = (MemorySection) conf.get("playerInfo");
|
|
|
+ for (Map.Entry<String, Object> e : root.getValues(false).entrySet()) {
|
|
|
+ UUID u = UUID.fromString(e.getKey());
|
|
|
+ PlayerInfo pi = PlayerInfo.deserialize((MemorySection) e.getValue());
|
|
|
+ infomap.put(u, pi);
|
|
|
+ }
|
|
|
+ loaded = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveToConfig(FileConfiguration conf) {
|
|
|
+ assert loaded;
|
|
|
+ HashMap<String, HashMap<String, Object>> map =
|
|
|
+ new HashMap<String, HashMap<String, Object>>();
|
|
|
+ for (Map.Entry<UUID, PlayerInfo> e : infomap.entrySet())
|
|
|
+ map.put(e.getKey().toString(), e.getValue().serialize());
|
|
|
+ conf.set("playerInfo", map);
|
|
|
+ }
|
|
|
+}
|