Add support for visibleregions list for regions component - limit

which regions are shown
This commit is contained in:
Mike Primm 2011-06-20 18:48:23 -05:00
parent 2c3e8fbdc0
commit a7c6a20dcc
2 changed files with 22 additions and 0 deletions

View File

@ -60,6 +60,10 @@ components:
# strokeWeight: 3
# fillColor: "#FF0000"
# fillOpacity: 0.35
# # Optional setting to limit which regions to show, by name - if commented out, all regions are shown
# visibleregions:
# - homebase
# - miningsite
#- class: org.dynmap.TestComponent
# stuff: "This is some configuration-value"

View File

@ -1,10 +1,13 @@
package org.dynmap.regions;
import java.io.File;
import java.util.List;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Map;
import java.util.HashSet;
import java.util.logging.Level;
import org.bukkit.util.config.Configuration;
import org.dynmap.ConfigurationNode;
@ -60,6 +63,21 @@ public class RegionHandler extends FileHandler {
regionConfig.load();
/* Parse region data and store in MemoryInputStream */
Map<?, ?> regionData = (Map<?, ?>) regionConfig.getProperty(regions.getString("basenode", "regions"));
/* See if we have explicit list of regions to report - limit to this list if we do */
List<String> idlist = regions.getStrings("visibleregions", null);
if(idlist != null) {
@SuppressWarnings("unchecked")
HashSet<String> ids = new HashSet<String>((Collection<? extends String>) regionData.keySet());
for(String id : ids) {
/* If not in list, remove it */
if(!idlist.contains(id)) {
regionData.remove(id);
log.info("discard " + id);
}
else
log.info("keep " + id);
}
}
try {
ByteArrayOutputStream fos = new ByteArrayOutputStream();
fos.write(Json.stringifyJson(regionData).getBytes());