Fixed parenting not saving.

This commit is contained in:
sk89q 2011-04-02 14:11:12 -07:00
parent 896c7fc467
commit b584b996a3
3 changed files with 34 additions and 33 deletions

View File

@ -25,7 +25,6 @@
import org.bukkit.plugin.PluginManager;
import org.bukkit.block.Block;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.World;
import org.bukkit.event.block.*;

View File

@ -23,6 +23,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -37,6 +38,7 @@
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
import com.sk89q.worldguard.util.yaml.Configuration;
import com.sk89q.worldguard.util.yaml.ConfigurationNode;
@ -62,8 +64,11 @@ public void load() throws IOException {
this.regions = new HashMap<String, ProtectedRegion>();
return;
}
regions = new HashMap<String, ProtectedRegion>();
Map<String,ProtectedRegion> regions =
new HashMap<String,ProtectedRegion>();
Map<ProtectedRegion,String> parentSets =
new LinkedHashMap<ProtectedRegion, String>();
for (Map.Entry<String, ConfigurationNode> entry : regionData.entrySet()) {
String id = entry.getKey().toLowerCase().replace(".", "");
@ -100,10 +105,32 @@ public void load() throws IOException {
region.setOwners(parseDomain(node.getNode("owners")));
region.setMembers(parseDomain(node.getNode("members")));
regions.put(id, region);
String parentId = node.getString("parent");
if (parentId != null) {
parentSets.put(region, parentId);
}
} catch (NullPointerException e) {
logger.warning("Missing data for region '" + id + '"');
}
}
// Relink parents
for (Map.Entry<ProtectedRegion, String> entry : parentSets.entrySet()) {
ProtectedRegion parent = regions.get(entry.getValue());
if (parent != null) {
try {
entry.getKey().setParent(parent);
} catch (CircularInheritanceException e) {
logger.warning("Circular inheritance detect with '"
+ entry.getValue() + "' detected as a parent");
}
} else {
logger.warning("Unknown region parent: " + entry.getValue());
}
}
this.regions = regions;
}
private <V> V checkNonNull(V val) throws NullPointerException {
@ -194,6 +221,10 @@ public void save() throws IOException {
node.setProperty("flags", getFlagData(region));
node.setProperty("owners", getDomainData(region.getOwners()));
node.setProperty("members", getDomainData(region.getMembers()));
ProtectedRegion parent = region.getParent();
if (parent != null) {
node.setProperty("parent", parent.getId());
}
}
config.save();

View File

@ -50,11 +50,7 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
/**
* Holds the curParent.
*/
private transient ProtectedRegion parent;
/**
* Holds the curParent's Id. Used for serialization, don't touch it.
*/
private String parentId;
private ProtectedRegion parent;
/**
* List of owners.
*/
@ -84,31 +80,6 @@ public String getId() {
return id;
}
/*
* Important for serialization
*/
public String getParentId() {
if (this.parent != null) {
this.parentId = parent.getId();
}
return this.parentId;
}
/**
* @setFlag the parentId. Used for serialization, don't touch it.
*/
public void setParentId() {
if (this.parent != null) {
this.parentId = parent.getId();
} else {
this.parentId = null;
}
}
/**
* Get the lower point of the cuboid.
*