diff --git a/.gitignore b/.gitignore index 408c231..6ef25e1 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,6 @@ /manifest.mf # Mac filesystem dust -/.DS_Store \ No newline at end of file +/.DS_Store + +*.iml \ No newline at end of file diff --git a/Factions-2.7.1.jar b/Factions-2.7.1.jar deleted file mode 100644 index 053f6ca..0000000 Binary files a/Factions-2.7.1.jar and /dev/null differ diff --git a/MassiveCore-2.7.1.jar b/MassiveCore-2.7.1.jar deleted file mode 100644 index 1af8047..0000000 Binary files a/MassiveCore-2.7.1.jar and /dev/null differ diff --git a/pom.xml b/pom.xml index 42c006c..93c97ee 100644 --- a/pom.xml +++ b/pom.xml @@ -1,90 +1,83 @@ - - 4.0.0 - org.dynmap - Dynmap-Factions - 0.91 - - ${maven.build.timestamp} - yyyyMMddHHmm - UTF-8 - Dev${timestamp} - - + + 4.0.0 + org.dynmap + Dynmap-Factions + 0.92 + + ${maven.build.timestamp} + yyyyMMddHHmm + UTF-8 + Dev${timestamp} + + - - - src/main/resources - true - - *.yml - *.txt - - - - src/main/resources - false - - *.yml - *.txt - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.0.2 - - 1.6 - 1.6 - - - - - - - - - - - bukkit-repo - http://repo.bukkit.org/content/repositories/releases/ - - - - - - - dynmap-repo - http://repo.mikeprimm.com/ - - - - - - org.dynmap - dynmap-api - 1.9 - - - org.bukkit - bukkit - 1.7.10-R0.1-SNAPSHOT - - - com.massivecraft - Factions - 2.7.1 - system - ${project.basedir}/Factions-2.7.1.jar - - - com.massivecraft - MassiveCore - 2.7.1 - system - ${project.basedir}/MassiveCore-2.7.1.jar - - + + + src/main/resources + true + + *.yml + *.txt + + + + src/main/resources + false + + *.yml + *.txt + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 16 + 16 + + + + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + dynmap + https://repo.mikeprimm.com/ + + + + + + us.dynmap + dynmap-api + 3.6-SNAPSHOT + provided + + + org.spigotmc + spigot-api + 1.20.6-R0.1-SNAPSHOT + provided + + + com.massivecraft + Factions + 3.3.3 + provided + + + com.massivecraft.massivecore + MassiveCore + 3.3.3 + provided + + \ No newline at end of file diff --git a/src/main/assembly/package.xml b/src/main/assembly/package.xml deleted file mode 100644 index 2ec55c3..0000000 --- a/src/main/assembly/package.xml +++ /dev/null @@ -1,16 +0,0 @@ - - bin - false - - zip - - - - - - ${project.build.directory}/${artifactId}-${version}.jar - / - ${artifactId}.jar - - - diff --git a/src/main/java/org/dynmap/factions/AreaStyle.java b/src/main/java/org/dynmap/factions/AreaStyle.java new file mode 100644 index 0000000..080d419 --- /dev/null +++ b/src/main/java/org/dynmap/factions/AreaStyle.java @@ -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); + } + +} diff --git a/src/main/java/org/dynmap/factions/Direction.java b/src/main/java/org/dynmap/factions/Direction.java new file mode 100644 index 0000000..38e37f5 --- /dev/null +++ b/src/main/java/org/dynmap/factions/Direction.java @@ -0,0 +1,10 @@ +package org.dynmap.factions; + +public enum Direction { + + XPLUS, + ZPLUS, + XMINUS, + ZMINUS + +} diff --git a/src/main/java/org/dynmap/factions/DynmapFactionsPlugin.java b/src/main/java/org/dynmap/factions/DynmapFactionsPlugin.java index 717b820..11a96d6 100644 --- a/src/main/java/org/dynmap/factions/DynmapFactionsPlugin.java +++ b/src/main/java/org/dynmap/factions/DynmapFactionsPlugin.java @@ -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 = "
%regionname%
Flags
%flags%
"; Plugin dynmap; @@ -55,10 +47,9 @@ public class DynmapFactionsPlugin extends JavaPlugin { Plugin factions; Factions factapi; boolean playersets; - + int blocksize; - - FileConfiguration cfg; + MarkerSet set; long updperiod; boolean use3d; @@ -68,179 +59,103 @@ public class DynmapFactionsPlugin extends JavaPlugin { Set visible; Set 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); - } - } - - private void requestUpdatePlayerSet(String factid) { - if(playersets) - getServer().getScheduler().scheduleSyncDelayedTask(this, new PlayerSetUpdate(factid)); - } + FactionsUpdate pending = null; - 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) { + if (factid.indexOf('-') >= 0) { return; } - Set plids = new HashSet(); + Set plids = new HashSet<>(); FactionColl fc = FactionColl.get(); Faction f = fc.getByName(factid); /* Get faction */ - if(f != null) { + if (f != null) { List ps = f.getMPlayers(); - for(MPlayer fp : ps) { + for (MPlayer fp : ps) { plids.add(fp.getId()); } factid = f.getId(); } String setid = "factions." + factid; PlayerSet set = markerapi.getPlayerSet(setid); /* See if set exists */ - if((set == null) && (f != null)) { + if ((set == null) && (f != null)) { 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 resareas = new HashMap(); - private Map resmark = new HashMap(); - + + private Map resareas = new HashMap<>(); + private Map resmark = new HashMap<>(); + private String formatInfoWindow(Faction fact) { - String v = "
"+infowindow+"
"; + String v = "
" + infowindow + "
"; v = v.replace("%regionname%", ChatColor.stripColor(fact.getName())); v = v.replace("%description%", ChatColor.stripColor(fact.getDescription())); MPlayer adm = fact.getLeader(); - v = v.replace("%playerowners%", (adm!=null)?adm.getName():""); - String res = ""; - for(MPlayer r : fact.getMPlayers()) { - if(res.length()>0) res += ", "; - res += r.getName(); + v = v.replace("%playerowners%", (adm != null) ? adm.getName() : ""); + StringBuilder res = new StringBuilder(); + for (MPlayer r : fact.getMPlayers()) { + if (!res.isEmpty()) { + res.append(", "); + } + res.append(r.getName()); } - v = v.replace("%playermembers%", res); - + v = v.replace("%playermembers%", res.toString()); + v = v.replace("%nation%", ChatColor.stripColor(fact.getName())); /* Build flags */ - String flgs = ""; - for(MFlag ff : MFlagColl.get().getAll()) { - flgs += "
" + ff.getName() + ": " + fact.getFlag(ff); - v = v.replace("%flag." + ff.getName() + "%", fact.getFlag(ff)?"true":"false"); + StringBuilder flgs = new StringBuilder(); + for (MFlag ff : MFlagColl.get().getAll()) { + flgs.append("
").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; } - + private void addStyle(String resid, AreaMarker m) { AreaStyle as = cusstyle.get(resid); - if(as == null) { + if (as == null) { as = defstyle; } int sc = 0xFF0000; @@ -248,179 +163,170 @@ 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); m.setBoostFlag(as.boost); } - + private MarkerIcon getMarkerIcon(String factname, Faction fact) { AreaStyle as = cusstyle.get(factname); - if(as == null) { + 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; - ArrayDeque stack = new ArrayDeque(); - stack.push(new int[] { x, y }); - - while(stack.isEmpty() == false) { + ArrayDeque stack = new ArrayDeque<>(); + stack.push(new int[]{x, y}); + + while (!stack.isEmpty()) { int[] nxt = stack.pop(); x = nxt[0]; y = nxt[1]; - if(src.getFlag(x, y)) { /* Set in src */ + if (src.getFlag(x, y)) { /* Set in src */ src.setFlag(x, y, false); /* Clear source */ dest.setFlag(x, y, true); /* Set in destination */ cnt++; - if(src.getFlag(x+1, y)) - stack.push(new int[] { x+1, y }); - if(src.getFlag(x-1, y)) - stack.push(new int[] { x-1, y }); - if(src.getFlag(x, y+1)) - stack.push(new int[] { x, y+1 }); - if(src.getFlag(x, y-1)) - stack.push(new int[] { x, y-1 }); + if (src.getFlag(x + 1, y)) { + stack.push(new int[]{x + 1, y}); + } + if (src.getFlag(x - 1, y)) { + stack.push(new int[]{x - 1, y}); + } + if (src.getFlag(x, y + 1)) { + stack.push(new int[]{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> blocks = new HashMap>(); - } - + /* Handle specific faction on specific world */ private void handleFactionOnWorld(String factname, Faction fact, String world, LinkedList blocks, Map newmap, Map newmark) { - double[] x = null; - double[] z = null; + double[] x; + double[] z; int poly_index = 0; /* Index of polygon for given faction */ - + /* Build popup */ String desc = formatInfoWindow(fact); - + /* Handle areas */ - if(isVisible(factname, world)) { - if(blocks.isEmpty()) - return; - LinkedList nodevals = new LinkedList(); + if (isVisible(factname, world)) { + if (blocks.isEmpty()) { + return; + } + LinkedList 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 */ - nodevals.addLast(b); - } + /* 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) { + while (nodevals != null) { LinkedList ournodes = null; LinkedList 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; + 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)) { + if ((ourblks == null) && curblks.getFlag(nodex, nodez)) { ourblks = new TileFlags(); /* Create map for shape */ - ournodes = new LinkedList(); + 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)) { + else if ((ourblks != null) && ourblks.getFlag(nodex, nodez)) { ournodes.add(node); - if(nodex < minx) { - minx = nodex; minz = nodez; - } - else if((nodex == minx) && (nodez < minz)) { + 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(); + } else { /* Else, keep it in the list for the next polygon */ + if (newlist == null) { + newlist = new LinkedList<>(); + } newlist.add(node); } } nodevals = newlist; /* Replace list (null if no more to process) */ - if(ourblks != null) { + 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 linelist = new ArrayList(); - 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) { + Direction dir = Direction.XPLUS; + ArrayList 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? */ + 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--; + } 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? */ + 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++; - } - 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? */ + 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++; + } 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? */ + 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--; - } - else { /* Left turn */ - linelist.add(new int[] { cur_x, cur_z }); /* Finish line */ - dir = direction.XMINUS; - cur_x--; cur_z--; } break; } @@ -430,29 +336,28 @@ public class DynmapFactionsPlugin extends JavaPlugin { int sz = linelist.size(); x = new double[sz]; z = new double[sz]; - for(int i = 0; i < sz; i++) { + 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; + 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) { + if (m == null) { m = set.createAreaMarker(polyid, factname, false, world, x, z, false); - if(m == null) { + if (m == null) { info("error adding area marker " + polyid); return; } - } - else { + } 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++; @@ -460,97 +365,102 @@ public class DynmapFactionsPlugin extends JavaPlugin { } } } - + /* Update Factions information */ - private void updateFactions() { - Map newmap = new HashMap(); /* Build new map */ - Map newmark = new HashMap(); /* Build new map */ - + void updateFactions() { + Map newmap = new HashMap<>(); /* Build new map */ + Map newmark = new HashMap<>(); /* Build new map */ + /* Parse into faction centric mapping, split by world */ - Map blocks_by_faction = new HashMap(); - + Map blocks_by_faction = new HashMap<>(); + FactionColl fc = FactionColl.get(); - Collection facts = fc.getAll(); - for (Faction fact : facts) { - Set chunks = BoardColl.get().getChunks(fact); - String fid = fc.getUniverse() + "_" + fact.getId(); - FactionBlocks factblocks = blocks_by_faction.get(fid); /* Look up faction */ - if(factblocks == null) { /* Create faction block if first time */ - factblocks = new FactionBlocks(); - blocks_by_faction.put(fid, factblocks); - } + Collection facts = fc.getAll(); + for (Faction fact : facts) { + Set chunks = BoardColl.get().getChunks(fact); + String fid = fc.getUniverse() + "_" + fact.getId(); + FactionBlocks factblocks = blocks_by_faction.get(fid); /* Look up faction */ + if (factblocks == null) { /* Create faction block if first time */ + factblocks = new FactionBlocks(); + blocks_by_faction.put(fid, factblocks); + } - for (PS cc : chunks) { - String world = cc.getWorld(); + for (PS cc : chunks) { + String world = cc.getWorld(); - /* Get block set for given world */ - LinkedList blocks = factblocks.blocks.get(world); - if(blocks == null) { - blocks = new LinkedList(); - factblocks.blocks.put(world, blocks); - } - FactionBlock fb = new FactionBlock(); - fb.x = cc.getChunkX(); - fb.z = cc.getChunkZ(); - blocks.add(fb); /* Add to list */ + /* Get block set for given world */ + LinkedList blocks = factblocks.blocks.computeIfAbsent(world, k -> new LinkedList<>()); + FactionBlock fb = new FactionBlock(cc.getChunkX(), cc.getChunkZ()); + blocks.add(fb); /* Add to list */ + } + } + /* Loop through factions */ + for (Faction fact : facts) { + 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; + } + + /* Loop through each world that faction has blocks on */ + for (Map.Entry> worldblocks : factblocks.blocks.entrySet()) { + handleFactionOnWorld(factname, fact, worldblocks.getKey(), worldblocks.getValue(), newmap, newmark); + } + factblocks.blocks.clear(); + + /* Now, add marker for home location */ + EntityInternalMap warps = fact.getWarps(); + Warp home = null; + for (String warp : warps.keySet()) { + if (warp.equalsIgnoreCase("home")) { + home = warps.get(warp); } } - /* Loop through factions */ - for(Faction fact : facts) { - 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; - - /* Loop through each world that faction has blocks on */ - for(Map.Entry> worldblocks : factblocks.blocks.entrySet()) { - handleFactionOnWorld(factname, fact, worldblocks.getKey(), worldblocks.getValue(), newmap, newmark); - } - factblocks.blocks.clear(); - - /* Now, add marker for home location */ - PS homeloc = fact.getHome(); - if(homeloc != null) { - String markid = fc.getUniverse() + "_" + factname + "__home"; - MarkerIcon ico = getMarkerIcon(factname, fact); - if(ico != null) { - Marker home = resmark.remove(markid); - String lbl = factname + " [home]"; - if(home == null) { - home = set.createMarker(markid, lbl, homeloc.getWorld(), - homeloc.getLocationX(), homeloc.getLocationY(), homeloc.getLocationZ(), ico, false); - } - 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 (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 homeMarker = resmark.remove(markid); + String lbl = factname + " [home]"; + 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); + } + if (homeMarker != null) { + homeMarker.setDescription(formatInfoWindow(fact)); /* Set popup */ + newmark.put(markid, homeMarker); } } + } } blocks_by_faction.clear(); - + /* Now, review old map - anything left is gone */ - for(AreaMarker oldm : resareas.values()) { + for (AreaMarker oldm : resareas.values()) { oldm.deleteMarker(); } - for(Marker oldm : resmark.values()) { + for (Marker oldm : resmark.values()) { oldm.deleteMarker(); } /* And replace with new map */ resareas = newmap; resmark = newmark; - + } - + private void updatePlayerSets() { - if(playersets) { + if (playersets) { FactionColl fc = FactionColl.get(); - for(Faction f : fc.getAll()) { + for (Faction f : fc.getAll()) { if ((f == fc.getNone()) || (f == fc.getWarzone()) || (f == fc.getSafezone())) { continue; } @@ -558,128 +468,73 @@ 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 */ dynmap = pm.getPlugin("dynmap"); - if(dynmap == null) { + if (dynmap == null) { severe("Cannot find dynmap!"); return; } - api = (DynmapAPI)dynmap; /* Get API */ + api = (DynmapAPI) dynmap; /* Get API */ /* Get Factions */ Plugin p = pm.getPlugin("Factions"); - if(p == null) { + if (p == null) { severe("Cannot find Factions!"); return; } 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) { + if (markerapi == null) { severe("Error loading dynmap marker API!"); return; } /* Connect to factions API */ factapi = Factions.get(); - + blocksize = 16; /* Fixed at 16 */ - + /* Load configuration */ - if(reload) { + if (reload) { this.reloadConfig(); - if(set != null) { + if (set != null) { set.deleteMarkerSet(); set = null; } - } - else { + } else { reload = true; } 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.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) { + } + if (set == null) { severe("Error creating marker set"); return; } @@ -688,37 +543,38 @@ 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(); + defstyle = new AreaStyle(this, cfg, "regionstyle"); + cusstyle = new HashMap<>(); ConfigurationSection sect = cfg.getConfigurationSection("custstyle"); - if(sect != null) { + if (sect != null) { Set ids = sect.getKeys(false); - - for(String id : ids) { - cusstyle.put(id, new AreaStyle(cfg, "custstyle." + id, defstyle)); + + for (String id : ids) { + cusstyle.put(id, new AreaStyle(this, cfg, "custstyle." + id, defstyle)); } } List vis = cfg.getStringList("visibleregions"); - if(vis != null) { - visible = new HashSet(vis); + if (vis != null) { + visible = new HashSet<>(vis); } List hid = cfg.getStringList("hiddenregions"); - if(hid != null) { - hidden = new HashSet(hid); + if (hid != null) { + hidden = new HashSet<>(hid); } /* Chec if player sets enabled */ playersets = cfg.getBoolean("visibility-by-faction", false); - if(playersets) { + if (playersets) { try { - if(!api.testIfPlayerInfoProtected()) { + if (!api.testIfPlayerInfoProtected()) { playersets = false; info("Dynmap does not have player-info-protected enabled - visibility-by-faction will have no effect"); } @@ -731,18 +587,20 @@ 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"); } public void onDisable() { - if(set != null) { + if (set != null) { set.deleteMarkerSet(); set = null; } diff --git a/src/main/java/org/dynmap/factions/FactionBlock.java b/src/main/java/org/dynmap/factions/FactionBlock.java new file mode 100644 index 0000000..0d6b765 --- /dev/null +++ b/src/main/java/org/dynmap/factions/FactionBlock.java @@ -0,0 +1,4 @@ +package org.dynmap.factions; + +public record FactionBlock(int x, int z) { +} diff --git a/src/main/java/org/dynmap/factions/FactionBlocks.java b/src/main/java/org/dynmap/factions/FactionBlocks.java new file mode 100644 index 0000000..781a0ed --- /dev/null +++ b/src/main/java/org/dynmap/factions/FactionBlocks.java @@ -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> blocks = new HashMap<>(); + +} diff --git a/src/main/java/org/dynmap/factions/FactionsUpdate.java b/src/main/java/org/dynmap/factions/FactionsUpdate.java new file mode 100644 index 0000000..80a8110 --- /dev/null +++ b/src/main/java/org/dynmap/factions/FactionsUpdate.java @@ -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; + } + } + +} diff --git a/src/main/java/org/dynmap/factions/MetricsLite.java b/src/main/java/org/dynmap/factions/MetricsLite.java index 79e0ad2..eba1b0d 100644 --- a/src/main/java/org/dynmap/factions/MetricsLite.java +++ b/src/main/java/org/dynmap/factions/MetricsLite.java @@ -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; @@ -193,16 +194,11 @@ public class MetricsLite { * @return true if metrics should be opted out of it */ public boolean isOptOut() { - synchronized(optOutLock) { + synchronized (optOutLock) { 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()); } @@ -378,10 +374,10 @@ public class MetricsLite { * * * @param buffer the stringbuilder to append the data pair onto - * @param key the key value - * @param value the value + * @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); } } \ No newline at end of file diff --git a/src/main/java/org/dynmap/factions/OurServerListener.java b/src/main/java/org/dynmap/factions/OurServerListener.java new file mode 100644 index 0000000..dfa5bef --- /dev/null +++ b/src/main/java/org/dynmap/factions/OurServerListener.java @@ -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); + } + } + +} diff --git a/src/main/java/org/dynmap/factions/PlayerSetUpdate.java b/src/main/java/org/dynmap/factions/PlayerSetUpdate.java new file mode 100644 index 0000000..ab68665 --- /dev/null +++ b/src/main/java/org/dynmap/factions/PlayerSetUpdate.java @@ -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); + } + } +} diff --git a/src/main/java/org/dynmap/factions/TileFlags.java b/src/main/java/org/dynmap/factions/TileFlags.java index 0c180fb..4b078b1 100644 --- a/src/main/java/org/dynmap/factions/TileFlags.java +++ b/src/main/java/org/dynmap/factions/TileFlags.java @@ -1,67 +1,67 @@ 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 - * + *

* 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 chunkmap = new HashMap(); - private long last_key = Long.MAX_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.MAX_VALUE; - } + private final Map chunkMap = new HashMap<>(); + private long last_key = Long.MAX_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.MAX_VALUE; + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f06e41b..a57e67c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -12,7 +12,7 @@ layer: layerprio: 2 # (optional) set minimum zoom level before layer is visible (0 = defalt, always visible) minzoom: 0 - + # Format for popup - substitute values for macros infowindow: '

%regionname%
Flags
%flags%
' @@ -27,15 +27,15 @@ regionstyle: fillOpacity: 0.35 homeicon: "redflag" boost: false - + # Optional setting to limit which regions to show, by name - if commented out, all regions are shown # To show all regions on a given world, add 'world:' to the list visibleregions: [ ] - + # Optional setting to hide specific regions, by name # To hide all regions on a given world, add 'world:' to the list hiddenregions: [ ] - + # Optional per-region overrides for regionstyle (any defined replace those in regionstyle) custstyle: SafeZone: