From b4dc142455050f1848709d80cab84bf57755252e Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Tue, 24 Dec 2013 23:42:53 -0600 Subject: [PATCH] Save and load the prisoners on flat file. --- .../java/com/graywolf336/jail/JailIO.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/JailIO.java b/src/main/java/com/graywolf336/jail/JailIO.java index 1008518..747e2be 100644 --- a/src/main/java/com/graywolf336/jail/JailIO.java +++ b/src/main/java/com/graywolf336/jail/JailIO.java @@ -214,9 +214,17 @@ public class JailIO { flat.set(cNode + "prisoner.name", p.getName()); flat.set(cNode + "prisoner.muted", p.isMuted()); flat.set(cNode + "prisoner.time", p.getRemainingTime()); + flat.set(cNode + "prisoner.offlinePending", p.isOfflinePending()); } } + for(Prisoner p : j.getPrisonersNotInCells()) { + String pNode = node + "prisoners." + p.getName() + "."; + flat.set(pNode + "muted", p.isMuted()); + flat.set(pNode + "time", p.getRemainingTime()); + flat.set(pNode + "offlinePending", p.isOfflinePending()); + } + try { flat.save(new File(pl.getDataFolder(), "data.yml")); } catch (IOException e) { @@ -288,7 +296,9 @@ public class JailIO { } if(flat.contains(cellNode + "prisoner")) { - c.setPrisoner(new Prisoner(flat.getString(cellNode + "prisoner.name"), flat.getBoolean(cellNode + "prisoner.muted"), flat.getLong(cellNode + "prisoner.time"))); + Prisoner p = new Prisoner(flat.getString(cellNode + "prisoner.name"), flat.getBoolean(cellNode + "prisoner.muted"), flat.getLong(cellNode + "prisoner.time")); + p.setOfflinePending(flat.getBoolean(cellNode + "prisoner.offlinePending")); + c.setPrisoner(p); } j.addCell(c, false); @@ -298,8 +308,26 @@ public class JailIO { } } - if(pl.getServer().getWorld(j.getWorldName()) != null) pl.getJailManager().addJail(j, false); - else pl.getLogger().severe("Failed to load the jail " + j.getName() + " as the world '" + j.getWorldName() + "' does not exist (is null). Did you remove this world?"); + if(flat.isConfigurationSection(node + "prisoners")) { + Set prisoners = flat.getConfigurationSection(node + "prisoners").getKeys(false); + if(!prisoners.isEmpty()) { + pl.getLogger().info("Prisoner configuration section for " + j.getName() + " exists and there are " + prisoners.size() + " prisoners."); + for(String prisoner : prisoners) { + String pNode = node + "prisoners." + prisoner + "."; + Prisoner pris = new Prisoner(prisoner, flat.getBoolean(pNode + "muted"), flat.getLong(pNode + "time")); + pris.setOfflinePending(flat.getBoolean(pNode + "offlinePending")); + j.addPrisoner(pris); + } + }else { + pl.getLogger().warning("Prisoner configuration section for " + j.getName() + "exists but there are no prisoners."); + } + } + + if(pl.getServer().getWorld(j.getWorldName()) != null) { + pl.getJailManager().addJail(j, false); + pl.getLogger().info("Loaded jail " + j.getName() + " with " + j.getAllPrisoners().size() + " prisoners."); + } else + pl.getLogger().severe("Failed to load the jail " + j.getName() + " as the world '" + j.getWorldName() + "' does not exist (is null). Did you remove this world?"); break; } }