parent
7381ec8bce
commit
99e995b8dd
7 changed files with 450 additions and 0 deletions
Binary file not shown.
Binary file not shown.
@ -0,0 +1,83 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>org.dynmap</groupId> |
||||||
|
<artifactId>Dynmap-WorldGuard</artifactId> |
||||||
|
<version>0.10</version> |
||||||
|
|
||||||
|
<build> |
||||||
|
<resources> |
||||||
|
<resource> |
||||||
|
<directory>src/main/resources</directory> |
||||||
|
<filtering>true</filtering> |
||||||
|
<includes> |
||||||
|
<include>*.yml</include> |
||||||
|
<include>*.txt</include> |
||||||
|
</includes> |
||||||
|
</resource> |
||||||
|
<resource> |
||||||
|
<directory>src/main/resources</directory> |
||||||
|
<filtering>false</filtering> |
||||||
|
<excludes> |
||||||
|
<exclude>*.yml</exclude> |
||||||
|
<exclude>*.txt</exclude> |
||||||
|
</excludes> |
||||||
|
</resource> |
||||||
|
</resources> |
||||||
|
|
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<artifactId>maven-assembly-plugin</artifactId> |
||||||
|
<configuration> |
||||||
|
<descriptors> |
||||||
|
<descriptor>src/main/assembly/package.xml</descriptor> |
||||||
|
</descriptors> |
||||||
|
<!-- Hack for bug in maven-assembly: http://jira.codehaus.org/browse/MASSEMBLY-449 --> |
||||||
|
<archiverConfig> |
||||||
|
<fileMode>420</fileMode> <!-- 420(dec) = 644(oct) --> |
||||||
|
<directoryMode>493</directoryMode> <!-- 493(dec) = 755(oct) --> |
||||||
|
<defaultDirectoryMode>493</defaultDirectoryMode> |
||||||
|
</archiverConfig> |
||||||
|
</configuration> |
||||||
|
|
||||||
|
<executions> |
||||||
|
<execution> |
||||||
|
<id>build</id> |
||||||
|
<phase>package</phase> |
||||||
|
<goals> |
||||||
|
<goal>single</goal> |
||||||
|
</goals> |
||||||
|
</execution> |
||||||
|
</executions> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>org.dynmap</groupId> |
||||||
|
<artifactId>dynmap-api</artifactId> |
||||||
|
<version>0.25</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.bukkit</groupId> |
||||||
|
<artifactId>bukkit</artifactId> |
||||||
|
<version>0.0.1-SNAPSHOT</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.sk89q</groupId> |
||||||
|
<artifactId>WorldGuard</artifactId> |
||||||
|
<version>5.3</version> |
||||||
|
<scope>system</scope> |
||||||
|
<systemPath>${project.basedir}/WorldGuard.jar</systemPath> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.sk89q</groupId> |
||||||
|
<artifactId>WorldEdit</artifactId> |
||||||
|
<version>4.7</version> |
||||||
|
<scope>system</scope> |
||||||
|
<systemPath>${project.basedir}/WorldEdit.jar</systemPath> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
@ -0,0 +1,16 @@ |
|||||||
|
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> |
||||||
|
<id>bin</id> |
||||||
|
<includeBaseDirectory>false</includeBaseDirectory> |
||||||
|
<formats> |
||||||
|
<format>zip</format> |
||||||
|
</formats> |
||||||
|
<fileSets> |
||||||
|
</fileSets> |
||||||
|
<files> |
||||||
|
<file> |
||||||
|
<source>${project.build.directory}/${artifactId}-${version}.jar</source> |
||||||
|
<outputDirectory>/</outputDirectory> |
||||||
|
<destName>${artifactId}.jar</destName> |
||||||
|
</file> |
||||||
|
</files> |
||||||
|
</assembly> |
@ -0,0 +1,300 @@ |
|||||||
|
package org.dynmap.worldguard; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Set; |
||||||
|
import java.util.logging.Level; |
||||||
|
import java.util.logging.Logger; |
||||||
|
|
||||||
|
import org.bukkit.Location; |
||||||
|
import org.bukkit.World; |
||||||
|
import org.bukkit.configuration.ConfigurationSection; |
||||||
|
import org.bukkit.configuration.file.FileConfiguration; |
||||||
|
import org.bukkit.plugin.java.JavaPlugin; |
||||||
|
import org.bukkit.plugin.Plugin; |
||||||
|
import org.dynmap.DynmapAPI; |
||||||
|
import org.dynmap.markers.AreaMarker; |
||||||
|
import org.dynmap.markers.MarkerAPI; |
||||||
|
import org.dynmap.markers.MarkerSet; |
||||||
|
import org.dynmap.markers.Marker; |
||||||
|
|
||||||
|
import com.sk89q.worldedit.BlockVector; |
||||||
|
import com.sk89q.worldedit.BlockVector2D; |
||||||
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; |
||||||
|
import com.sk89q.worldguard.protection.GlobalRegionManager; |
||||||
|
import com.sk89q.worldguard.protection.flags.Flag; |
||||||
|
import com.sk89q.worldguard.protection.managers.RegionManager; |
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; |
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; |
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion; |
||||||
|
|
||||||
|
public class DynmapWorldGuardPlugin extends JavaPlugin { |
||||||
|
private static final Logger log = Logger.getLogger("Minecraft"); |
||||||
|
private static final String LOG_PREFIX = "[Dynmap-WorldGuard] "; |
||||||
|
private static final String DEF_INFOWINDOW = "<div class=\"infowindow\"><span style=\"font-size:120%;\">%regionname%</span><br /> Owner <span style=\"font-weight:bold;\">%playerowners%</span><br />Flags<br /><span style=\"font-weight:bold;\">%flags%</span></div>"; |
||||||
|
DynmapAPI api; |
||||||
|
MarkerAPI markerapi; |
||||||
|
WorldGuardPlugin wg; |
||||||
|
|
||||||
|
FileConfiguration cfg; |
||||||
|
MarkerSet set; |
||||||
|
long updperiod; |
||||||
|
boolean use3d; |
||||||
|
String infowindow; |
||||||
|
AreaStyle defstyle; |
||||||
|
Map<String, AreaStyle> cusstyle; |
||||||
|
Set<String> visible; |
||||||
|
Set<String> hidden; |
||||||
|
|
||||||
|
private static class AreaStyle { |
||||||
|
String strokecolor; |
||||||
|
double strokeopacity; |
||||||
|
int strokeweight; |
||||||
|
String fillcolor; |
||||||
|
double fillopacity; |
||||||
|
|
||||||
|
AreaStyle(FileConfiguration cfg, String path, AreaStyle def) { |
||||||
|
strokecolor = cfg.getString(path+".strokeColor", def.strokecolor); |
||||||
|
strokeopacity = cfg.getDouble(path+".strokeOpacity", def.strokeopacity); |
||||||
|
strokeweight = cfg.getInt(path+".strokeWeight", def.strokeweight); |
||||||
|
fillcolor = cfg.getString(path+".fillColor", def.fillcolor); |
||||||
|
fillopacity = cfg.getDouble(path+".fillOpacity", def.fillopacity); |
||||||
|
} |
||||||
|
|
||||||
|
AreaStyle(FileConfiguration cfg, String path) { |
||||||
|
strokecolor = cfg.getString(path+".strokeColor", "#FF0000"); |
||||||
|
strokeopacity = cfg.getDouble(path+".strokeOpacity", 0.8); |
||||||
|
strokeweight = cfg.getInt(path+".strokeWeight", 3); |
||||||
|
fillcolor = cfg.getString(path+".fillColor", "#FF0000"); |
||||||
|
fillopacity = cfg.getDouble(path+".fillOpacity", 0.35); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static void info(String msg) { |
||||||
|
log.log(Level.INFO, LOG_PREFIX + msg); |
||||||
|
} |
||||||
|
public static void severe(String msg) { |
||||||
|
log.log(Level.SEVERE, LOG_PREFIX + msg); |
||||||
|
} |
||||||
|
|
||||||
|
private class WorldGuardUpdate implements Runnable { |
||||||
|
public void run() { |
||||||
|
updateRegions(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private Map<String, AreaMarker> resareas = new HashMap<String, AreaMarker>(); |
||||||
|
|
||||||
|
private String formatInfoWindow(ProtectedRegion region) { |
||||||
|
String v = "<div class=\"regioninfo\">"+infowindow+"</div>"; |
||||||
|
v = v.replaceAll("%regionname%", region.getId()); |
||||||
|
v = v.replaceAll("%playerowners%", region.getOwners().toPlayersString()); |
||||||
|
v = v.replaceAll("%groupowners%", region.getOwners().toGroupsString()); |
||||||
|
v = v.replaceAll("%playermembers%", region.getMembers().toPlayersString()); |
||||||
|
v = v.replaceAll("%groupmembers%", region.getMembers().toGroupsString()); |
||||||
|
if(region.getParent() != null) |
||||||
|
v = v.replaceAll("%parent%", region.getParent().getId()); |
||||||
|
else |
||||||
|
v = v.replaceAll("%parent%", ""); |
||||||
|
v = v.replaceAll("%priority%", String.valueOf(region.getPriority())); |
||||||
|
Map<Flag<?>, Object> map = region.getFlags(); |
||||||
|
String flgs = ""; |
||||||
|
for(Flag<?> f : map.keySet()) { |
||||||
|
flgs += f.getName() + ": " + map.get(f).toString() + "<br/>"; |
||||||
|
} |
||||||
|
v = v.replaceAll("%flags%", flgs); |
||||||
|
return v; |
||||||
|
} |
||||||
|
|
||||||
|
private boolean isVisible(String id) { |
||||||
|
if((visible != null) && (visible.size() > 0)) { |
||||||
|
if(visible.contains(id) == false) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
if((hidden != null) && (hidden.size() > 0)) { |
||||||
|
if(hidden.contains(id)) |
||||||
|
return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
private void addStyle(String resid, AreaMarker m) { |
||||||
|
AreaStyle as = cusstyle.get(resid); |
||||||
|
if(as == null) |
||||||
|
as = defstyle; |
||||||
|
int sc = 0xFF0000; |
||||||
|
int fc = 0xFF0000; |
||||||
|
try { |
||||||
|
sc = Integer.parseInt(as.strokecolor.substring(1), 16); |
||||||
|
fc = Integer.parseInt(as.fillcolor.substring(1), 16); |
||||||
|
} catch (NumberFormatException nfx) { |
||||||
|
} |
||||||
|
m.setLineStyle(as.strokeweight, as.strokeopacity, sc); |
||||||
|
m.setFillStyle(as.fillopacity, fc); |
||||||
|
} |
||||||
|
|
||||||
|
/* Handle specific region */ |
||||||
|
private void handleRegion(World world, ProtectedRegion region, Map<String, AreaMarker> newmap) { |
||||||
|
String name = region.getId(); |
||||||
|
double[] x = null; |
||||||
|
double[] z = null; |
||||||
|
|
||||||
|
/* Build popup */ |
||||||
|
String desc = formatInfoWindow(region); |
||||||
|
|
||||||
|
/* Handle areas */ |
||||||
|
if(isVisible(region.getId())) { |
||||||
|
String id = region.getId(); |
||||||
|
String tn = region.getTypeName(); |
||||||
|
BlockVector l0 = region.getMinimumPoint(); |
||||||
|
BlockVector l1 = region.getMaximumPoint(); |
||||||
|
|
||||||
|
if(tn.equalsIgnoreCase("cuboid")) { /* Cubiod region? */ |
||||||
|
/* Make outline */ |
||||||
|
x = new double[4]; |
||||||
|
z = new double[4]; |
||||||
|
x[0] = l0.getX(); z[0] = l0.getZ(); |
||||||
|
x[1] = l0.getX(); z[1] = l1.getZ()+1.0; |
||||||
|
x[2] = l1.getX() + 1.0; z[2] = l1.getZ()+1.0; |
||||||
|
x[3] = l1.getX() + 1.0; z[3] = l0.getZ(); |
||||||
|
} |
||||||
|
else if(tn.equalsIgnoreCase("polygon")) { |
||||||
|
ProtectedPolygonalRegion ppr = (ProtectedPolygonalRegion)region; |
||||||
|
List<BlockVector2D> points = ppr.getPoints(); |
||||||
|
x = new double[points.size()]; |
||||||
|
z = new double[points.size()]; |
||||||
|
for(int i = 0; i < points.size(); i++) { |
||||||
|
BlockVector2D pt = points.get(i); |
||||||
|
x[i] = pt.getX(); z[i] = pt.getZ(); |
||||||
|
} |
||||||
|
} |
||||||
|
else { /* Unsupported type */ |
||||||
|
return; |
||||||
|
} |
||||||
|
AreaMarker m = resareas.remove(id); /* Existing area? */ |
||||||
|
if(m == null) { |
||||||
|
m = set.createAreaMarker(id, name, false, world.getName(), x, z, false); |
||||||
|
if(m == null) |
||||||
|
return; |
||||||
|
} |
||||||
|
else { |
||||||
|
m.setCornerLocations(x, z); /* Replace corner locations */ |
||||||
|
m.setLabel(name); /* Update label */ |
||||||
|
} |
||||||
|
if(use3d) { /* If 3D? */ |
||||||
|
m.setRangeY(l1.getY()+1.0, l0.getY()); |
||||||
|
} |
||||||
|
m.setDescription(desc); /* Set popup */ |
||||||
|
|
||||||
|
/* Set line and fill properties */ |
||||||
|
addStyle(id, m); |
||||||
|
|
||||||
|
/* Add to map */ |
||||||
|
newmap.put(id, m); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/* Update worldguard region information */ |
||||||
|
private void updateRegions() { |
||||||
|
Map<String,AreaMarker> newmap = new HashMap<String,AreaMarker>(); /* Build new map */ |
||||||
|
|
||||||
|
/* Loop through worlds */ |
||||||
|
for(World w : getServer().getWorlds()) { |
||||||
|
RegionManager rm = wg.getRegionManager(w); /* Get region manager for world */ |
||||||
|
if(rm == null) continue; |
||||||
|
|
||||||
|
Map<String,ProtectedRegion> regions = rm.getRegions(); /* Get all the regions */ |
||||||
|
for(ProtectedRegion pr : regions.values()) { |
||||||
|
handleRegion(w, pr, newmap); |
||||||
|
} |
||||||
|
} |
||||||
|
/* Now, review old map - anything left is gone */ |
||||||
|
for(AreaMarker oldm : resareas.values()) { |
||||||
|
oldm.deleteMarker(); |
||||||
|
} |
||||||
|
/* And replace with new map */ |
||||||
|
resareas = newmap; |
||||||
|
|
||||||
|
getServer().getScheduler().scheduleSyncDelayedTask(this, new WorldGuardUpdate(), updperiod); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void onEnable() { |
||||||
|
Plugin p = this.getServer().getPluginManager().getPlugin("dynmap"); /* Find dynmap */ |
||||||
|
if(p == null) { |
||||||
|
severe("Error loading dynmap API!"); |
||||||
|
return; |
||||||
|
} |
||||||
|
api = (DynmapAPI)p; /* Get API */ |
||||||
|
/* Now, get markers API */ |
||||||
|
markerapi = api.getMarkerAPI(); |
||||||
|
if(markerapi == null) { |
||||||
|
severe("Error loading dynmap marker API!"); |
||||||
|
return; |
||||||
|
} |
||||||
|
/* Find worldguard */ |
||||||
|
p = this.getServer().getPluginManager().getPlugin("WorldGuard"); |
||||||
|
if(p == null) { |
||||||
|
severe("Error loading WorldGuard"); |
||||||
|
return; |
||||||
|
} |
||||||
|
wg = (WorldGuardPlugin)p; |
||||||
|
|
||||||
|
/* Load configuration */ |
||||||
|
FileConfiguration cfg = getConfig(); |
||||||
|
cfg.options().copyDefaults(true); /* Load defaults, if needed */ |
||||||
|
this.saveConfig(); /* Save updates, if needed */ |
||||||
|
|
||||||
|
/* Now, add marker set for mobs (make it transient) */ |
||||||
|
set = markerapi.createMarkerSet("worldguard.markerset", cfg.getString("layer.name", "WorldGuard"), null, false); |
||||||
|
if(set == null) { |
||||||
|
severe("Error creating marker set"); |
||||||
|
return; |
||||||
|
} |
||||||
|
set.setLayerPriority(cfg.getInt("layer.layerprio", 10)); |
||||||
|
set.setHideByDefault(cfg.getBoolean("layer.hidebydefault", false)); |
||||||
|
use3d = cfg.getBoolean("use3dregions", false); |
||||||
|
infowindow = cfg.getString("infowindow", DEF_INFOWINDOW); |
||||||
|
|
||||||
|
/* Get style information */ |
||||||
|
defstyle = new AreaStyle(cfg, "regionstyle"); |
||||||
|
cusstyle = new HashMap<String, AreaStyle>(); |
||||||
|
ConfigurationSection sect = cfg.getConfigurationSection("custstyle"); |
||||||
|
if(sect != null) { |
||||||
|
Set<String> ids = sect.getKeys(false); |
||||||
|
|
||||||
|
for(String id : ids) { |
||||||
|
cusstyle.put(id, new AreaStyle(cfg, "custstyle." + id, defstyle)); |
||||||
|
} |
||||||
|
} |
||||||
|
List vis = cfg.getList("visibleregions"); |
||||||
|
if(vis != null) { |
||||||
|
visible = new HashSet<String>(vis); |
||||||
|
} |
||||||
|
List hid = cfg.getList("hiddenregions"); |
||||||
|
if(hid != null) { |
||||||
|
hidden = new HashSet<String>(hid); |
||||||
|
} |
||||||
|
|
||||||
|
/* Set up update job - based on periond */ |
||||||
|
int per = cfg.getInt("update.period", 300); |
||||||
|
if(per < 15) per = 15; |
||||||
|
updperiod = (long)(per*20); |
||||||
|
|
||||||
|
getServer().getScheduler().scheduleSyncDelayedTask(this, new WorldGuardUpdate(), 40); /* First time is 2 seconds */ |
||||||
|
|
||||||
|
info("version " + this.getDescription().getVersion() + " is enabled"); |
||||||
|
} |
||||||
|
|
||||||
|
public void onDisable() { |
||||||
|
if(set != null) { |
||||||
|
set.deleteMarkerSet(); |
||||||
|
set = null; |
||||||
|
} |
||||||
|
resareas.clear(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
# Dynmap-WorldGuard configuration |
||||||
|
# |
||||||
|
update: |
||||||
|
# Seconds between checks for Residence updates |
||||||
|
period: 300 |
||||||
|
|
||||||
|
layer: |
||||||
|
name: "WorldGuard" |
||||||
|
# Make mobs layer hidden by default |
||||||
|
hidebydefault: false |
||||||
|
# ordering priority in layer menu (low goes before high - default is 0) |
||||||
|
layerprio: 0 |
||||||
|
|
||||||
|
# Set true to show 3D volumes for zones |
||||||
|
use3dregions: false |
||||||
|
|
||||||
|
# Format for popup - substitute values for macros |
||||||
|
infowindow: '<div class=\"infowindow\"><span style=\"font-size:120%;">%regionname% (%parent) - %priority</span><br /> Owners <span style="font-weight:bold;">%playerowners%<br/>%groupowners%</span><br/>Members <span style="font-weight:bold;">%playermembers%<br/>%groupmembers%</span><br/>Flags<br /><span style="font-weight:bold;">%flags%</span></div>' |
||||||
|
|
||||||
|
regionstyle: |
||||||
|
strokeColor: "#FF0000" |
||||||
|
strokeOpacity: 0.8 |
||||||
|
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 |
||||||
|
# - area.subzone1 |
||||||
|
|
||||||
|
# Optional setting to hide specific regions, by name |
||||||
|
#hiddenregions: |
||||||
|
# - hiddenplace |
||||||
|
# - secretsite |
||||||
|
|
||||||
|
# Optional per-region overrides for regionstyle (any defined replace those in regionstyle) |
||||||
|
#customstyle: |
||||||
|
# homebase: |
||||||
|
# strokeColor: "#00FF00" |
||||||
|
# homebase.sub1: |
||||||
|
# strokeColor: "#007F00" |
||||||
|
|
||||||
|
|
@ -0,0 +1,6 @@ |
|||||||
|
name: Dynmap-WorldGuard |
||||||
|
main: org.dynmap.worldguard.DynmapWorldGuardPlugin |
||||||
|
version: "${project.version}" |
||||||
|
author: mikeprimm |
||||||
|
depend: [ dynmap, WorldGuard ] |
||||||
|
|
Loading…
Reference in new issue