Initial drop
This commit is contained in:
parent
f65fc8bfb8
commit
34c64af107
25
.gitignore
vendored
Normal file
25
.gitignore
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Eclipse stuff
|
||||||
|
/.classpath
|
||||||
|
/.project
|
||||||
|
/.settings
|
||||||
|
|
||||||
|
# netbeans
|
||||||
|
/nbproject
|
||||||
|
|
||||||
|
# we use maven!
|
||||||
|
/build.xml
|
||||||
|
|
||||||
|
# maven
|
||||||
|
/target
|
||||||
|
|
||||||
|
# vim
|
||||||
|
.*.sw[a-p]
|
||||||
|
|
||||||
|
# various other potential build files
|
||||||
|
/build
|
||||||
|
/bin
|
||||||
|
/dist
|
||||||
|
/manifest.mf
|
||||||
|
|
||||||
|
# Mac filesystem dust
|
||||||
|
/.DS_Store
|
BIN
Factions.jar
Normal file
BIN
Factions.jar
Normal file
Binary file not shown.
76
pom.xml
Normal file
76
pom.xml
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<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-Factions</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>1.0.0-R1-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.massivecraft</groupId>
|
||||||
|
<artifactId>Factions</artifactId>
|
||||||
|
<version>1.6.1</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${project.basedir}/Factions.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
16
src/main/assembly/package.xml
Normal file
16
src/main/assembly/package.xml
Normal file
@ -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>
|
565
src/main/java/org/dynmap/factions/DynmapFactionsPlugin.java
Normal file
565
src/main/java/org/dynmap/factions/DynmapFactionsPlugin.java
Normal file
@ -0,0 +1,565 @@
|
|||||||
|
package org.dynmap.factions;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
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.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.event.Event.Priority;
|
||||||
|
import org.bukkit.event.Event.Type;
|
||||||
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
|
import org.bukkit.event.server.ServerListener;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.dynmap.DynmapAPI;
|
||||||
|
import org.dynmap.markers.AreaMarker;
|
||||||
|
import org.dynmap.markers.Marker;
|
||||||
|
import org.dynmap.markers.MarkerAPI;
|
||||||
|
import org.dynmap.markers.MarkerIcon;
|
||||||
|
import org.dynmap.markers.MarkerSet;
|
||||||
|
|
||||||
|
import com.massivecraft.factions.FPlayer;
|
||||||
|
import com.massivecraft.factions.Factions;
|
||||||
|
import com.massivecraft.factions.Board;
|
||||||
|
import com.massivecraft.factions.Faction;
|
||||||
|
|
||||||
|
public class DynmapFactionsPlugin extends JavaPlugin {
|
||||||
|
private static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
private static final String LOG_PREFIX = "[Dynmap-Factions] ";
|
||||||
|
private static final String DEF_INFOWINDOW = "<div class=\"infowindow\"><span style=\"font-size:120%;\">%regionname%</span><br />Flags<br /><span style=\"font-weight:bold;\">%flags%</span></div>";
|
||||||
|
Plugin dynmap;
|
||||||
|
DynmapAPI api;
|
||||||
|
MarkerAPI markerapi;
|
||||||
|
Plugin factions;
|
||||||
|
Factions factapi;
|
||||||
|
|
||||||
|
int blocksize;
|
||||||
|
|
||||||
|
FileConfiguration cfg;
|
||||||
|
MarkerSet set;
|
||||||
|
long updperiod;
|
||||||
|
boolean use3d;
|
||||||
|
String infowindow;
|
||||||
|
AreaStyle defstyle;
|
||||||
|
Map<String, AreaStyle> cusstyle;
|
||||||
|
Set<String> visible;
|
||||||
|
Set<String> hidden;
|
||||||
|
boolean stop;
|
||||||
|
|
||||||
|
private class AreaStyle {
|
||||||
|
String strokecolor;
|
||||||
|
double strokeopacity;
|
||||||
|
int strokeweight;
|
||||||
|
String fillcolor;
|
||||||
|
double fillopacity;
|
||||||
|
String homemarker;
|
||||||
|
MarkerIcon homeicon;
|
||||||
|
|
||||||
|
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);
|
||||||
|
homemarker = cfg.getString(path+".homeicon", def.homemarker);
|
||||||
|
if(homemarker != null) {
|
||||||
|
homeicon = markerapi.getMarkerIcon(homemarker);
|
||||||
|
if(homeicon == null) {
|
||||||
|
severe("Invalid homeicon: " + homemarker);
|
||||||
|
homeicon = markerapi.getMarkerIcon("blueicon");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
homemarker = cfg.getString(path+".homeicon", null);
|
||||||
|
if(homemarker != null) {
|
||||||
|
homeicon = markerapi.getMarkerIcon(homemarker);
|
||||||
|
if(homeicon == null) {
|
||||||
|
severe("Invalid homeicon: " + homemarker);
|
||||||
|
homeicon = markerapi.getMarkerIcon("blueicon");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 FactionsUpdate implements Runnable {
|
||||||
|
public void run() {
|
||||||
|
if(!stop)
|
||||||
|
updateFactions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, AreaMarker> resareas = new HashMap<String, AreaMarker>();
|
||||||
|
private Map<String, Marker> resmark = new HashMap<String, Marker>();
|
||||||
|
|
||||||
|
private String formatInfoWindow(Faction fact) {
|
||||||
|
String v = "<div class=\"regioninfo\">"+infowindow+"</div>";
|
||||||
|
v = v.replaceAll("%regionname%", ChatColor.stripColor(fact.getTag()));
|
||||||
|
FPlayer adm = fact.getFPlayerAdmin();
|
||||||
|
v = v.replaceAll("%playerowners%", (adm!=null)?adm.getName():"");
|
||||||
|
String res = "";
|
||||||
|
for(FPlayer r : fact.getFPlayers()) {
|
||||||
|
if(res.length()>0) res += ",";
|
||||||
|
res += r.getName();
|
||||||
|
}
|
||||||
|
v = v.replaceAll("%playermembers%", res);
|
||||||
|
|
||||||
|
v = v.replaceAll("%nation%", ChatColor.stripColor(fact.getTag()));
|
||||||
|
/* Build flags */
|
||||||
|
String flgs = "open: " + fact.getOpen();
|
||||||
|
flgs += "<br/>peactful: " + fact.isPeaceful();
|
||||||
|
flgs += "<br/>peacefulExplosionsEnabled: " + fact.getPeacefulExplosionsEnabled();
|
||||||
|
flgs += "<br/>warzone: " + fact.isWarZone();
|
||||||
|
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) {
|
||||||
|
info("addStyle(" + resid + ")");
|
||||||
|
AreaStyle as = cusstyle.get(resid);
|
||||||
|
if(as == null) {
|
||||||
|
as = defstyle;
|
||||||
|
info("addStyle - default");
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MarkerIcon getMarkerIcon(String factname, Faction fact) {
|
||||||
|
AreaStyle as = cusstyle.get(factname);
|
||||||
|
if(as == null) {
|
||||||
|
as = defstyle;
|
||||||
|
}
|
||||||
|
return as.homeicon;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum direction { XPLUS, ZPLUS, XMINUS, ZMINUS };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all contiguous blocks, set in target and clear in source
|
||||||
|
*/
|
||||||
|
private int floodFillTarget(TileFlags src, TileFlags dest, int x, int y) {
|
||||||
|
int cnt = 0;
|
||||||
|
if(src.getFlag(x, y)) { /* Set in src */
|
||||||
|
src.setFlag(x, y, false); /* Clear source */
|
||||||
|
dest.setFlag(x, y, true); /* Set in destination */
|
||||||
|
cnt++;
|
||||||
|
cnt += floodFillTarget(src, dest, x+1, y); /* Fill adjacent blocks */
|
||||||
|
cnt += floodFillTarget(src, dest, x-1, y);
|
||||||
|
cnt += floodFillTarget(src, dest, x, y+1);
|
||||||
|
cnt += floodFillTarget(src, dest, x, y-1);
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FactionBlock {
|
||||||
|
int x, z;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FactionBlocks {
|
||||||
|
Map<String, LinkedList<FactionBlock>> blocks = new HashMap<String, LinkedList<FactionBlock>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Handle specific faction on specific world */
|
||||||
|
private void handleFactionOnWorld(String factname, Faction fact, String world, LinkedList<FactionBlock> blocks, Map<String, AreaMarker> newmap, Map<String, Marker> newmark) {
|
||||||
|
double[] x = null;
|
||||||
|
double[] z = null;
|
||||||
|
int poly_index = 0; /* Index of polygon for given faction */
|
||||||
|
|
||||||
|
/* Build popup */
|
||||||
|
String desc = formatInfoWindow(fact);
|
||||||
|
|
||||||
|
/* Handle areas */
|
||||||
|
if(isVisible(factname)) {
|
||||||
|
if(blocks.isEmpty())
|
||||||
|
return;
|
||||||
|
LinkedList<FactionBlock> nodevals = new LinkedList<FactionBlock>();
|
||||||
|
TileFlags curblks = new TileFlags();
|
||||||
|
/* Loop through blocks: set flags on blockmaps */
|
||||||
|
for(FactionBlock b : blocks) {
|
||||||
|
curblks.setFlag(b.x, b.z, true); /* Set flag for block */
|
||||||
|
nodevals.addLast(b);
|
||||||
|
}
|
||||||
|
/* Loop through until we don't find more areas */
|
||||||
|
while(nodevals != null) {
|
||||||
|
LinkedList<FactionBlock> ournodes = null;
|
||||||
|
LinkedList<FactionBlock> newlist = null;
|
||||||
|
TileFlags ourblks = null;
|
||||||
|
int minx = Integer.MAX_VALUE;
|
||||||
|
int minz = Integer.MAX_VALUE;
|
||||||
|
for(FactionBlock node : nodevals) {
|
||||||
|
int nodex = node.x;
|
||||||
|
int nodez = node.z;
|
||||||
|
/* If we need to start shape, and this block is not part of one yet */
|
||||||
|
if((ourblks == null) && curblks.getFlag(nodex, nodez)) {
|
||||||
|
ourblks = new TileFlags(); /* Create map for shape */
|
||||||
|
ournodes = new LinkedList<FactionBlock>();
|
||||||
|
floodFillTarget(curblks, ourblks, nodex, nodez); /* Copy shape */
|
||||||
|
ournodes.add(node); /* Add it to our node list */
|
||||||
|
minx = nodex; minz = nodez;
|
||||||
|
}
|
||||||
|
/* If shape found, and we're in it, add to our node list */
|
||||||
|
else if((ourblks != null) && ourblks.getFlag(nodex, nodez)) {
|
||||||
|
ournodes.add(node);
|
||||||
|
if(nodex < minx) {
|
||||||
|
minx = nodex; minz = nodez;
|
||||||
|
}
|
||||||
|
else if((nodex == minx) && (nodez < minz)) {
|
||||||
|
minz = nodez;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { /* Else, keep it in the list for the next polygon */
|
||||||
|
if(newlist == null) newlist = new LinkedList<FactionBlock>();
|
||||||
|
newlist.add(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nodevals = newlist; /* Replace list (null if no more to process) */
|
||||||
|
if(ourblks != null) {
|
||||||
|
/* Trace outline of blocks - start from minx, minz going to x+ */
|
||||||
|
int init_x = minx;
|
||||||
|
int init_z = minz;
|
||||||
|
int cur_x = minx;
|
||||||
|
int cur_z = minz;
|
||||||
|
direction dir = direction.XPLUS;
|
||||||
|
ArrayList<int[]> linelist = new ArrayList<int[]>();
|
||||||
|
linelist.add(new int[] { init_x, init_z } ); // Add start point
|
||||||
|
while((cur_x != init_x) || (cur_z != init_z) || (dir != direction.ZMINUS)) {
|
||||||
|
switch(dir) {
|
||||||
|
case XPLUS: /* Segment in X+ direction */
|
||||||
|
if(!ourblks.getFlag(cur_x+1, cur_z)) { /* Right turn? */
|
||||||
|
linelist.add(new int[] { cur_x+1, cur_z }); /* Finish line */
|
||||||
|
dir = direction.ZPLUS; /* Change direction */
|
||||||
|
}
|
||||||
|
else if(!ourblks.getFlag(cur_x+1, cur_z-1)) { /* Straight? */
|
||||||
|
cur_x++;
|
||||||
|
}
|
||||||
|
else { /* Left turn */
|
||||||
|
linelist.add(new int[] { cur_x+1, cur_z }); /* Finish line */
|
||||||
|
dir = direction.ZMINUS;
|
||||||
|
cur_x++; cur_z--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ZPLUS: /* Segment in Z+ direction */
|
||||||
|
if(!ourblks.getFlag(cur_x, cur_z+1)) { /* Right turn? */
|
||||||
|
linelist.add(new int[] { cur_x+1, cur_z+1 }); /* Finish line */
|
||||||
|
dir = direction.XMINUS; /* Change direction */
|
||||||
|
}
|
||||||
|
else if(!ourblks.getFlag(cur_x+1, cur_z+1)) { /* Straight? */
|
||||||
|
cur_z++;
|
||||||
|
}
|
||||||
|
else { /* Left turn */
|
||||||
|
linelist.add(new int[] { cur_x+1, cur_z+1 }); /* Finish line */
|
||||||
|
dir = direction.XPLUS;
|
||||||
|
cur_x++; cur_z++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case XMINUS: /* Segment in X- direction */
|
||||||
|
if(!ourblks.getFlag(cur_x-1, cur_z)) { /* Right turn? */
|
||||||
|
linelist.add(new int[] { cur_x, cur_z+1 }); /* Finish line */
|
||||||
|
dir = direction.ZMINUS; /* Change direction */
|
||||||
|
}
|
||||||
|
else if(!ourblks.getFlag(cur_x-1, cur_z+1)) { /* Straight? */
|
||||||
|
cur_x--;
|
||||||
|
}
|
||||||
|
else { /* Left turn */
|
||||||
|
linelist.add(new int[] { cur_x, cur_z+1 }); /* Finish line */
|
||||||
|
dir = direction.ZPLUS;
|
||||||
|
cur_x--; cur_z++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ZMINUS: /* Segment in Z- direction */
|
||||||
|
if(!ourblks.getFlag(cur_x, cur_z-1)) { /* Right turn? */
|
||||||
|
linelist.add(new int[] { cur_x, cur_z }); /* Finish line */
|
||||||
|
dir = direction.XPLUS; /* Change direction */
|
||||||
|
}
|
||||||
|
else if(!ourblks.getFlag(cur_x-1, cur_z-1)) { /* Straight? */
|
||||||
|
cur_z--;
|
||||||
|
}
|
||||||
|
else { /* Left turn */
|
||||||
|
linelist.add(new int[] { cur_x, cur_z }); /* Finish line */
|
||||||
|
dir = direction.XMINUS;
|
||||||
|
cur_x--; cur_z--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Build information for specific area */
|
||||||
|
String polyid = factname + "__" + world + "__" + poly_index;
|
||||||
|
int sz = linelist.size();
|
||||||
|
x = new double[sz];
|
||||||
|
z = new double[sz];
|
||||||
|
for(int i = 0; i < sz; i++) {
|
||||||
|
int[] line = linelist.get(i);
|
||||||
|
x[i] = (double)line[0] * (double)blocksize;
|
||||||
|
z[i] = (double)line[1] * (double)blocksize;
|
||||||
|
}
|
||||||
|
/* Find existing one */
|
||||||
|
AreaMarker m = resareas.remove(polyid); /* Existing area? */
|
||||||
|
if(m == null) {
|
||||||
|
m = set.createAreaMarker(polyid, factname, false, world, x, z, false);
|
||||||
|
if(m == null) {
|
||||||
|
info("error adding area marker " + polyid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m.setCornerLocations(x, z); /* Replace corner locations */
|
||||||
|
m.setLabel(factname); /* Update label */
|
||||||
|
}
|
||||||
|
m.setDescription(desc); /* Set popup */
|
||||||
|
|
||||||
|
/* Set line and fill properties */
|
||||||
|
addStyle(factname, m);
|
||||||
|
|
||||||
|
/* Add to map */
|
||||||
|
newmap.put(polyid, m);
|
||||||
|
poly_index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update Factions information */
|
||||||
|
private void updateFactions() {
|
||||||
|
Map<String,AreaMarker> newmap = new HashMap<String,AreaMarker>(); /* Build new map */
|
||||||
|
Map<String,Marker> newmark = new HashMap<String,Marker>(); /* Build new map */
|
||||||
|
|
||||||
|
/* Get board in save format - not good, but best option for traversing the data
|
||||||
|
* Map by world, with Map by coordinate pair ("x,z") with value of faction ID */
|
||||||
|
Map<String, Map<String, String>> mapdata = Board.dumpAsSaveFormat();
|
||||||
|
/* Parse into faction centric mapping, split by world */
|
||||||
|
Map<String, FactionBlocks> blocks_by_faction = new HashMap<String, FactionBlocks>();
|
||||||
|
for(Map.Entry<String, Map<String,String>> me : mapdata.entrySet()) {
|
||||||
|
String world = me.getKey();
|
||||||
|
for(Map.Entry<String,String> be : me.getValue().entrySet()) {
|
||||||
|
String coord = be.getKey();
|
||||||
|
String fact = be.getValue();
|
||||||
|
info("world=" + world + ", fact=" + fact + ", coord=" + coord);
|
||||||
|
|
||||||
|
FactionBlocks factblocks = blocks_by_faction.get(fact); /* Look up faction */
|
||||||
|
if(factblocks == null) { /* Create faction block if first time */
|
||||||
|
factblocks = new FactionBlocks();
|
||||||
|
blocks_by_faction.put(fact, factblocks);
|
||||||
|
}
|
||||||
|
/* Get block set for given world */
|
||||||
|
LinkedList<FactionBlock> blocks = factblocks.blocks.get(world);
|
||||||
|
if(blocks == null) {
|
||||||
|
blocks = new LinkedList<FactionBlock>();
|
||||||
|
factblocks.blocks.put(world, blocks);
|
||||||
|
}
|
||||||
|
/* Parse coords */
|
||||||
|
String[] split = coord.split(",");
|
||||||
|
if(split.length == 2) {
|
||||||
|
try {
|
||||||
|
FactionBlock fb = new FactionBlock();
|
||||||
|
fb.x = Integer.valueOf(split[0]);
|
||||||
|
fb.z = Integer.valueOf(split[1]);
|
||||||
|
blocks.add(fb); /* Add to list */
|
||||||
|
} catch (NumberFormatException nfx) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Loop through factions */
|
||||||
|
Collection<Faction> facts = factapi.get();
|
||||||
|
for(Faction fact : facts) {
|
||||||
|
String factname = ChatColor.stripColor(fact.getTag());
|
||||||
|
info("id=" + fact.getId() + ", factname=" + factname);
|
||||||
|
|
||||||
|
FactionBlocks factblocks = blocks_by_faction.get(fact.getId());
|
||||||
|
if(factblocks == null) continue;
|
||||||
|
/* Loop through each world that faction has blocks on */
|
||||||
|
for(Map.Entry<String, LinkedList<FactionBlock>> worldblocks : factblocks.blocks.entrySet()) {
|
||||||
|
handleFactionOnWorld(factname, fact, worldblocks.getKey(), worldblocks.getValue(), newmap, newmark);
|
||||||
|
}
|
||||||
|
factblocks.blocks.clear();
|
||||||
|
|
||||||
|
/* Now, add marker for home location */
|
||||||
|
Location homeloc = fact.getHome();
|
||||||
|
if(homeloc != null) {
|
||||||
|
String markid = factname + "__home";
|
||||||
|
MarkerIcon ico = getMarkerIcon(factname, fact);
|
||||||
|
if(ico != null) {
|
||||||
|
Marker home = resmark.remove(markid);
|
||||||
|
if(home == null) {
|
||||||
|
home = set.createMarker(markid, factname, homeloc.getWorld().getName(),
|
||||||
|
homeloc.getX(), homeloc.getY(), homeloc.getZ(), ico, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
home.setLocation(homeloc.getWorld().getName(), homeloc.getX(), homeloc.getY(), homeloc.getZ());
|
||||||
|
home.setLabel(factname); /* Update label */
|
||||||
|
home.setMarkerIcon(ico);
|
||||||
|
}
|
||||||
|
home.setDescription(formatInfoWindow(fact)); /* Set popup */
|
||||||
|
newmark.put(markid, home);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
blocks_by_faction.clear();
|
||||||
|
|
||||||
|
/* Now, review old map - anything left is gone */
|
||||||
|
for(AreaMarker oldm : resareas.values()) {
|
||||||
|
oldm.deleteMarker();
|
||||||
|
}
|
||||||
|
for(Marker oldm : resmark.values()) {
|
||||||
|
oldm.deleteMarker();
|
||||||
|
}
|
||||||
|
/* And replace with new map */
|
||||||
|
resareas = newmap;
|
||||||
|
resmark = newmark;
|
||||||
|
|
||||||
|
getServer().getScheduler().scheduleSyncDelayedTask(this, new FactionsUpdate(), updperiod);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class OurServerListener extends ServerListener {
|
||||||
|
@Override
|
||||||
|
public void onPluginEnable(PluginEnableEvent event) {
|
||||||
|
Plugin p = event.getPlugin();
|
||||||
|
String name = p.getDescription().getName();
|
||||||
|
if(name.equals("dynmap") || name.equals("Factions")) {
|
||||||
|
if(dynmap.isEnabled() && factions.isEnabled())
|
||||||
|
activate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEnable() {
|
||||||
|
info("initializing");
|
||||||
|
PluginManager pm = getServer().getPluginManager();
|
||||||
|
/* Get dynmap */
|
||||||
|
dynmap = pm.getPlugin("dynmap");
|
||||||
|
if(dynmap == null) {
|
||||||
|
severe("Cannot find dynmap!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
api = (DynmapAPI)dynmap; /* Get API */
|
||||||
|
/* Get Factions */
|
||||||
|
Plugin p = pm.getPlugin("Factions");
|
||||||
|
if(p == null) {
|
||||||
|
severe("Cannot find Factions!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
factions = p;
|
||||||
|
|
||||||
|
/* If both enabled, activate */
|
||||||
|
if(dynmap.isEnabled() && factions.isEnabled())
|
||||||
|
activate();
|
||||||
|
else
|
||||||
|
getServer().getPluginManager().registerEvent(Type.PLUGIN_ENABLE, new OurServerListener(), Priority.Monitor, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void activate() {
|
||||||
|
markerapi = api.getMarkerAPI();
|
||||||
|
if(markerapi == null) {
|
||||||
|
severe("Error loading dynmap marker API!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* Connect to factions API */
|
||||||
|
factapi = Factions.i;
|
||||||
|
|
||||||
|
blocksize = 16; /* Fixed at 16 */
|
||||||
|
|
||||||
|
/* 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("factions.markerset", cfg.getString("layer.name", "Factions"), 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) {
|
||||||
|
info("id=" + id + " style added");
|
||||||
|
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 = (per*20);
|
||||||
|
stop = false;
|
||||||
|
|
||||||
|
getServer().getScheduler().scheduleSyncDelayedTask(this, new FactionsUpdate(), 40); /* First time is 2 seconds */
|
||||||
|
|
||||||
|
info("version " + this.getDescription().getVersion() + " is activated");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
if(set != null) {
|
||||||
|
set.deleteMarkerSet();
|
||||||
|
set = null;
|
||||||
|
}
|
||||||
|
resareas.clear();
|
||||||
|
stop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
67
src/main/java/org/dynmap/factions/TileFlags.java
Normal file
67
src/main/java/org/dynmap/factions/TileFlags.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package org.dynmap.factions;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scalable flags primitive - used for keeping track of potentially huge number of tiles
|
||||||
|
*
|
||||||
|
* Represents a flag for each tile, with 2D coordinates based on 0,0 origin. Flags are grouped
|
||||||
|
* 64 x 64, represented by an array of 64 longs. Each set is stored in a hashmap, keyed by a long
|
||||||
|
* computed by ((x/64)<<32)+(y/64).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class TileFlags {
|
||||||
|
private HashMap<Long, long[]> chunkmap = new HashMap<Long, long[]>();
|
||||||
|
private long last_key = Long.MIN_VALUE;
|
||||||
|
private long[] last_row;
|
||||||
|
|
||||||
|
public TileFlags() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getFlag(int x, int y) {
|
||||||
|
long k = (((long)(x >> 6)) << 32) | (0xFFFFFFFFL & (long)(y >> 6));
|
||||||
|
long[] row;
|
||||||
|
if(k == last_key) {
|
||||||
|
row = last_row;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
row = chunkmap.get(k);
|
||||||
|
last_key = k;
|
||||||
|
last_row = row;
|
||||||
|
}
|
||||||
|
if(row == null)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return (row[y & 0x3F] & (1L << (x & 0x3F))) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFlag(int x, int y, boolean f) {
|
||||||
|
long k = (((long)(x >> 6)) << 32) | (0xFFFFFFFFL & (long)(y >> 6));
|
||||||
|
long[] row;
|
||||||
|
if(k == last_key) {
|
||||||
|
row = last_row;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
row = chunkmap.get(k);
|
||||||
|
last_key = k;
|
||||||
|
last_row = row;
|
||||||
|
}
|
||||||
|
if(f) {
|
||||||
|
if(row == null) {
|
||||||
|
row = new long[64];
|
||||||
|
chunkmap.put(k, row);
|
||||||
|
last_row = row;
|
||||||
|
}
|
||||||
|
row[y & 0x3F] |= (1L << (x & 0x3F));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(row != null)
|
||||||
|
row[y & 0x3F] &= ~(1L << (x & 0x3F));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void clear() {
|
||||||
|
chunkmap.clear();
|
||||||
|
last_row = null;
|
||||||
|
last_key = Long.MIN_VALUE;
|
||||||
|
}
|
||||||
|
}
|
42
src/main/resources/config.yml
Normal file
42
src/main/resources/config.yml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Dynmap-Factions configuration
|
||||||
|
#
|
||||||
|
update:
|
||||||
|
# Seconds between checks for Factions updates
|
||||||
|
period: 300
|
||||||
|
|
||||||
|
layer:
|
||||||
|
name: "Factions"
|
||||||
|
# Make mobs layer hidden by default
|
||||||
|
hidebydefault: false
|
||||||
|
# ordering priority in layer menu (low goes before high - default is 0)
|
||||||
|
layerprio: 2
|
||||||
|
|
||||||
|
# Format for popup - substitute values for macros
|
||||||
|
infowindow: '<div class="infowindow"><span style="font-size:120%;">%regionname%</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
|
||||||
|
homeicon: "redflag"
|
||||||
|
|
||||||
|
# Optional setting to limit which regions to show, by name - if commented out, all regions are shown
|
||||||
|
visibleregions:
|
||||||
|
# - faction1
|
||||||
|
# - faction2
|
||||||
|
|
||||||
|
# Optional setting to hide specific regions, by name
|
||||||
|
hiddenregions:
|
||||||
|
# - hiddenfaction
|
||||||
|
# - secretsite
|
||||||
|
|
||||||
|
# Optional per-region overrides for regionstyle (any defined replace those in regionstyle)
|
||||||
|
custstyle:
|
||||||
|
SafeZone:
|
||||||
|
strokeColor: "#0000FF"
|
||||||
|
fillColor: "#0000FF"
|
||||||
|
WarZone:
|
||||||
|
strokeColor: "#404040"
|
||||||
|
fillColor: "#404040"
|
6
src/main/resources/plugin.yml
Normal file
6
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
name: Dynmap-Factions
|
||||||
|
main: org.dynmap.factions.DynmapFactionsPlugin
|
||||||
|
version: "${project.version}"
|
||||||
|
author: mikeprimm
|
||||||
|
softdepend: [dynmap,Factions]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user