From 23970a4e363188bc8c44c6ebc066c2e4f678178c Mon Sep 17 00:00:00 2001 From: Redecouverte Date: Thu, 24 Feb 2011 12:06:27 +0100 Subject: [PATCH] extended AreaFlags data storage, fixed typo on renaming old regions.txt --- .../worldguard/bukkit/WorldGuardPlugin.java | 2 +- .../protection/regions/AreaFlags.java | 136 +++++++++++++++++- 2 files changed, 130 insertions(+), 8 deletions(-) diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index f3fd2432..d91053a9 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -347,7 +347,7 @@ public void loadConfiguration() { } mgr.save(); - CSVfile.renameTo(new File(this.getDataFolder(), "region.txt.old")); + CSVfile.renameTo(new File(this.getDataFolder(), "regions.txt.old")); logger.info("WorldGuard: Done."); } diff --git a/src/com/sk89q/worldguard/protection/regions/AreaFlags.java b/src/com/sk89q/worldguard/protection/regions/AreaFlags.java index 81a12d96..aff0444c 100644 --- a/src/com/sk89q/worldguard/protection/regions/AreaFlags.java +++ b/src/com/sk89q/worldguard/protection/regions/AreaFlags.java @@ -111,10 +111,23 @@ public static String fromAlias(String name) { } } - private Map states = new HashMap(); - + private Map> flags = new HashMap>(); + + + private Map getFlagData(String name) + { + Map ret = flags.get(name); + if(ret == null) + { + ret = new HashMap(); + flags.put(name, ret); + } + + return ret; + } + public State get(String flag) { - State state = states.get(flag); + State state = State.valueOf(getFlagData("states").get(flag)); if (state == null) { return State.NONE; } @@ -123,14 +136,22 @@ public State get(String flag) { public void set(String flag, State state) { if (state == State.NONE) { - states.remove(flag); + getFlagData("states").remove(flag); } else { - states.put(flag, state); + getFlagData("states").put(flag, state.toString()); } } public Set> entrySet() { - return states.entrySet(); + + Map ret = new HashMap(); + + for(Map.Entry entry : getFlagData("states").entrySet()) + { + ret.put(entry.getKey(), State.valueOf(entry.getValue())); + } + + return ret.entrySet(); } @Override @@ -140,6 +161,107 @@ public boolean equals(Object obj) { } AreaFlags other = (AreaFlags)obj; - return other.states.equals(this); + return other.flags.equals(this.flags); } + + @Override + public int hashCode() { + int hash = 3; + hash = 97 * hash + (this.flags != null ? this.flags.hashCode() : 0); + return hash; + } + + + public void setFlag(String name, String subname, String value) + { + if (value == null) { + getFlagData(name).remove(subname); + } else { + getFlagData(name).put(subname, value); + } + } + + public void setFlag(String name, String subname, Boolean value) + { + if (value == null) { + getFlagData(name).remove(subname); + } else { + getFlagData(name).put(subname, value.toString()); + } + } + + public void setFlag(String name, String subname, Integer value) + { + if (value == null) { + getFlagData(name).remove(subname); + } else { + getFlagData(name).put(subname, value.toString()); + } + } + + public void setFlag(String name, String subname, Float value) + { + if (value == null) { + getFlagData(name).remove(subname); + } else { + getFlagData(name).put(subname, value.toString()); + } + } + + public void setFlag(String name, String subname, Double value) + { + if (value == null) { + getFlagData(name).remove(subname); + } else { + getFlagData(name).put(subname, value.toString()); + } + } + + public String getFlag(String name, String subname) + { + return getFlagData(name).get(subname); + } + + public Boolean getBooleanFlag(String name, String subname) + { + String data = getFlagData(name).get(subname); + if(data == null) + { + return null; + } + return Boolean.valueOf(data); + } + + public Integer getIntFlag(String name, String subname) + { + String data = getFlagData(name).get(subname); + if(data == null) + { + return null; + } + return Integer.valueOf(data); + } + + public Float getFloatFlag(String name, String subname) + { + String data = getFlagData(name).get(subname); + if(data == null) + { + return null; + } + return Float.valueOf(data); + } + + public Double getDoubleFlag(String name, String subname) + { + String data = getFlagData(name).get(subname); + if(data == null) + { + return null; + } + return Double.valueOf(data); + } + + + }