Add support for ownerstyle (style based on owner player or group) and add wildcard option for custstyle (wildcard '|' in region ID)

recommended
Mike Primm 14 years ago committed by mikeprimm
parent a3264e3b75
commit 13de73ded2
  1. 59
      src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java
  2. 7
      src/main/resources/config.yml

@ -26,6 +26,7 @@ import org.dynmap.markers.MarkerSet;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
@ -47,6 +48,8 @@ public class DynmapWorldGuardPlugin extends JavaPlugin {
String infowindow; String infowindow;
AreaStyle defstyle; AreaStyle defstyle;
Map<String, AreaStyle> cusstyle; Map<String, AreaStyle> cusstyle;
Map<String, AreaStyle> cuswildstyle;
Map<String, AreaStyle> ownerstyle;
Set<String> visible; Set<String> visible;
Set<String> hidden; Set<String> hidden;
boolean stop; boolean stop;
@ -125,10 +128,40 @@ public class DynmapWorldGuardPlugin extends JavaPlugin {
return true; return true;
} }
private void addStyle(String resid, AreaMarker m) { private void addStyle(String resid, AreaMarker m, ProtectedRegion region) {
AreaStyle as = cusstyle.get(resid); AreaStyle as = cusstyle.get(resid);
if(as == null) { /* Check for wildcard style matches */
for(String wc : cuswildstyle.keySet()) {
String[] tok = wc.split("\\|");
if((tok.length == 1) && resid.startsWith(tok[0]))
as = cuswildstyle.get(wc);
else if((tok.length >= 2) && resid.startsWith(tok[0]) && resid.endsWith(tok[1]))
as = cuswildstyle.get(wc);
}
}
if(as == null) { /* Check for owner style matches */
if(ownerstyle.isEmpty() != true) {
DefaultDomain dd = region.getOwners();
Set<String> play = dd.getPlayers();
if(play != null) {
for(String p : play) {
if(as == null) {
as = ownerstyle.get(p.toLowerCase());
}
}
}
Set<String> grp = dd.getGroups();
if(grp != null) {
for(String p : grp) {
if(as == null)
as = ownerstyle.get(p.toLowerCase());
}
}
}
}
if(as == null) if(as == null)
as = defstyle; as = defstyle;
int sc = 0xFF0000; int sc = 0xFF0000;
int fc = 0xFF0000; int fc = 0xFF0000;
try { try {
@ -178,9 +211,10 @@ public class DynmapWorldGuardPlugin extends JavaPlugin {
else { /* Unsupported type */ else { /* Unsupported type */
return; return;
} }
AreaMarker m = resareas.remove(id); /* Existing area? */ String markerid = world.getName() + "_" + id;
AreaMarker m = resareas.remove(markerid); /* Existing area? */
if(m == null) { if(m == null) {
m = set.createAreaMarker(id, name, false, world.getName(), x, z, false); m = set.createAreaMarker(markerid, name, false, world.getName(), x, z, false);
if(m == null) if(m == null)
return; return;
} }
@ -194,10 +228,10 @@ public class DynmapWorldGuardPlugin extends JavaPlugin {
m.setDescription(desc); /* Set popup */ m.setDescription(desc); /* Set popup */
/* Set line and fill properties */ /* Set line and fill properties */
addStyle(id, m); addStyle(id, m, region);
/* Add to map */ /* Add to map */
newmap.put(id, m); newmap.put(markerid, m);
} }
} }
@ -288,12 +322,25 @@ public class DynmapWorldGuardPlugin extends JavaPlugin {
/* Get style information */ /* Get style information */
defstyle = new AreaStyle(cfg, "regionstyle"); defstyle = new AreaStyle(cfg, "regionstyle");
cusstyle = new HashMap<String, AreaStyle>(); cusstyle = new HashMap<String, AreaStyle>();
ownerstyle = new HashMap<String, AreaStyle>();
cuswildstyle = new HashMap<String, AreaStyle>();
ConfigurationSection sect = cfg.getConfigurationSection("custstyle"); ConfigurationSection sect = cfg.getConfigurationSection("custstyle");
if(sect != null) { if(sect != null) {
Set<String> ids = sect.getKeys(false); Set<String> ids = sect.getKeys(false);
for(String id : ids) { for(String id : ids) {
cusstyle.put(id, new AreaStyle(cfg, "custstyle." + id, defstyle)); if(id.indexOf('|') >= 0)
cuswildstyle.put(id, new AreaStyle(cfg, "custstyle." + id, defstyle));
else
cusstyle.put(id, new AreaStyle(cfg, "custstyle." + id, defstyle));
}
}
sect = cfg.getConfigurationSection("ownerstyle");
if(sect != null) {
Set<String> ids = sect.getKeys(false);
for(String id : ids) {
ownerstyle.put(id.toLowerCase(), new AreaStyle(cfg, "ownerstyle." + id, defstyle));
} }
} }
List vis = cfg.getList("visibleregions"); List vis = cfg.getList("visibleregions");

@ -31,8 +31,13 @@ visibleregions: [ ]
hiddenregions: [ ] hiddenregions: [ ]
# Optional per-region overrides for regionstyle (any defined replace those in regionstyle) # Optional per-region overrides for regionstyle (any defined replace those in regionstyle)
# Also supports region IDs with single wildcard '|' pattern
custstyle: custstyle:
customregion1: customregion1:
strokeColor: "#00FF00" strokeColor: "#00FF00"
# Optional per-owner overrides for regionstyle (lower priority than custstyle) - works for group or user names
ownerstyle:
kingoftheworld:
strokecolor: "#C0C0C0"

Loading…
Cancel
Save