Initial. perhaps broken update attempt
This commit is contained in:
parent
6fb1174adf
commit
ef3cf02a23
2
.gitignore
vendored
2
.gitignore
vendored
@ -23,3 +23,5 @@
|
||||
|
||||
# Mac filesystem dust
|
||||
/.DS_Store
|
||||
|
||||
*.iml
|
Binary file not shown.
Binary file not shown.
51
pom.xml
51
pom.xml
@ -1,8 +1,9 @@
|
||||
<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">
|
||||
<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.91</version>
|
||||
<version>0.92</version>
|
||||
<properties>
|
||||
<timestamp>${maven.build.timestamp}</timestamp>
|
||||
<maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
|
||||
@ -34,57 +35,49 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<releases>
|
||||
</releases>
|
||||
<snapshots>
|
||||
</snapshots>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/repositories/releases/</url>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<releases>
|
||||
</releases>
|
||||
<snapshots>
|
||||
</snapshots>
|
||||
<id>dynmap-repo</id>
|
||||
<url>http://repo.mikeprimm.com/</url>
|
||||
<id>dynmap</id>
|
||||
<url>https://repo.mikeprimm.com/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.dynmap</groupId>
|
||||
<groupId>us.dynmap</groupId>
|
||||
<artifactId>dynmap-api</artifactId>
|
||||
<version>1.9</version>
|
||||
<version>3.6-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.7.10-R0.1-SNAPSHOT</version>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.20.6-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.massivecraft</groupId>
|
||||
<artifactId>Factions</artifactId>
|
||||
<version>2.7.1</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/Factions-2.7.1.jar</systemPath>
|
||||
<version>3.3.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.massivecraft</groupId>
|
||||
<groupId>com.massivecraft.massivecore</groupId>
|
||||
<artifactId>MassiveCore</artifactId>
|
||||
<version>2.7.1</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/MassiveCore-2.7.1.jar</systemPath>
|
||||
<version>3.3.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,16 +0,0 @@
|
||||
<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>
|
51
src/main/java/org/dynmap/factions/AreaStyle.java
Normal file
51
src/main/java/org/dynmap/factions/AreaStyle.java
Normal file
@ -0,0 +1,51 @@
|
||||
package org.dynmap.factions;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.dynmap.markers.MarkerIcon;
|
||||
|
||||
class AreaStyle {
|
||||
|
||||
final String strokecolor;
|
||||
final double strokeopacity;
|
||||
final int strokeweight;
|
||||
final String fillcolor;
|
||||
final double fillopacity;
|
||||
final String homemarker;
|
||||
MarkerIcon homeicon;
|
||||
final boolean boost;
|
||||
|
||||
AreaStyle(DynmapFactionsPlugin dynmapFactionsPlugin, 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 = dynmapFactionsPlugin.markerapi.getMarkerIcon(homemarker);
|
||||
if (homeicon == null) {
|
||||
DynmapFactionsPlugin.severe("Invalid homeicon: " + homemarker);
|
||||
homeicon = dynmapFactionsPlugin.markerapi.getMarkerIcon("blueicon");
|
||||
}
|
||||
}
|
||||
boost = cfg.getBoolean(path + ".boost", def.boost);
|
||||
}
|
||||
|
||||
AreaStyle(DynmapFactionsPlugin dynmapFactionsPlugin, 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 = dynmapFactionsPlugin.markerapi.getMarkerIcon(homemarker);
|
||||
if (homeicon == null) {
|
||||
DynmapFactionsPlugin.severe("Invalid homeicon: " + homemarker);
|
||||
homeicon = dynmapFactionsPlugin.markerapi.getMarkerIcon("blueicon");
|
||||
}
|
||||
}
|
||||
boost = cfg.getBoolean(path + ".boost", false);
|
||||
}
|
||||
|
||||
}
|
10
src/main/java/org/dynmap/factions/Direction.java
Normal file
10
src/main/java/org/dynmap/factions/Direction.java
Normal file
@ -0,0 +1,10 @@
|
||||
package org.dynmap.factions;
|
||||
|
||||
public enum Direction {
|
||||
|
||||
XPLUS,
|
||||
ZPLUS,
|
||||
XMINUS,
|
||||
ZMINUS
|
||||
|
||||
}
|
@ -1,5 +1,29 @@
|
||||
package org.dynmap.factions;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.MFlag;
|
||||
import com.massivecraft.factions.entity.MFlagColl;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.Warp;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.EntityInternalMap;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
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 org.dynmap.markers.PlayerSet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
@ -13,40 +37,8 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
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 org.dynmap.markers.PlayerSet;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.MFlag;
|
||||
import com.massivecraft.factions.entity.MFlagColl;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.event.EventFactionsChunksChange;
|
||||
import com.massivecraft.factions.event.EventFactionsCreate;
|
||||
import com.massivecraft.factions.event.EventFactionsDisband;
|
||||
import com.massivecraft.factions.event.EventFactionsHomeChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||
import com.massivecraft.factions.event.EventFactionsNameChange;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
|
||||
private static Logger log;
|
||||
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;
|
||||
@ -58,7 +50,6 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
|
||||
int blocksize;
|
||||
|
||||
FileConfiguration cfg;
|
||||
MarkerSet set;
|
||||
long updperiod;
|
||||
boolean use3d;
|
||||
@ -68,112 +59,35 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
Set<String> visible;
|
||||
Set<String> hidden;
|
||||
boolean stop;
|
||||
static DynmapFactionsPlugin instance;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
log = this.getLogger();
|
||||
}
|
||||
|
||||
private class AreaStyle {
|
||||
String strokecolor;
|
||||
double strokeopacity;
|
||||
int strokeweight;
|
||||
String fillcolor;
|
||||
double fillopacity;
|
||||
String homemarker;
|
||||
MarkerIcon homeicon;
|
||||
boolean boost;
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
boost = cfg.getBoolean(path+".boost", def.boost);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
boost = cfg.getBoolean(path+".boost", false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void info(String msg) {
|
||||
log.log(Level.INFO, msg);
|
||||
}
|
||||
|
||||
public static void severe(String msg) {
|
||||
log.log(Level.SEVERE, msg);
|
||||
}
|
||||
|
||||
private class FactionsUpdate implements Runnable {
|
||||
public boolean runonce;
|
||||
public void run() {
|
||||
if(!stop) {
|
||||
updateFactions();
|
||||
if(!runonce) {
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(DynmapFactionsPlugin.this, this, updperiod);
|
||||
}
|
||||
else if(pending == this) {
|
||||
pending = null;
|
||||
}
|
||||
}
|
||||
void requestUpdatePlayerSet(String factid) {
|
||||
if (playersets) {
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(this, new PlayerSetUpdate(this, factid));
|
||||
}
|
||||
}
|
||||
|
||||
private class PlayerSetUpdate implements Runnable {
|
||||
public String faction;
|
||||
public PlayerSetUpdate(String fid) {
|
||||
faction = fid;
|
||||
}
|
||||
public void run() {
|
||||
if(!stop)
|
||||
updatePlayerSet(faction);
|
||||
}
|
||||
}
|
||||
FactionsUpdate pending = null;
|
||||
|
||||
private void requestUpdatePlayerSet(String factid) {
|
||||
if(playersets)
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(this, new PlayerSetUpdate(factid));
|
||||
}
|
||||
|
||||
private FactionsUpdate pending = null;
|
||||
|
||||
private void requestUpdateFactions() {
|
||||
if(pending == null) {
|
||||
FactionsUpdate upd = new FactionsUpdate();
|
||||
upd.runonce = true;
|
||||
pending = upd;
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(this, upd, 20);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePlayerSet(String factid) {
|
||||
void updatePlayerSet(String factid) {
|
||||
/* If Wilderness or other unassociated factions (guid-style ID), skip */
|
||||
if (factid.indexOf('-') >= 0) {
|
||||
return;
|
||||
}
|
||||
Set<String> plids = new HashSet<String>();
|
||||
Set<String> plids = new HashSet<>();
|
||||
FactionColl fc = FactionColl.get();
|
||||
|
||||
Faction f = fc.getByName(factid); /* Get faction */
|
||||
@ -190,16 +104,16 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
set = markerapi.createPlayerSet(setid, true, plids, false);
|
||||
info("Added player visibility set '" + setid + "' for faction " + factid);
|
||||
}
|
||||
else if(f != null) {
|
||||
|
||||
if (f != null) {
|
||||
set.setPlayers(plids);
|
||||
}
|
||||
else {
|
||||
} else if (set != null) {
|
||||
set.deleteSet();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, AreaMarker> resareas = new HashMap<String, AreaMarker>();
|
||||
private Map<String, Marker> resmark = new HashMap<String, Marker>();
|
||||
private Map<String, AreaMarker> resareas = new HashMap<>();
|
||||
private Map<String, Marker> resmark = new HashMap<>();
|
||||
|
||||
private String formatInfoWindow(Faction fact) {
|
||||
String v = "<div class=\"regioninfo\">" + infowindow + "</div>";
|
||||
@ -207,33 +121,34 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
v = v.replace("%description%", ChatColor.stripColor(fact.getDescription()));
|
||||
MPlayer adm = fact.getLeader();
|
||||
v = v.replace("%playerowners%", (adm != null) ? adm.getName() : "");
|
||||
String res = "";
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (MPlayer r : fact.getMPlayers()) {
|
||||
if(res.length()>0) res += ", ";
|
||||
res += r.getName();
|
||||
if (!res.isEmpty()) {
|
||||
res.append(", ");
|
||||
}
|
||||
v = v.replace("%playermembers%", res);
|
||||
res.append(r.getName());
|
||||
}
|
||||
v = v.replace("%playermembers%", res.toString());
|
||||
|
||||
v = v.replace("%nation%", ChatColor.stripColor(fact.getName()));
|
||||
/* Build flags */
|
||||
String flgs = "";
|
||||
StringBuilder flgs = new StringBuilder();
|
||||
for (MFlag ff : MFlagColl.get().getAll()) {
|
||||
flgs += "<br/>" + ff.getName() + ": " + fact.getFlag(ff);
|
||||
flgs.append("<br/>").append(ff.getName()).append(": ").append(fact.getFlag(ff));
|
||||
v = v.replace("%flag." + ff.getName() + "%", fact.getFlag(ff) ? "true" : "false");
|
||||
}
|
||||
v = v.replace("%flags%", flgs);
|
||||
v = v.replace("%flags%", flgs.toString());
|
||||
return v;
|
||||
}
|
||||
|
||||
private boolean isVisible(String id, String worldname) {
|
||||
if((visible != null) && (visible.size() > 0)) {
|
||||
if((visible.contains(id) == false) && (visible.contains("world:" + worldname) == false)) {
|
||||
if ((visible != null) && (!visible.isEmpty())) {
|
||||
if ((!visible.contains(id)) && (!visible.contains("world:" + worldname))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if((hidden != null) && (hidden.size() > 0)) {
|
||||
if(hidden.contains(id) || hidden.contains("world:" + worldname))
|
||||
return false;
|
||||
if ((hidden != null) && (!hidden.isEmpty())) {
|
||||
return !hidden.contains(id) && !hidden.contains("world:" + worldname);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -248,7 +163,7 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
try {
|
||||
sc = Integer.parseInt(as.strokecolor.substring(1), 16);
|
||||
fc = Integer.parseInt(as.fillcolor.substring(1), 16);
|
||||
} catch (NumberFormatException nfx) {
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
m.setLineStyle(as.strokeweight, as.strokeopacity, sc);
|
||||
m.setFillStyle(as.fillopacity, fc);
|
||||
@ -263,17 +178,15 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
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;
|
||||
ArrayDeque<int[]> stack = new ArrayDeque<int[]>();
|
||||
ArrayDeque<int[]> stack = new ArrayDeque<>();
|
||||
stack.push(new int[]{x, y});
|
||||
|
||||
while(stack.isEmpty() == false) {
|
||||
while (!stack.isEmpty()) {
|
||||
int[] nxt = stack.pop();
|
||||
x = nxt[0];
|
||||
y = nxt[1];
|
||||
@ -281,31 +194,27 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
src.setFlag(x, y, false); /* Clear source */
|
||||
dest.setFlag(x, y, true); /* Set in destination */
|
||||
cnt++;
|
||||
if(src.getFlag(x+1, y))
|
||||
if (src.getFlag(x + 1, y)) {
|
||||
stack.push(new int[]{x + 1, y});
|
||||
if(src.getFlag(x-1, y))
|
||||
}
|
||||
if (src.getFlag(x - 1, y)) {
|
||||
stack.push(new int[]{x - 1, y});
|
||||
if(src.getFlag(x, y+1))
|
||||
}
|
||||
if (src.getFlag(x, y + 1)) {
|
||||
stack.push(new int[]{x, y + 1});
|
||||
if(src.getFlag(x, y-1))
|
||||
}
|
||||
if (src.getFlag(x, y - 1)) {
|
||||
stack.push(new int[]{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;
|
||||
double[] x;
|
||||
double[] z;
|
||||
int poly_index = 0; /* Index of polygon for given faction */
|
||||
|
||||
/* Build popup */
|
||||
@ -313,13 +222,14 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
|
||||
/* Handle areas */
|
||||
if (isVisible(factname, world)) {
|
||||
if(blocks.isEmpty())
|
||||
if (blocks.isEmpty()) {
|
||||
return;
|
||||
LinkedList<FactionBlock> nodevals = new LinkedList<FactionBlock>();
|
||||
}
|
||||
LinkedList<FactionBlock> nodevals = new LinkedList<>();
|
||||
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 */
|
||||
curblks.setFlag(b.x(), b.z(), true); /* Set flag for block */
|
||||
nodevals.addLast(b);
|
||||
}
|
||||
/* Loop through until we don't find more areas */
|
||||
@ -330,97 +240,93 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
int minx = Integer.MAX_VALUE;
|
||||
int minz = Integer.MAX_VALUE;
|
||||
for (FactionBlock node : nodevals) {
|
||||
int nodex = node.x;
|
||||
int nodez = node.z;
|
||||
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>();
|
||||
ournodes = new LinkedList<>();
|
||||
floodFillTarget(curblks, ourblks, nodex, nodez); /* Copy shape */
|
||||
ournodes.add(node); /* Add it to our node list */
|
||||
minx = nodex; minz = nodez;
|
||||
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)) {
|
||||
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<>();
|
||||
}
|
||||
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)) {
|
||||
Direction dir = Direction.XPLUS;
|
||||
ArrayList<int[]> linelist = new ArrayList<>();
|
||||
linelist.add(new int[]{minx, minz}); // Add start point
|
||||
while ((cur_x != minx) || (cur_z != minz) || (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? */
|
||||
dir = Direction.ZPLUS; /* Change direction */
|
||||
} else if (!ourblks.getFlag(cur_x + 1, cur_z - 1)) { /* Straight? */
|
||||
cur_x++;
|
||||
}
|
||||
else { /* Left turn */
|
||||
} else { /* Left turn */
|
||||
linelist.add(new int[]{cur_x + 1, cur_z}); /* Finish line */
|
||||
dir = direction.ZMINUS;
|
||||
cur_x++; cur_z--;
|
||||
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? */
|
||||
dir = Direction.XMINUS; /* Change direction */
|
||||
} else if (!ourblks.getFlag(cur_x + 1, cur_z + 1)) { /* Straight? */
|
||||
cur_z++;
|
||||
}
|
||||
else { /* Left turn */
|
||||
} else { /* Left turn */
|
||||
linelist.add(new int[]{cur_x + 1, cur_z + 1}); /* Finish line */
|
||||
dir = direction.XPLUS;
|
||||
cur_x++; cur_z++;
|
||||
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? */
|
||||
dir = Direction.ZMINUS; /* Change direction */
|
||||
} else if (!ourblks.getFlag(cur_x - 1, cur_z + 1)) { /* Straight? */
|
||||
cur_x--;
|
||||
}
|
||||
else { /* Left turn */
|
||||
} else { /* Left turn */
|
||||
linelist.add(new int[]{cur_x, cur_z + 1}); /* Finish line */
|
||||
dir = direction.ZPLUS;
|
||||
cur_x--; cur_z++;
|
||||
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? */
|
||||
dir = Direction.XPLUS; /* Change direction */
|
||||
} else if (!ourblks.getFlag(cur_x - 1, cur_z - 1)) { /* Straight? */
|
||||
cur_z--;
|
||||
}
|
||||
else { /* Left turn */
|
||||
} else { /* Left turn */
|
||||
linelist.add(new int[]{cur_x, cur_z}); /* Finish line */
|
||||
dir = direction.XMINUS;
|
||||
cur_x--; cur_z--;
|
||||
dir = Direction.XMINUS;
|
||||
cur_x--;
|
||||
cur_z--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -443,8 +349,7 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
info("error adding area marker " + polyid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
m.setCornerLocations(x, z); /* Replace corner locations */
|
||||
m.setLabel(factname); /* Update label */
|
||||
}
|
||||
@ -462,12 +367,12 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
void updateFactions() {
|
||||
Map<String, AreaMarker> newmap = new HashMap<>(); /* Build new map */
|
||||
Map<String, Marker> newmark = new HashMap<>(); /* Build new map */
|
||||
|
||||
/* Parse into faction centric mapping, split by world */
|
||||
Map<String, FactionBlocks> blocks_by_faction = new HashMap<String, FactionBlocks>();
|
||||
Map<String, FactionBlocks> blocks_by_faction = new HashMap<>();
|
||||
|
||||
FactionColl fc = FactionColl.get();
|
||||
Collection<Faction> facts = fc.getAll();
|
||||
@ -484,14 +389,8 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
String world = cc.getWorld();
|
||||
|
||||
/* 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);
|
||||
}
|
||||
FactionBlock fb = new FactionBlock();
|
||||
fb.x = cc.getChunkX();
|
||||
fb.z = cc.getChunkZ();
|
||||
LinkedList<FactionBlock> blocks = factblocks.blocks.computeIfAbsent(world, k -> new LinkedList<>());
|
||||
FactionBlock fb = new FactionBlock(cc.getChunkX(), cc.getChunkZ());
|
||||
blocks.add(fb); /* Add to list */
|
||||
}
|
||||
}
|
||||
@ -500,7 +399,9 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
String factname = ChatColor.stripColor(fact.getName());
|
||||
String fid = fc.getUniverse() + "_" + fact.getId();
|
||||
FactionBlocks factblocks = blocks_by_faction.get(fid); /* Look up faction */
|
||||
if (factblocks == null) continue;
|
||||
if (factblocks == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Loop through each world that faction has blocks on */
|
||||
for (Map.Entry<String, LinkedList<FactionBlock>> worldblocks : factblocks.blocks.entrySet()) {
|
||||
@ -509,25 +410,34 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
factblocks.blocks.clear();
|
||||
|
||||
/* Now, add marker for home location */
|
||||
PS homeloc = fact.getHome();
|
||||
EntityInternalMap<Warp> warps = fact.getWarps();
|
||||
Warp home = null;
|
||||
for (String warp : warps.keySet()) {
|
||||
if (warp.equalsIgnoreCase("home")) {
|
||||
home = warps.get(warp);
|
||||
}
|
||||
}
|
||||
if (home == null) {
|
||||
continue;
|
||||
}
|
||||
PS homeloc = home.getLocation();
|
||||
if (homeloc != null) {
|
||||
String markid = fc.getUniverse() + "_" + factname + "__home";
|
||||
MarkerIcon ico = getMarkerIcon(factname, fact);
|
||||
if (ico != null) {
|
||||
Marker home = resmark.remove(markid);
|
||||
Marker homeMarker = resmark.remove(markid);
|
||||
String lbl = factname + " [home]";
|
||||
if(home == null) {
|
||||
home = set.createMarker(markid, lbl, homeloc.getWorld(),
|
||||
if (homeMarker == null) {
|
||||
homeMarker = set.createMarker(markid, lbl, homeloc.getWorld(),
|
||||
homeloc.getLocationX(), homeloc.getLocationY(), homeloc.getLocationZ(), ico, false);
|
||||
} else {
|
||||
homeMarker.setLocation(homeloc.getWorld(), homeloc.getLocationX(), homeloc.getLocationY(), homeloc.getLocationZ());
|
||||
homeMarker.setLabel(lbl); /* Update label */
|
||||
homeMarker.setMarkerIcon(ico);
|
||||
}
|
||||
else {
|
||||
home.setLocation(homeloc.getWorld(), homeloc.getLocationX(), homeloc.getLocationY(), homeloc.getLocationZ());
|
||||
home.setLabel(lbl); /* Update label */
|
||||
home.setMarkerIcon(ico);
|
||||
}
|
||||
if (home != null) {
|
||||
home.setDescription(formatInfoWindow(fact)); /* Set popup */
|
||||
newmark.put(markid, home);
|
||||
if (homeMarker != null) {
|
||||
homeMarker.setDescription(formatInfoWindow(fact)); /* Set popup */
|
||||
newmark.put(markid, homeMarker);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -559,64 +469,8 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private class OurServerListener implements Listener {
|
||||
@EventHandler
|
||||
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();
|
||||
}
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onFPlayerJoin(EventFactionsMembershipChange event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
if(playersets) {
|
||||
Faction f = event.getNewFaction();
|
||||
requestUpdatePlayerSet(f.getId());
|
||||
}
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onFactionCreate(EventFactionsCreate event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
if(playersets)
|
||||
requestUpdatePlayerSet(event.getFactionId());
|
||||
requestUpdateFactions();
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onFactionDisband(EventFactionsDisband event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
if(playersets) {
|
||||
Faction f = event.getFaction();
|
||||
requestUpdatePlayerSet(f.getId());
|
||||
}
|
||||
requestUpdateFactions();
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onFactionRename(EventFactionsNameChange event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
requestUpdateFactions();
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onFactionRename(EventFactionsHomeChange event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
requestUpdateFactions();
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onFactionRename(EventFactionsChunksChange event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
requestUpdateFactions();
|
||||
}
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
info("initializing");
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
/* Get dynmap */
|
||||
@ -635,19 +489,20 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
factions = p;
|
||||
|
||||
/* If both enabled, activate */
|
||||
if(dynmap.isEnabled() && factions.isEnabled())
|
||||
if (dynmap.isEnabled() && factions.isEnabled()) {
|
||||
activate();
|
||||
}
|
||||
|
||||
try {
|
||||
MetricsLite ml = new MetricsLite(this);
|
||||
ml.start();
|
||||
} catch (IOException iox) {
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean reload = false;
|
||||
|
||||
private void activate() {
|
||||
void activate() {
|
||||
markerapi = api.getMarkerAPI();
|
||||
if (markerapi == null) {
|
||||
severe("Error loading dynmap marker API!");
|
||||
@ -665,8 +520,7 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
set.deleteMarkerSet();
|
||||
set = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
reload = true;
|
||||
}
|
||||
FileConfiguration cfg = getConfig();
|
||||
@ -675,10 +529,11 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
|
||||
/* Now, add marker set for mobs (make it transient) */
|
||||
set = markerapi.getMarkerSet("factions.markerset");
|
||||
if(set == null)
|
||||
if (set == null) {
|
||||
set = markerapi.createMarkerSet("factions.markerset", cfg.getString("layer.name", "Factions"), null, false);
|
||||
else
|
||||
} else {
|
||||
set.setMarkerSetLabel(cfg.getString("layer.name", "Factions"));
|
||||
}
|
||||
if (set == null) {
|
||||
severe("Error creating marker set");
|
||||
return;
|
||||
@ -688,31 +543,32 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
resmark.clear();
|
||||
|
||||
int minzoom = cfg.getInt("layer.minzoom", 0);
|
||||
if(minzoom > 0)
|
||||
if (minzoom > 0) {
|
||||
set.setMinZoom(minzoom);
|
||||
}
|
||||
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>();
|
||||
defstyle = new AreaStyle(this, cfg, "regionstyle");
|
||||
cusstyle = new HashMap<>();
|
||||
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));
|
||||
cusstyle.put(id, new AreaStyle(this, cfg, "custstyle." + id, defstyle));
|
||||
}
|
||||
}
|
||||
List<String> vis = cfg.getStringList("visibleregions");
|
||||
if (vis != null) {
|
||||
visible = new HashSet<String>(vis);
|
||||
visible = new HashSet<>(vis);
|
||||
}
|
||||
List<String> hid = cfg.getStringList("hiddenregions");
|
||||
if (hid != null) {
|
||||
hidden = new HashSet<String>(hid);
|
||||
hidden = new HashSet<>(hid);
|
||||
}
|
||||
/* Chec if player sets enabled */
|
||||
playersets = cfg.getBoolean("visibility-by-faction", false);
|
||||
@ -731,12 +587,14 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
||||
|
||||
/* Set up update job - based on periond */
|
||||
int per = cfg.getInt("update.period", 300);
|
||||
if(per < 15) per = 15;
|
||||
updperiod = (per*20);
|
||||
if (per < 15) {
|
||||
per = 15;
|
||||
}
|
||||
updperiod = (per * 20L);
|
||||
stop = false;
|
||||
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(this, new FactionsUpdate(), 40); /* First time is 2 seconds */
|
||||
getServer().getPluginManager().registerEvents(new OurServerListener(), this);
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(this, new FactionsUpdate(this), 40); /* First time is 2 seconds */
|
||||
getServer().getPluginManager().registerEvents(new OurServerListener(this), this);
|
||||
|
||||
info("version " + this.getDescription().getVersion() + " is activated");
|
||||
}
|
||||
|
4
src/main/java/org/dynmap/factions/FactionBlock.java
Normal file
4
src/main/java/org/dynmap/factions/FactionBlock.java
Normal file
@ -0,0 +1,4 @@
|
||||
package org.dynmap.factions;
|
||||
|
||||
public record FactionBlock(int x, int z) {
|
||||
}
|
11
src/main/java/org/dynmap/factions/FactionBlocks.java
Normal file
11
src/main/java/org/dynmap/factions/FactionBlocks.java
Normal file
@ -0,0 +1,11 @@
|
||||
package org.dynmap.factions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
public class FactionBlocks {
|
||||
|
||||
final Map<String, LinkedList<FactionBlock>> blocks = new HashMap<>();
|
||||
|
||||
}
|
26
src/main/java/org/dynmap/factions/FactionsUpdate.java
Normal file
26
src/main/java/org/dynmap/factions/FactionsUpdate.java
Normal file
@ -0,0 +1,26 @@
|
||||
package org.dynmap.factions;
|
||||
|
||||
public class FactionsUpdate implements Runnable {
|
||||
|
||||
private final DynmapFactionsPlugin dynmapFactionsPlugin;
|
||||
public boolean runonce;
|
||||
|
||||
public FactionsUpdate(DynmapFactionsPlugin dynmapFactionsPlugin) {
|
||||
this.dynmapFactionsPlugin = dynmapFactionsPlugin;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (dynmapFactionsPlugin.stop) {
|
||||
return;
|
||||
}
|
||||
|
||||
dynmapFactionsPlugin.updateFactions();
|
||||
if (!runonce) {
|
||||
dynmapFactionsPlugin.getServer().getScheduler().scheduleSyncDelayedTask(dynmapFactionsPlugin,
|
||||
this, dynmapFactionsPlugin.updperiod);
|
||||
} else if (dynmapFactionsPlugin.pending == this) {
|
||||
dynmapFactionsPlugin.pending = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -45,6 +45,7 @@ import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -197,12 +198,7 @@ public class MetricsLite {
|
||||
try {
|
||||
// Reload the metrics file
|
||||
configuration.load(getConfigFile());
|
||||
} catch (IOException ex) {
|
||||
if (debug) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
} catch (IOException | InvalidConfigurationException ex) {
|
||||
if (debug) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
}
|
||||
@ -381,7 +377,7 @@ public class MetricsLite {
|
||||
* @param key the key value
|
||||
* @param value the value
|
||||
*/
|
||||
private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException {
|
||||
private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) {
|
||||
buffer.append('&').append(encode(key)).append('=').append(encode(value));
|
||||
}
|
||||
|
||||
@ -391,8 +387,8 @@ public class MetricsLite {
|
||||
* @param text the text to encode
|
||||
* @return the encoded text, as UTF-8
|
||||
*/
|
||||
private static String encode(final String text) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(text, "UTF-8");
|
||||
private static String encode(final String text) {
|
||||
return URLEncoder.encode(text, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
}
|
111
src/main/java/org/dynmap/factions/OurServerListener.java
Normal file
111
src/main/java/org/dynmap/factions/OurServerListener.java
Normal file
@ -0,0 +1,111 @@
|
||||
package org.dynmap.factions;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.event.EventFactionsChunksChange;
|
||||
import com.massivecraft.factions.event.EventFactionsCreate;
|
||||
import com.massivecraft.factions.event.EventFactionsDisband;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||
import com.massivecraft.factions.event.EventFactionsNameChange;
|
||||
import com.massivecraft.factions.event.EventFactionsWarpAdd;
|
||||
import com.massivecraft.factions.event.EventFactionsWarpRemove;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
class OurServerListener implements Listener {
|
||||
private final DynmapFactionsPlugin dynmapFactionsPlugin;
|
||||
|
||||
public OurServerListener(DynmapFactionsPlugin dynmapFactionsPlugin) {
|
||||
this.dynmapFactionsPlugin = dynmapFactionsPlugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
Plugin p = event.getPlugin();
|
||||
String name = p.getDescription().getName();
|
||||
if (name.equals("dynmap") || name.equals("Factions")) {
|
||||
if (dynmapFactionsPlugin.dynmap.isEnabled() && dynmapFactionsPlugin.factions.isEnabled()) {
|
||||
dynmapFactionsPlugin.activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onFPlayerJoin(EventFactionsMembershipChange event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (dynmapFactionsPlugin.playersets) {
|
||||
Faction f = event.getNewFaction();
|
||||
dynmapFactionsPlugin.requestUpdatePlayerSet(f.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onFactionCreate(EventFactionsCreate event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (dynmapFactionsPlugin.playersets) {
|
||||
dynmapFactionsPlugin.requestUpdatePlayerSet(event.getFactionId());
|
||||
}
|
||||
requestUpdateFactions();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onFactionDisband(EventFactionsDisband event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (dynmapFactionsPlugin.playersets) {
|
||||
Faction f = event.getFaction();
|
||||
dynmapFactionsPlugin.requestUpdatePlayerSet(f.getId());
|
||||
}
|
||||
requestUpdateFactions();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onFactionRename(EventFactionsNameChange event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
requestUpdateFactions();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onFactionRename(EventFactionsWarpAdd event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
requestUpdateFactions();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onFactionRename(EventFactionsWarpRemove event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
requestUpdateFactions();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onFactionRename(EventFactionsChunksChange event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
requestUpdateFactions();
|
||||
}
|
||||
|
||||
private void requestUpdateFactions() {
|
||||
if (DynmapFactionsPlugin.instance.pending == null) {
|
||||
FactionsUpdate upd = new FactionsUpdate(DynmapFactionsPlugin.instance);
|
||||
upd.runonce = true;
|
||||
DynmapFactionsPlugin.instance.pending = upd;
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(DynmapFactionsPlugin.instance, upd, 20);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
17
src/main/java/org/dynmap/factions/PlayerSetUpdate.java
Normal file
17
src/main/java/org/dynmap/factions/PlayerSetUpdate.java
Normal file
@ -0,0 +1,17 @@
|
||||
package org.dynmap.factions;
|
||||
|
||||
class PlayerSetUpdate implements Runnable {
|
||||
private final DynmapFactionsPlugin dynmapFactionsPlugin;
|
||||
public final String faction;
|
||||
|
||||
public PlayerSetUpdate(DynmapFactionsPlugin dynmapFactionsPlugin, String fid) {
|
||||
this.dynmapFactionsPlugin = dynmapFactionsPlugin;
|
||||
faction = fid;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (!dynmapFactionsPlugin.stop) {
|
||||
dynmapFactionsPlugin.updatePlayerSet(faction);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
package org.dynmap.factions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* scalable flags primitive - used for keeping track of potentially huge number of tiles
|
||||
*
|
||||
* <p>
|
||||
* 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 final Map<Long, long[]> chunkMap = new HashMap<>();
|
||||
private long last_key = Long.MAX_VALUE;
|
||||
private long[] last_row;
|
||||
|
||||
@ -23,44 +23,44 @@ public class TileFlags {
|
||||
long[] row;
|
||||
if (k == last_key) {
|
||||
row = last_row;
|
||||
}
|
||||
else {
|
||||
row = chunkmap.get(k);
|
||||
} else {
|
||||
row = chunkMap.get(k);
|
||||
last_key = k;
|
||||
last_row = row;
|
||||
}
|
||||
if(row == null)
|
||||
if (row == null) {
|
||||
return false;
|
||||
else
|
||||
} 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);
|
||||
} else {
|
||||
row = chunkMap.get(k);
|
||||
last_key = k;
|
||||
last_row = row;
|
||||
}
|
||||
if (f) {
|
||||
if (row == null) {
|
||||
row = new long[64];
|
||||
chunkmap.put(k, row);
|
||||
chunkMap.put(k, row);
|
||||
last_row = row;
|
||||
}
|
||||
row[y & 0x3F] |= (1L << (x & 0x3F));
|
||||
}
|
||||
else {
|
||||
if(row != null)
|
||||
} else {
|
||||
if (row != null) {
|
||||
row[y & 0x3F] &= ~(1L << (x & 0x3F));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
chunkmap.clear();
|
||||
chunkMap.clear();
|
||||
last_row = null;
|
||||
last_key = Long.MAX_VALUE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user