Improved YAML loading/saving.

This commit is contained in:
sk89q 2011-04-01 22:46:45 -07:00
parent 649db3aca2
commit 9803d6b731
3 changed files with 23 additions and 7 deletions

View File

@ -25,6 +25,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
@ -216,12 +217,27 @@ private <V> void addMarshalledFlag(Map<String, Object> flagData,
private Map<String, Object> getDomainData(DefaultDomain domain) {
Map<String, Object> domainData = new HashMap<String, Object>();
domainData.put("players", domain.getPlayers());
domainData.put("groups", domain.getGroups());
setDomainData(domainData, "players", domain.getPlayers());
setDomainData(domainData, "groups", domain.getGroups());
return domainData;
}
private void setDomainData(Map<String, Object> domainData,
String key, Set<String> domain) {
if (domain.size() == 0) {
return;
}
List<String> list = new ArrayList<String>();
for (String str : domain) {
list.add(str);
}
domainData.put(key, list);
}
@Override
public Map<String, ProtectedRegion> getRegions() {
return regions;

View File

@ -75,8 +75,8 @@ public Configuration(File file) {
super(new HashMap<String, Object>());
DumperOptions options = new DumperOptions();
options.setIndent(4);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setIndent(2);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.AUTO);
yaml = new Yaml(new SafeConstructor(), new Representer(), options);

View File

@ -158,9 +158,9 @@ public void setProperty(String path, Object value) {
* @return
*/
public ConfigurationNode addNode(String path) {
ConfigurationNode node = new ConfigurationNode(
new HashMap<String, Object>());
setProperty(path, node);
Map<String, Object> map = new HashMap<String, Object>();
ConfigurationNode node = new ConfigurationNode(map);
setProperty(path, map);
return node;
}