Merge pull request #230 from mikeprimm/master

Add support for optional 'visibleregions' list attribute for regions component, to limit visible region population
This commit is contained in:
mikeprimm 2011-06-20 16:50:48 -07:00
commit 42f4d4e4a6
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());