This commit is contained in:
drtshock 2014-12-07 14:26:13 -06:00
parent a1ab22554c
commit caa6f0f0f0
12 changed files with 490 additions and 555 deletions

View File

@ -269,20 +269,7 @@ public class Conf {
public static int dynmapLayerMinimumZoom = 0; public static int dynmapLayerMinimumZoom = 0;
// Format for popup - substitute values for macros // Format for popup - substitute values for macros
public static String dynmapDescription = public static String dynmapDescription = "<div class=\"infowindow\">\n" + "<span style=\"font-weight: bold; font-size: 150%;\">%name%</span><br>\n" + "<span style=\"font-style: italic; font-size: 110%;\">%description%</span><br>" + "<br>\n" + "<span style=\"font-weight: bold;\">Leader:</span> %players.leader%<br>\n" + "<span style=\"font-weight: bold;\">Admins:</span> %players.admins.count%<br>\n" + "<span style=\"font-weight: bold;\">Moderators:</span> %players.moderators.count%<br>\n" + "<span style=\"font-weight: bold;\">Members:</span> %players.normals.count%<br>\n" + "<span style=\"font-weight: bold;\">TOTAL:</span> %players.count%<br>\n" + "</br>\n" + "<span style=\"font-weight: bold;\">Bank:</span> %money%<br>\n" + "<br>\n" + "</div>";
"<div class=\"infowindow\">\n"
+ "<span style=\"font-weight: bold; font-size: 150%;\">%name%</span><br>\n"
+ "<span style=\"font-style: italic; font-size: 110%;\">%description%</span><br>"
+ "<br>\n"
+ "<span style=\"font-weight: bold;\">Leader:</span> %players.leader%<br>\n"
+ "<span style=\"font-weight: bold;\">Admins:</span> %players.admins.count%<br>\n"
+ "<span style=\"font-weight: bold;\">Moderators:</span> %players.moderators.count%<br>\n"
+ "<span style=\"font-weight: bold;\">Members:</span> %players.normals.count%<br>\n"
+ "<span style=\"font-weight: bold;\">TOTAL:</span> %players.count%<br>\n"
+ "</br>\n"
+ "<span style=\"font-weight: bold;\">Bank:</span> %money%<br>\n"
+ "<br>\n"
+ "</div>";
// Enable the %money% macro. Only do this if you know your economy manager is thread-safe. // Enable the %money% macro. Only do this if you know your economy manager is thread-safe.
public static boolean dynmapDescriptionMoney = false; public static boolean dynmapDescriptionMoney = false;
@ -310,21 +297,11 @@ public class Conf {
public static final transient String DYNMAP_STYLE_HOME_MARKER = "greenflag"; public static final transient String DYNMAP_STYLE_HOME_MARKER = "greenflag";
public static final transient boolean DYNMAP_STYLE_BOOST = false; public static final transient boolean DYNMAP_STYLE_BOOST = false;
public static DynmapStyle dynmapDefaultStyle = new DynmapStyle() public static DynmapStyle dynmapDefaultStyle = new DynmapStyle().setStrokeColor(DYNMAP_STYLE_LINE_COLOR).setLineOpacity(DYNMAP_STYLE_LINE_OPACITY).setLineWeight(DYNMAP_STYLE_LINE_WEIGHT).setFillColor(DYNMAP_STYLE_FILL_COLOR).setFillOpacity(DYNMAP_STYLE_FILL_OPACITY).setHomeMarker(DYNMAP_STYLE_HOME_MARKER).setBoost(DYNMAP_STYLE_BOOST);
.setStrokeColor(DYNMAP_STYLE_LINE_COLOR)
.setLineOpacity(DYNMAP_STYLE_LINE_OPACITY)
.setLineWeight(DYNMAP_STYLE_LINE_WEIGHT)
.setFillColor(DYNMAP_STYLE_FILL_COLOR)
.setFillOpacity(DYNMAP_STYLE_FILL_OPACITY)
.setHomeMarker(DYNMAP_STYLE_HOME_MARKER)
.setBoost(DYNMAP_STYLE_BOOST);
// Optional per Faction style overrides. Any defined replace those in dynmapDefaultStyle. // Optional per Faction style overrides. Any defined replace those in dynmapDefaultStyle.
// Specify Faction either by name or UUID. // Specify Faction either by name or UUID.
public static Map<String, DynmapStyle> dynmapFactionStyles = ImmutableMap.of( public static Map<String, DynmapStyle> dynmapFactionStyles = ImmutableMap.of("SafeZone", new DynmapStyle().setStrokeColor("#FF00FF").setFillColor("#FF00FF").setBoost(false), "WarZone", new DynmapStyle().setStrokeColor("#FF0000").setFillColor("#FF0000").setBoost(false));
"SafeZone", new DynmapStyle().setStrokeColor("#FF00FF").setFillColor("#FF00FF").setBoost(false),
"WarZone", new DynmapStyle().setStrokeColor("#FF0000").setFillColor("#FF0000").setBoost(false)
);
//Faction banks, to pay for land claiming and other costs instead of individuals paying for them //Faction banks, to pay for land claiming and other costs instead of individuals paying for them

View File

@ -38,7 +38,7 @@ public class Essentials {
} }
public static boolean isVanished(Player player) { public static boolean isVanished(Player player) {
if(essentials == null) { if (essentials == null) {
return false; return false;
} }
return essentials.getUser(player).isVanished(); return essentials.getUser(player).isVanished();

View File

@ -2,66 +2,112 @@ package com.massivecraft.factions.integration.dynmap;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
public class DynmapStyle public class DynmapStyle {
{ // -------------------------------------------- //
// -------------------------------------------- // // FIELDS
// FIELDS // -------------------------------------------- //
// -------------------------------------------- //
public String lineColor = null; public String lineColor = null;
public int getLineColor() { return getColor(coalesce(this.lineColor, Conf.dynmapDefaultStyle.lineColor, Conf.DYNMAP_STYLE_LINE_COLOR)); }
public DynmapStyle setStrokeColor(String strokeColor) { this.lineColor = strokeColor; return this; }
public Double lineOpacity = null; public int getLineColor() {
public double getLineOpacity() { return coalesce(this.lineOpacity, Conf.dynmapDefaultStyle.lineOpacity, Conf.DYNMAP_STYLE_LINE_OPACITY); } return getColor(coalesce(this.lineColor, Conf.dynmapDefaultStyle.lineColor, Conf.DYNMAP_STYLE_LINE_COLOR));
public DynmapStyle setLineOpacity(Double strokeOpacity) { this.lineOpacity = strokeOpacity; return this; } }
public Integer lineWeight = null; public DynmapStyle setStrokeColor(String strokeColor) {
public int getLineWeight() { return coalesce(this.lineWeight, Conf.dynmapDefaultStyle.lineWeight, Conf.DYNMAP_STYLE_LINE_WEIGHT); } this.lineColor = strokeColor;
public DynmapStyle setLineWeight(Integer strokeWeight) { this.lineWeight = strokeWeight; return this; } return this;
}
public String fillColor = null; public Double lineOpacity = null;
public int getFillColor() { return getColor(coalesce(this.fillColor, Conf.dynmapDefaultStyle.fillColor, Conf.DYNMAP_STYLE_FILL_COLOR)); }
public DynmapStyle setFillColor(String fillColor) { this.fillColor = fillColor; return this; }
public Double fillOpacity = null; public double getLineOpacity() {
public double getFillOpacity() { return coalesce(this.fillOpacity, Conf.dynmapDefaultStyle.fillOpacity, Conf.DYNMAP_STYLE_FILL_OPACITY); } return coalesce(this.lineOpacity, Conf.dynmapDefaultStyle.lineOpacity, Conf.DYNMAP_STYLE_LINE_OPACITY);
public DynmapStyle setFillOpacity(Double fillOpacity) { this.fillOpacity = fillOpacity; return this; } }
// NOTE: We just return the string here. We do not return the resolved Dynmap MarkerIcon object. public DynmapStyle setLineOpacity(Double strokeOpacity) {
// The reason is we use this class in the MConf. For serialization to work Dynmap would have to be loaded and we can't require that. this.lineOpacity = strokeOpacity;
// Using dynmap is optional. return this;
public String homeMarker = null; }
public String getHomeMarker() { return coalesce(this.homeMarker, Conf.dynmapDefaultStyle.homeMarker, Conf.DYNMAP_STYLE_HOME_MARKER); }
public DynmapStyle setHomeMarker(String homeMarker) { this.homeMarker = homeMarker; return this; }
public Boolean boost = null; public Integer lineWeight = null;
public boolean getBoost() { return coalesce(this.boost, Conf.dynmapDefaultStyle.boost, Conf.DYNMAP_STYLE_BOOST); }
public DynmapStyle setBoost(Boolean boost) { this.boost = boost; return this; }
// -------------------------------------------- // public int getLineWeight() {
// UTIL return coalesce(this.lineWeight, Conf.dynmapDefaultStyle.lineWeight, Conf.DYNMAP_STYLE_LINE_WEIGHT);
// -------------------------------------------- // }
@SafeVarargs public DynmapStyle setLineWeight(Integer strokeWeight) {
public static <T> T coalesce(T... items) this.lineWeight = strokeWeight;
{ return this;
for (T item : items) }
{
if (item != null) return item;
}
return null;
}
public static int getColor(String string) public String fillColor = null;
{
int ret = 0x00FF00; public int getFillColor() {
try return getColor(coalesce(this.fillColor, Conf.dynmapDefaultStyle.fillColor, Conf.DYNMAP_STYLE_FILL_COLOR));
{ }
ret = Integer.parseInt(string.substring(1), 16);
} public DynmapStyle setFillColor(String fillColor) {
catch (NumberFormatException ignored) {} this.fillColor = fillColor;
return ret; return this;
} }
public Double fillOpacity = null;
public double getFillOpacity() {
return coalesce(this.fillOpacity, Conf.dynmapDefaultStyle.fillOpacity, Conf.DYNMAP_STYLE_FILL_OPACITY);
}
public DynmapStyle setFillOpacity(Double fillOpacity) {
this.fillOpacity = fillOpacity;
return this;
}
// NOTE: We just return the string here. We do not return the resolved Dynmap MarkerIcon object.
// The reason is we use this class in the MConf. For serialization to work Dynmap would have to be loaded and we can't require that.
// Using dynmap is optional.
public String homeMarker = null;
public String getHomeMarker() {
return coalesce(this.homeMarker, Conf.dynmapDefaultStyle.homeMarker, Conf.DYNMAP_STYLE_HOME_MARKER);
}
public DynmapStyle setHomeMarker(String homeMarker) {
this.homeMarker = homeMarker;
return this;
}
public Boolean boost = null;
public boolean getBoost() {
return coalesce(this.boost, Conf.dynmapDefaultStyle.boost, Conf.DYNMAP_STYLE_BOOST);
}
public DynmapStyle setBoost(Boolean boost) {
this.boost = boost;
return this;
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
@SafeVarargs
public static <T> T coalesce(T... items) {
for (T item : items) {
if (item != null) {
return item;
}
}
return null;
}
public static int getColor(String string) {
int ret = 0x00FF00;
try {
ret = Integer.parseInt(string.substring(1), 16);
} catch (NumberFormatException ignored) {
}
return ret;
}
} }

View File

@ -16,8 +16,7 @@ import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
// This source code is a heavily modified version of mikeprimms plugin Dynmap-Factions. // This source code is a heavily modified version of mikeprimms plugin Dynmap-Factions.
public class EngineDynmap public class EngineDynmap {
{
// -------------------------------------------- // // -------------------------------------------- //
// CONSTANTS // CONSTANTS
// -------------------------------------------- // // -------------------------------------------- //
@ -42,27 +41,28 @@ public class EngineDynmap
// -------------------------------------------- // // -------------------------------------------- //
private static EngineDynmap i = new EngineDynmap(); private static EngineDynmap i = new EngineDynmap();
public static EngineDynmap getInstance() { return i; }
private EngineDynmap() {} public static EngineDynmap getInstance() {
return i;
}
private EngineDynmap() {
}
public DynmapAPI dynmapApi; public DynmapAPI dynmapApi;
public MarkerAPI markerApi; public MarkerAPI markerApi;
public MarkerSet markerset; public MarkerSet markerset;
public void init() public void init() {
{
Plugin dynmap = Bukkit.getServer().getPluginManager().getPlugin("dynmap"); Plugin dynmap = Bukkit.getServer().getPluginManager().getPlugin("dynmap");
if (dynmap == null || !dynmap.isEnabled()) if (dynmap == null || !dynmap.isEnabled()) {
{
return; return;
} }
// Should we even use dynmap? // Should we even use dynmap?
if (!Conf.dynmapUse) if (!Conf.dynmapUse) {
{ if (this.markerset != null) {
if (this.markerset != null)
{
this.markerset.deleteMarkerSet(); this.markerset.deleteMarkerSet();
this.markerset = null; this.markerset = null;
} }
@ -70,20 +70,22 @@ public class EngineDynmap
} }
// Shedule non thread safe sync at the end! // Shedule non thread safe sync at the end!
Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() {
{
@Override @Override
public void run() public void run() {
{
final Map<String, TempMarker> homes = createHomes(); final Map<String, TempMarker> homes = createHomes();
final Map<String, TempAreaMarker> areas = createAreas(); final Map<String, TempAreaMarker> areas = createAreas();
final Map<String, Set<String>> playerSets = createPlayersets(); final Map<String, Set<String>> playerSets = createPlayersets();
if (!updateCore()) return; if (!updateCore()) {
return;
}
// createLayer() is thread safe but it makes use of fields set in updateCore() so we must have it after. // createLayer() is thread safe but it makes use of fields set in updateCore() so we must have it after.
if (!updateLayer(createLayer())) return; if (!updateLayer(createLayer())) {
return;
}
updateHomes(homes); updateHomes(homes);
updateAreas(areas); updateAreas(areas);
@ -93,20 +95,17 @@ public class EngineDynmap
} }
// Thread Safe / Asynchronous: No // Thread Safe / Asynchronous: No
public boolean updateCore() public boolean updateCore() {
{
// Get DynmapAPI // Get DynmapAPI
this.dynmapApi = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap"); this.dynmapApi = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap");
if (this.dynmapApi == null) if (this.dynmapApi == null) {
{
severe("Could not retrieve the DynmapAPI."); severe("Could not retrieve the DynmapAPI.");
return false; return false;
} }
// Get MarkerAPI // Get MarkerAPI
this.markerApi = this.dynmapApi.getMarkerAPI(); this.markerApi = this.dynmapApi.getMarkerAPI();
if (this.markerApi == null) if (this.markerApi == null) {
{
severe("Could not retrieve the MarkerAPI."); severe("Could not retrieve the MarkerAPI.");
return false; return false;
} }
@ -115,8 +114,7 @@ public class EngineDynmap
} }
// Thread Safe / Asynchronous: Yes // Thread Safe / Asynchronous: Yes
public TempMarkerSet createLayer() public TempMarkerSet createLayer() {
{
TempMarkerSet ret = new TempMarkerSet(); TempMarkerSet ret = new TempMarkerSet();
ret.label = Conf.dynmapLayerName; ret.label = Conf.dynmapLayerName;
ret.minimumZoom = Conf.dynmapLayerMinimumZoom; ret.minimumZoom = Conf.dynmapLayerMinimumZoom;
@ -126,20 +124,15 @@ public class EngineDynmap
} }
// Thread Safe / Asynchronous: No // Thread Safe / Asynchronous: No
public boolean updateLayer(TempMarkerSet temp) public boolean updateLayer(TempMarkerSet temp) {
{
this.markerset = this.markerApi.getMarkerSet(FACTIONS_MARKERSET); this.markerset = this.markerApi.getMarkerSet(FACTIONS_MARKERSET);
if (this.markerset == null) if (this.markerset == null) {
{
this.markerset = temp.create(this.markerApi, FACTIONS_MARKERSET); this.markerset = temp.create(this.markerApi, FACTIONS_MARKERSET);
if (this.markerset == null) if (this.markerset == null) {
{
severe("Could not create the Faction Markerset/Layer"); severe("Could not create the Faction Markerset/Layer");
return false; return false;
} }
} } else {
else
{
temp.update(this.markerset); temp.update(this.markerset);
} }
return true; return true;
@ -150,15 +143,15 @@ public class EngineDynmap
// -------------------------------------------- // // -------------------------------------------- //
// Thread Safe / Asynchronous: Yes // Thread Safe / Asynchronous: Yes
public Map<String, TempMarker> createHomes() public Map<String, TempMarker> createHomes() {
{
Map<String, TempMarker> ret = new HashMap<String, TempMarker>(); Map<String, TempMarker> ret = new HashMap<String, TempMarker>();
// Loop current factions // Loop current factions
for (Faction faction : Factions.getInstance().getAllFactions()) for (Faction faction : Factions.getInstance().getAllFactions()) {
{
Location ps = faction.getHome(); Location ps = faction.getHome();
if (ps == null) continue; if (ps == null) {
continue;
}
DynmapStyle style = getStyle(faction); DynmapStyle style = getStyle(faction);
@ -181,18 +174,15 @@ public class EngineDynmap
// Thread Safe / Asynchronous: No // Thread Safe / Asynchronous: No
// This method places out the faction home markers into the factions markerset. // This method places out the faction home markers into the factions markerset.
public void updateHomes(Map<String, TempMarker> homes) public void updateHomes(Map<String, TempMarker> homes) {
{
// Put all current faction markers in a map // Put all current faction markers in a map
Map<String, Marker> markers = new HashMap<String, Marker>(); Map<String, Marker> markers = new HashMap<String, Marker>();
for (Marker marker : this.markerset.getMarkers()) for (Marker marker : this.markerset.getMarkers()) {
{
markers.put(marker.getMarkerID(), marker); markers.put(marker.getMarkerID(), marker);
} }
// Loop homes // Loop homes
for (Entry<String, TempMarker> entry : homes.entrySet()) for (Entry<String, TempMarker> entry : homes.entrySet()) {
{
String markerId = entry.getKey(); String markerId = entry.getKey();
TempMarker temp = entry.getValue(); TempMarker temp = entry.getValue();
@ -200,24 +190,19 @@ public class EngineDynmap
// NOTE: I remove from the map created just in the beginning of this method. // NOTE: I remove from the map created just in the beginning of this method.
// NOTE: That way what is left at the end will be outdated markers to remove. // NOTE: That way what is left at the end will be outdated markers to remove.
Marker marker = markers.remove(markerId); Marker marker = markers.remove(markerId);
if (marker == null) if (marker == null) {
{
marker = temp.create(this.markerApi, this.markerset, markerId); marker = temp.create(this.markerApi, this.markerset, markerId);
if (marker == null) if (marker == null) {
{
EngineDynmap.severe("Could not get/create the home marker " + markerId); EngineDynmap.severe("Could not get/create the home marker " + markerId);
} }
} } else {
else
{
temp.update(this.markerApi, marker); temp.update(this.markerApi, marker);
} }
} }
// Delete Deprecated Markers // Delete Deprecated Markers
// Only old markers should now be left // Only old markers should now be left
for (Marker marker : markers.values()) for (Marker marker : markers.values()) {
{
marker.deleteMarker(); marker.deleteMarker();
} }
} }
@ -227,35 +212,31 @@ public class EngineDynmap
// -------------------------------------------- // // -------------------------------------------- //
// Thread Safe: YES // Thread Safe: YES
public Map<String, TempAreaMarker> createAreas() public Map<String, TempAreaMarker> createAreas() {
{
Map<String, Map<Faction, Set<FLocation>>> worldFactionChunks = createWorldFactionChunks(); Map<String, Map<Faction, Set<FLocation>>> worldFactionChunks = createWorldFactionChunks();
return createAreas(worldFactionChunks); return createAreas(worldFactionChunks);
} }
// Thread Safe: YES // Thread Safe: YES
public Map<String, Map<Faction, Set<FLocation>>> createWorldFactionChunks() public Map<String, Map<Faction, Set<FLocation>>> createWorldFactionChunks() {
{
// Create map "world name --> faction --> set of chunk coords" // Create map "world name --> faction --> set of chunk coords"
Map<String, Map<Faction, Set<FLocation>>> worldFactionChunks = new HashMap<String, Map<Faction, Set<FLocation>>>(); Map<String, Map<Faction, Set<FLocation>>> worldFactionChunks = new HashMap<String, Map<Faction, Set<FLocation>>>();
// Note: The board is the world. The board id is the world name. // Note: The board is the world. The board id is the world name.
MemoryBoard board = (MemoryBoard) Board.getInstance(); MemoryBoard board = (MemoryBoard) Board.getInstance();
for (Entry<FLocation,String> entry : board.flocationIds.entrySet()) for (Entry<FLocation, String> entry : board.flocationIds.entrySet()) {
{
String world = entry.getKey().getWorldName(); String world = entry.getKey().getWorldName();
Faction chunkOwner = Factions.getInstance().getFactionById(entry.getValue()); Faction chunkOwner = Factions.getInstance().getFactionById(entry.getValue());
Map<Faction, Set<FLocation>> factionChunks = worldFactionChunks.get(world); Map<Faction, Set<FLocation>> factionChunks = worldFactionChunks.get(world);
if (factionChunks == null) if (factionChunks == null) {
{
factionChunks = new HashMap<Faction, Set<FLocation>>(); factionChunks = new HashMap<Faction, Set<FLocation>>();
worldFactionChunks.put(world, factionChunks); worldFactionChunks.put(world, factionChunks);
} }
Set<FLocation> factionTerritory = factionChunks.get(chunkOwner); Set<FLocation> factionTerritory = factionChunks.get(chunkOwner);
if (factionTerritory == null){ if (factionTerritory == null) {
factionTerritory = new HashSet<FLocation>(); factionTerritory = new HashSet<FLocation>();
factionChunks.put(chunkOwner, factionTerritory); factionChunks.put(chunkOwner, factionTerritory);
} }
@ -267,19 +248,16 @@ public class EngineDynmap
} }
// Thread Safe: YES // Thread Safe: YES
public Map<String, TempAreaMarker> createAreas(Map<String, Map<Faction, Set<FLocation>>> worldFactionChunks) public Map<String, TempAreaMarker> createAreas(Map<String, Map<Faction, Set<FLocation>>> worldFactionChunks) {
{
Map<String, TempAreaMarker> ret = new HashMap<String, TempAreaMarker>(); Map<String, TempAreaMarker> ret = new HashMap<String, TempAreaMarker>();
// For each world // For each world
for (Entry<String, Map<Faction, Set<FLocation>>> entry : worldFactionChunks.entrySet()) for (Entry<String, Map<Faction, Set<FLocation>>> entry : worldFactionChunks.entrySet()) {
{
String world = entry.getKey(); String world = entry.getKey();
Map<Faction, Set<FLocation>> factionChunks = entry.getValue(); Map<Faction, Set<FLocation>> factionChunks = entry.getValue();
// For each faction and its chunks in that world // For each faction and its chunks in that world
for (Entry<Faction, Set<FLocation>> entry1 : factionChunks.entrySet()) for (Entry<Faction, Set<FLocation>> entry1 : factionChunks.entrySet()) {
{
Faction faction = entry1.getKey(); Faction faction = entry1.getKey();
Set<FLocation> chunks = entry1.getValue(); Set<FLocation> chunks = entry1.getValue();
Map<String, TempAreaMarker> worldFactionMarkers = createAreas(world, faction, chunks); Map<String, TempAreaMarker> worldFactionMarkers = createAreas(world, faction, chunks);
@ -293,15 +271,18 @@ public class EngineDynmap
// Thread Safe: YES // Thread Safe: YES
// Handle specific faction on specific world // Handle specific faction on specific world
// "handle faction on world" // "handle faction on world"
public Map<String, TempAreaMarker> createAreas(String world, Faction faction, Set<FLocation> chunks) public Map<String, TempAreaMarker> createAreas(String world, Faction faction, Set<FLocation> chunks) {
{
Map<String, TempAreaMarker> ret = new HashMap<String, TempAreaMarker>(); Map<String, TempAreaMarker> ret = new HashMap<String, TempAreaMarker>();
// If the faction is visible ... // If the faction is visible ...
if (!isVisible(faction, world)) return ret; if (!isVisible(faction, world)) {
return ret;
}
// ... and has any chunks ... // ... and has any chunks ...
if (chunks.isEmpty()) return ret; if (chunks.isEmpty()) {
return ret;
}
// Index of polygon for given faction // Index of polygon for given faction
int markerIndex = 0; int markerIndex = 0;
@ -315,29 +296,25 @@ public class EngineDynmap
// Loop through chunks: set flags on chunk map // Loop through chunks: set flags on chunk map
TileFlags allChunkFlags = new TileFlags(); TileFlags allChunkFlags = new TileFlags();
LinkedList<FLocation> allChunks = new LinkedList<FLocation>(); LinkedList<FLocation> allChunks = new LinkedList<FLocation>();
for (FLocation chunk : chunks) for (FLocation chunk : chunks) {
{ allChunkFlags.setFlag((int) chunk.getX(), (int) chunk.getZ(), true); // Set flag for chunk
allChunkFlags.setFlag((int)chunk.getX(), (int)chunk.getZ(), true); // Set flag for chunk
allChunks.addLast(chunk); allChunks.addLast(chunk);
} }
// Loop through until we don't find more areas // Loop through until we don't find more areas
while (allChunks != null) while (allChunks != null) {
{
TileFlags ourChunkFlags = null; TileFlags ourChunkFlags = null;
LinkedList<FLocation> ourChunks = null; LinkedList<FLocation> ourChunks = null;
LinkedList<FLocation> newChunks = null; LinkedList<FLocation> newChunks = null;
int minimumX = Integer.MAX_VALUE; int minimumX = Integer.MAX_VALUE;
int minimumZ = Integer.MAX_VALUE; int minimumZ = Integer.MAX_VALUE;
for (FLocation chunk : allChunks) for (FLocation chunk : allChunks) {
{ int chunkX = (int) chunk.getX();
int chunkX = (int)chunk.getX(); int chunkZ = (int) chunk.getZ();
int chunkZ = (int)chunk.getZ();
// If we need to start shape, and this block is not part of one yet // If we need to start shape, and this block is not part of one yet
if (ourChunkFlags == null && allChunkFlags.getFlag(chunkX, chunkZ)) if (ourChunkFlags == null && allChunkFlags.getFlag(chunkX, chunkZ)) {
{
ourChunkFlags = new TileFlags(); // Create map for shape ourChunkFlags = new TileFlags(); // Create map for shape
ourChunks = new LinkedList<FLocation>(); ourChunks = new LinkedList<FLocation>();
floodFillTarget(allChunkFlags, ourChunkFlags, chunkX, chunkZ); // Copy shape floodFillTarget(allChunkFlags, ourChunkFlags, chunkX, chunkZ); // Copy shape
@ -346,23 +323,20 @@ public class EngineDynmap
minimumZ = chunkZ; minimumZ = chunkZ;
} }
// If shape found, and we're in it, add to our node list // If shape found, and we're in it, add to our node list
else if (ourChunkFlags != null && ourChunkFlags.getFlag(chunkX, chunkZ)) else if (ourChunkFlags != null && ourChunkFlags.getFlag(chunkX, chunkZ)) {
{
ourChunks.add(chunk); ourChunks.add(chunk);
if (chunkX < minimumX) if (chunkX < minimumX) {
{
minimumX = chunkX; minimumX = chunkX;
minimumZ = chunkZ; minimumZ = chunkZ;
} } else if (chunkX == minimumX && chunkZ < minimumZ) {
else if (chunkX == minimumX && chunkZ < minimumZ)
{
minimumZ = chunkZ; minimumZ = chunkZ;
} }
} }
// Else, keep it in the list for the next polygon // Else, keep it in the list for the next polygon
else else {
{ if (newChunks == null) {
if (newChunks == null) newChunks = new LinkedList<FLocation>(); newChunks = new LinkedList<FLocation>();
}
newChunks.add(chunk); newChunks.add(chunk);
} }
} }
@ -370,7 +344,9 @@ public class EngineDynmap
// Replace list (null if no more to process) // Replace list (null if no more to process)
allChunks = newChunks; allChunks = newChunks;
if (ourChunkFlags == null) continue; if (ourChunkFlags == null) {
continue;
}
// Trace outline of blocks - start from minx, minz going to x+ // Trace outline of blocks - start from minx, minz going to x+
int initialX = minimumX; int initialX = minimumX;
@ -379,91 +355,68 @@ public class EngineDynmap
int currentZ = minimumZ; int currentZ = minimumZ;
Direction direction = Direction.XPLUS; Direction direction = Direction.XPLUS;
ArrayList<int[]> linelist = new ArrayList<int[]>(); ArrayList<int[]> linelist = new ArrayList<int[]>();
linelist.add(new int[]{ initialX, initialZ }); // Add start point linelist.add(new int[]{initialX, initialZ}); // Add start point
while ((currentX != initialX) || (currentZ != initialZ) || (direction != Direction.ZMINUS)) while ((currentX != initialX) || (currentZ != initialZ) || (direction != Direction.ZMINUS)) {
{ switch (direction) {
switch (direction)
{
case XPLUS: // Segment in X+ direction case XPLUS: // Segment in X+ direction
if (!ourChunkFlags.getFlag(currentX + 1, currentZ)) if (!ourChunkFlags.getFlag(currentX + 1, currentZ)) { // Right turn?
{ // Right turn? linelist.add(new int[]{currentX + 1, currentZ}); // Finish line
linelist.add(new int[]{ currentX + 1, currentZ }); // Finish line
direction = Direction.ZPLUS; // Change direction direction = Direction.ZPLUS; // Change direction
} } else if (!ourChunkFlags.getFlag(currentX + 1, currentZ - 1)) { // Straight?
else if (!ourChunkFlags.getFlag(currentX + 1, currentZ - 1))
{ // Straight?
currentX++; currentX++;
} } else { // Left turn
else linelist.add(new int[]{currentX + 1, currentZ}); // Finish line
{ // Left turn
linelist.add(new int[]{ currentX + 1, currentZ }); // Finish line
direction = Direction.ZMINUS; direction = Direction.ZMINUS;
currentX++; currentX++;
currentZ--; currentZ--;
} }
break; break;
case ZPLUS: // Segment in Z+ direction case ZPLUS: // Segment in Z+ direction
if (!ourChunkFlags.getFlag(currentX, currentZ + 1)) if (!ourChunkFlags.getFlag(currentX, currentZ + 1)) { // Right turn?
{ // Right turn? linelist.add(new int[]{currentX + 1, currentZ + 1}); // Finish line
linelist.add(new int[]{ currentX + 1, currentZ + 1 }); // Finish line
direction = Direction.XMINUS; // Change direction direction = Direction.XMINUS; // Change direction
} } else if (!ourChunkFlags.getFlag(currentX + 1, currentZ + 1)) { // Straight?
else if (!ourChunkFlags.getFlag(currentX + 1, currentZ + 1))
{ // Straight?
currentZ++; currentZ++;
} } else { // Left turn
else linelist.add(new int[]{currentX + 1, currentZ + 1}); // Finish line
{ // Left turn
linelist.add(new int[]{ currentX + 1, currentZ + 1 }); // Finish line
direction = Direction.XPLUS; direction = Direction.XPLUS;
currentX++; currentX++;
currentZ++; currentZ++;
} }
break; break;
case XMINUS: // Segment in X- direction case XMINUS: // Segment in X- direction
if (!ourChunkFlags.getFlag(currentX - 1, currentZ)) if (!ourChunkFlags.getFlag(currentX - 1, currentZ)) { // Right turn?
{ // Right turn? linelist.add(new int[]{currentX, currentZ + 1}); // Finish line
linelist.add(new int[]{ currentX, currentZ + 1 }); // Finish line
direction = Direction.ZMINUS; // Change direction direction = Direction.ZMINUS; // Change direction
} } else if (!ourChunkFlags.getFlag(currentX - 1, currentZ + 1)) { // Straight?
else if (!ourChunkFlags.getFlag(currentX - 1, currentZ + 1))
{ // Straight?
currentX--; currentX--;
} } else { // Left turn
else linelist.add(new int[]{currentX, currentZ + 1}); // Finish line
{ // Left turn
linelist.add(new int[] { currentX, currentZ + 1 }); // Finish line
direction = Direction.ZPLUS; direction = Direction.ZPLUS;
currentX--; currentX--;
currentZ++; currentZ++;
} }
break; break;
case ZMINUS: // Segment in Z- direction case ZMINUS: // Segment in Z- direction
if (!ourChunkFlags.getFlag(currentX, currentZ - 1)) if (!ourChunkFlags.getFlag(currentX, currentZ - 1)) { // Right turn?
{ // Right turn? linelist.add(new int[]{currentX, currentZ}); // Finish line
linelist.add(new int[]{ currentX, currentZ }); // Finish line
direction = Direction.XPLUS; // Change direction direction = Direction.XPLUS; // Change direction
} } else if (!ourChunkFlags.getFlag(currentX - 1, currentZ - 1)) { // Straight?
else if (!ourChunkFlags.getFlag(currentX - 1, currentZ - 1))
{ // Straight?
currentZ--; currentZ--;
} } else { // Left turn
else linelist.add(new int[]{currentX, currentZ}); // Finish line
{ // Left turn
linelist.add(new int[] { currentX, currentZ }); // Finish line
direction = Direction.XMINUS; direction = Direction.XMINUS;
currentX--; currentX--;
currentZ--; currentZ--;
} }
break; break;
} }
} }
int sz = linelist.size(); int sz = linelist.size();
double[] x = new double[sz]; double[] x = new double[sz];
double[] z = new double[sz]; double[] z = new double[sz];
for (int i = 0; i < sz; i++) for (int i = 0; i < sz; i++) {
{
int[] line = linelist.get(i); int[] line = linelist.get(i);
x[i] = (double) line[0] * (double) BLOCKS_PER_CHUNK; x[i] = (double) line[0] * (double) BLOCKS_PER_CHUNK;
z[i] = (double) line[1] * (double) BLOCKS_PER_CHUNK; z[i] = (double) line[1] * (double) BLOCKS_PER_CHUNK;
@ -497,18 +450,15 @@ public class EngineDynmap
} }
// Thread Safe: NO // Thread Safe: NO
public void updateAreas(Map<String, TempAreaMarker> areas) public void updateAreas(Map<String, TempAreaMarker> areas) {
{
// Map Current // Map Current
Map<String, AreaMarker> markers = new HashMap<String, AreaMarker>(); Map<String, AreaMarker> markers = new HashMap<String, AreaMarker>();
for (AreaMarker marker : this.markerset.getAreaMarkers()) for (AreaMarker marker : this.markerset.getAreaMarkers()) {
{
markers.put(marker.getMarkerID(), marker); markers.put(marker.getMarkerID(), marker);
} }
// Loop New // Loop New
for (Entry<String, TempAreaMarker> entry : areas.entrySet()) for (Entry<String, TempAreaMarker> entry : areas.entrySet()) {
{
String markerId = entry.getKey(); String markerId = entry.getKey();
TempAreaMarker temp = entry.getValue(); TempAreaMarker temp = entry.getValue();
@ -516,23 +466,18 @@ public class EngineDynmap
// NOTE: I remove from the map created just in the beginning of this method. // NOTE: I remove from the map created just in the beginning of this method.
// NOTE: That way what is left at the end will be outdated markers to remove. // NOTE: That way what is left at the end will be outdated markers to remove.
AreaMarker marker = markers.remove(markerId); AreaMarker marker = markers.remove(markerId);
if (marker == null) if (marker == null) {
{
marker = temp.create(this.markerset, markerId); marker = temp.create(this.markerset, markerId);
if (marker == null) if (marker == null) {
{
severe("Could not get/create the area marker " + markerId); severe("Could not get/create the area marker " + markerId);
} }
} } else {
else
{
temp.update(marker); temp.update(marker);
} }
} }
// Only old/outdated should now be left. Delete them. // Only old/outdated should now be left. Delete them.
for (AreaMarker marker : markers.values()) for (AreaMarker marker : markers.values()) {
{
marker.deleteMarker(); marker.deleteMarker();
} }
} }
@ -542,25 +487,32 @@ public class EngineDynmap
// -------------------------------------------- // // -------------------------------------------- //
// Thread Safe / Asynchronous: Yes // Thread Safe / Asynchronous: Yes
public String createPlayersetId(Faction faction) public String createPlayersetId(Faction faction) {
{ if (faction == null) {
if (faction == null) return null; return null;
if (faction.isNone()) return null; }
if (faction.isNone()) {
return null;
}
String factionId = faction.getId(); String factionId = faction.getId();
if (factionId == null) return null; if (factionId == null) {
return null;
}
return FACTIONS_PLAYERSET_ + factionId; return FACTIONS_PLAYERSET_ + factionId;
} }
// Thread Safe / Asynchronous: Yes // Thread Safe / Asynchronous: Yes
public Set<String> createPlayerset(Faction faction) public Set<String> createPlayerset(Faction faction) {
{ if (faction == null) {
if (faction == null) return null; return null;
if (faction.isNone()) return null; }
if (faction.isNone()) {
return null;
}
Set<String> ret = new HashSet<String>(); Set<String> ret = new HashSet<String>();
for (FPlayer fplayer : faction.getFPlayers()) for (FPlayer fplayer : faction.getFPlayers()) {
{
// NOTE: We add both UUID and name. This might be a good idea for future proofing. // NOTE: We add both UUID and name. This might be a good idea for future proofing.
ret.add(fplayer.getId()); ret.add(fplayer.getId());
ret.add(fplayer.getName()); ret.add(fplayer.getName());
@ -570,21 +522,22 @@ public class EngineDynmap
} }
// Thread Safe / Asynchronous: Yes // Thread Safe / Asynchronous: Yes
public Map<String, Set<String>> createPlayersets() public Map<String, Set<String>> createPlayersets() {
{ if (!Conf.dynmapVisibilityByFaction) {
if (!Conf.dynmapVisibilityByFaction)
{
return null; return null;
} }
Map<String, Set<String>> ret = new HashMap<String, Set<String>>(); Map<String, Set<String>> ret = new HashMap<String, Set<String>>();
for (Faction faction : Factions.getInstance().getAllFactions()) for (Faction faction : Factions.getInstance().getAllFactions()) {
{
String playersetId = createPlayersetId(faction); String playersetId = createPlayersetId(faction);
if (playersetId == null) continue; if (playersetId == null) {
continue;
}
Set<String> playerIds = createPlayerset(faction); Set<String> playerIds = createPlayerset(faction);
if (playerIds == null) continue; if (playerIds == null) {
continue;
}
ret.put(playersetId, playerIds); ret.put(playersetId, playerIds);
} }
@ -592,41 +545,41 @@ public class EngineDynmap
} }
// Thread Safe / Asynchronous: No // Thread Safe / Asynchronous: No
public void updatePlayersets(Map<String, Set<String>> playersets) public void updatePlayersets(Map<String, Set<String>> playersets) {
{ if (playersets == null) {
if (playersets == null)
{
return; return;
} }
// Remove // Remove
for (PlayerSet set : this.markerApi.getPlayerSets()) for (PlayerSet set : this.markerApi.getPlayerSets()) {
{ if (!set.getSetID().startsWith(FACTIONS_PLAYERSET_)) {
if (!set.getSetID().startsWith(FACTIONS_PLAYERSET_)) continue; continue;
}
// (Null means remove all) // (Null means remove all)
if (playersets.containsKey(set.getSetID())) continue; if (playersets.containsKey(set.getSetID())) {
continue;
}
set.deleteSet(); set.deleteSet();
} }
// Add / Update // Add / Update
for (Entry<String, Set<String>> entry : playersets.entrySet()) for (Entry<String, Set<String>> entry : playersets.entrySet()) {
{
// Extract from Entry // Extract from Entry
String setId = entry.getKey(); String setId = entry.getKey();
Set<String> playerIds = entry.getValue(); Set<String> playerIds = entry.getValue();
// Get Creatively // Get Creatively
PlayerSet set = this.markerApi.getPlayerSet(setId); PlayerSet set = this.markerApi.getPlayerSet(setId);
if (set == null) set = this.markerApi.createPlayerSet( if (set == null) {
setId, // id set = this.markerApi.createPlayerSet(setId, // id
true, // symmetric true, // symmetric
playerIds, // players playerIds, // players
false // persistent false // persistent
); );
if (set == null) }
{ if (set == null) {
severe("Could not get/create the player set " + setId); severe("Could not get/create the player set " + setId);
continue; continue;
} }
@ -641,8 +594,7 @@ public class EngineDynmap
// -------------------------------------------- // // -------------------------------------------- //
// Thread Safe / Asynchronous: Yes // Thread Safe / Asynchronous: Yes
private String getDescription(Faction faction) private String getDescription(Faction faction) {
{
String ret = "<div class=\"regioninfo\">" + Conf.dynmapDescription + "</div>"; String ret = "<div class=\"regioninfo\">" + Conf.dynmapDescription + "</div>";
// Name // Name
@ -660,8 +612,7 @@ public class EngineDynmap
// Money // Money
String money = "unavailable"; String money = "unavailable";
if (Conf.bankEnabled && Conf.dynmapDescriptionMoney) if (Conf.bankEnabled && Conf.dynmapDescriptionMoney) {
{
money = String.format("%.2f", Econ.getBalance(faction.getAccountId())); money = String.format("%.2f", Econ.getBalance(faction.getAccountId()));
} }
ret = ret.replace("%money%", money); ret = ret.replace("%money%", money);
@ -702,37 +653,33 @@ public class EngineDynmap
return ret; return ret;
} }
public static String getHtmlPlayerString(Collection<FPlayer> playersOfficersList) public static String getHtmlPlayerString(Collection<FPlayer> playersOfficersList) {
{
String ret = ""; String ret = "";
for (FPlayer fplayer : playersOfficersList) for (FPlayer fplayer : playersOfficersList) {
{ if (ret.length() > 0) {
if (ret.length() > 0) ret += ", "; ret += ", ";
}
ret += getHtmlPlayerName(fplayer); ret += getHtmlPlayerName(fplayer);
} }
return ret; return ret;
} }
public static String getHtmlPlayerName(FPlayer fplayer) public static String getHtmlPlayerName(FPlayer fplayer) {
{ if (fplayer == null) {
if (fplayer == null) return "none"; return "none";
}
return escapeHtml(fplayer.getName()); return escapeHtml(fplayer.getName());
} }
public static String escapeHtml(String string) public static String escapeHtml(String string) {
{
StringBuilder out = new StringBuilder(Math.max(16, string.length())); StringBuilder out = new StringBuilder(Math.max(16, string.length()));
for (int i = 0; i < string.length(); i++) for (int i = 0; i < string.length(); i++) {
{
char c = string.charAt(i); char c = string.charAt(i);
if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') {
{
out.append("&#"); out.append("&#");
out.append((int) c); out.append((int) c);
out.append(';'); out.append(';');
} } else {
else
{
out.append(c); out.append(c);
} }
} }
@ -740,24 +687,27 @@ public class EngineDynmap
} }
// Thread Safe / Asynchronous: Yes // Thread Safe / Asynchronous: Yes
private boolean isVisible(Faction faction, String world) private boolean isVisible(Faction faction, String world) {
{ if (faction == null) {
if (faction == null) return false; return false;
}
final String factionId = faction.getId(); final String factionId = faction.getId();
if (factionId == null) return false; if (factionId == null) {
return false;
}
final String factionName = faction.getTag(); final String factionName = faction.getTag();
if (factionName == null) return false; if (factionName == null) {
return false;
}
Set<String> visible = Conf.dynmapVisibleFactions; Set<String> visible = Conf.dynmapVisibleFactions;
Set<String> hidden = Conf.dynmapHiddenFactions; Set<String> hidden = Conf.dynmapHiddenFactions;
if (!visible.isEmpty() && !visible.contains(factionId) && !visible.contains(factionName) && !visible.contains("world:" + world)) if (!visible.isEmpty() && !visible.contains(factionId) && !visible.contains(factionName) && !visible.contains("world:" + world)) {
{
return false; return false;
} }
if (hidden.contains(factionId) || hidden.contains(factionName) || hidden.contains("world:" + world)) if (hidden.contains(factionId) || hidden.contains(factionName) || hidden.contains("world:" + world)) {
{
return false; return false;
} }
@ -765,59 +715,64 @@ public class EngineDynmap
} }
// Thread Safe / Asynchronous: Yes // Thread Safe / Asynchronous: Yes
public DynmapStyle getStyle(Faction faction) public DynmapStyle getStyle(Faction faction) {
{
DynmapStyle ret; DynmapStyle ret;
ret = Conf.dynmapFactionStyles.get(faction.getId()); ret = Conf.dynmapFactionStyles.get(faction.getId());
if (ret != null) return ret; if (ret != null) {
return ret;
}
ret = Conf.dynmapFactionStyles.get(faction.getTag()); ret = Conf.dynmapFactionStyles.get(faction.getTag());
if (ret != null) return ret; if (ret != null) {
return ret;
}
return Conf.dynmapDefaultStyle; return Conf.dynmapDefaultStyle;
} }
// Thread Safe / Asynchronous: Yes // Thread Safe / Asynchronous: Yes
public static void info(String msg) public static void info(String msg) {
{
String message = DYNMAP_INTEGRATION + msg; String message = DYNMAP_INTEGRATION + msg;
System.out.println(message); System.out.println(message);
} }
// Thread Safe / Asynchronous: Yes // Thread Safe / Asynchronous: Yes
public static void severe(String msg) public static void severe(String msg) {
{
String message = DYNMAP_INTEGRATION + ChatColor.RED.toString() + msg; String message = DYNMAP_INTEGRATION + ChatColor.RED.toString() + msg;
System.out.println(message); System.out.println(message);
} }
enum Direction enum Direction {
{
XPLUS, ZPLUS, XMINUS, ZMINUS XPLUS, ZPLUS, XMINUS, ZMINUS
} }
// Find all contiguous blocks, set in target and clear in source // Find all contiguous blocks, set in target and clear in source
private int floodFillTarget(TileFlags source, TileFlags destination, int x, int y) private int floodFillTarget(TileFlags source, TileFlags destination, int x, int y) {
{
int cnt = 0; int cnt = 0;
ArrayDeque<int[]> stack = new ArrayDeque<int[]>(); ArrayDeque<int[]> stack = new ArrayDeque<int[]>();
stack.push(new int[] { x, y }); stack.push(new int[]{x, y});
while (!stack.isEmpty()) while (!stack.isEmpty()) {
{
int[] nxt = stack.pop(); int[] nxt = stack.pop();
x = nxt[0]; x = nxt[0];
y = nxt[1]; y = nxt[1];
if (source.getFlag(x, y)) if (source.getFlag(x, y)) { // Set in src
{ // Set in src
source.setFlag(x, y, false); // Clear source source.setFlag(x, y, false); // Clear source
destination.setFlag(x, y, true); // Set in destination destination.setFlag(x, y, true); // Set in destination
cnt++; cnt++;
if (source.getFlag(x + 1, y)) stack.push(new int[] { x + 1, y }); if (source.getFlag(x + 1, y)) {
if (source.getFlag(x - 1, y)) stack.push(new int[] { x - 1, y }); stack.push(new int[]{x + 1, y});
if (source.getFlag(x, y + 1)) stack.push(new int[] { x, y + 1 }); }
if (source.getFlag(x, y - 1)) stack.push(new int[] { x, y - 1 }); if (source.getFlag(x - 1, y)) {
stack.push(new int[]{x - 1, y});
}
if (source.getFlag(x, y + 1)) {
stack.push(new int[]{x, y + 1});
}
if (source.getFlag(x, y - 1)) {
stack.push(new int[]{x, y - 1});
}
} }
} }
return cnt; return cnt;

View File

@ -3,132 +3,114 @@ package com.massivecraft.factions.integration.dynmap;
import org.dynmap.markers.AreaMarker; import org.dynmap.markers.AreaMarker;
import org.dynmap.markers.MarkerSet; import org.dynmap.markers.MarkerSet;
public class TempAreaMarker public class TempAreaMarker {
{ // -------------------------------------------- //
// -------------------------------------------- // // FIELDS
// FIELDS // -------------------------------------------- //
// -------------------------------------------- //
public String label; public String label;
public String world; public String world;
public double x[]; public double x[];
public double z[]; public double z[];
public String description; public String description;
public int lineColor; public int lineColor;
public double lineOpacity; public double lineOpacity;
public int lineWeight; public int lineWeight;
public int fillColor; public int fillColor;
public double fillOpacity; public double fillOpacity;
public boolean boost; public boolean boost;
// -------------------------------------------- // // -------------------------------------------- //
// CREATE // CREATE
// -------------------------------------------- // // -------------------------------------------- //
public AreaMarker create(MarkerSet markerset, String markerId) public AreaMarker create(MarkerSet markerset, String markerId) {
{ AreaMarker ret = markerset.createAreaMarker(markerId, this.label, false, this.world, this.x, this.z, false // not persistent
AreaMarker ret = markerset.createAreaMarker( );
markerId,
this.label,
false,
this.world,
this.x,
this.z,
false // not persistent
);
if (ret == null) return null; if (ret == null) {
return null;
}
// Description // Description
ret.setDescription(this.description); ret.setDescription(this.description);
// Line Style // Line Style
ret.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor); ret.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
// Fill Style // Fill Style
ret.setFillStyle(this.fillOpacity, this.fillColor); ret.setFillStyle(this.fillOpacity, this.fillColor);
// Boost Flag // Boost Flag
ret.setBoostFlag(this.boost); ret.setBoostFlag(this.boost);
return ret; return ret;
} }
// -------------------------------------------- // // -------------------------------------------- //
// UPDATE // UPDATE
// -------------------------------------------- // // -------------------------------------------- //
public void update(AreaMarker marker) public void update(AreaMarker marker) {
{ // Corner Locations
// Corner Locations if (!equals(marker, this.x, this.z)) {
if (!equals(marker, this.x, this.z)) marker.setCornerLocations(this.x, this.z);
{ }
marker.setCornerLocations(this.x, this.z);
}
// Label // Label
if (!marker.getLabel().equals(this.label)) if (!marker.getLabel().equals(this.label)) {
{ marker.setLabel(this.label);
marker.setLabel(this.label); }
}
// Description // Description
if (!marker.getDescription().equals( this.description)) if (!marker.getDescription().equals(this.description)) {
{ marker.setDescription(this.description);
marker.setDescription(this.description); }
}
// Line Style // Line Style
if if (marker.getLineWeight() != this.lineWeight ||
( marker.getLineOpacity() != this.lineOpacity ||
marker.getLineWeight()!=this.lineWeight marker.getLineColor() != this.lineColor) {
|| marker.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
marker.getLineOpacity()!=this.lineOpacity }
||
marker.getLineColor()!=this.lineColor
)
{
marker.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
}
// Fill Style // Fill Style
if if ((marker.getFillOpacity() != this.fillOpacity) || (marker.getFillColor() != this.fillColor)) {
( marker.setFillStyle(this.fillOpacity, this.fillColor);
(marker.getFillOpacity()!=this.fillOpacity) }
|| // Boost Flag
(marker.getFillColor()!=this.fillColor) if (marker.getBoostFlag() != this.boost) {
) marker.setBoostFlag(this.boost);
{ }
marker.setFillStyle(this.fillOpacity, this.fillColor); }
}
// Boost Flag
if (marker.getBoostFlag()!=this.boost)
{
marker.setBoostFlag(this.boost);
}
}
// -------------------------------------------- // // -------------------------------------------- //
// UTIL // UTIL
// -------------------------------------------- // // -------------------------------------------- //
public static boolean equals(AreaMarker marker, double x[], double z[]) public static boolean equals(AreaMarker marker, double x[], double z[]) {
{ int length = marker.getCornerCount();
int length = marker.getCornerCount();
if (x.length != length) return false; if (x.length != length) {
if (z.length != length) return false; return false;
}
if (z.length != length) {
return false;
}
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++) {
{ if (marker.getCornerX(i) != x[i]) {
if (marker.getCornerX(i) != x[i]) return false; return false;
if (marker.getCornerZ(i) != z[i]) return false; }
} if (marker.getCornerZ(i) != z[i]) {
return false;
}
}
return true; return true;
} }
} }

View File

@ -1,92 +1,74 @@
package com.massivecraft.factions.integration.dynmap; package com.massivecraft.factions.integration.dynmap;
import com.massivecraft.factions.Conf;
import org.dynmap.markers.Marker; import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerAPI;
import org.dynmap.markers.MarkerIcon; import org.dynmap.markers.MarkerIcon;
import org.dynmap.markers.MarkerSet; import org.dynmap.markers.MarkerSet;
import com.massivecraft.factions.Conf; public class TempMarker {
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
public class TempMarker public String label;
{ public String world;
// -------------------------------------------- // public double x;
// FIELDS public double y;
// -------------------------------------------- // public double z;
public String iconName;
public String description;
public String label; // -------------------------------------------- //
public String world; // CREATE
public double x; // -------------------------------------------- //
public double y;
public double z;
public String iconName;
public String description;
// -------------------------------------------- // public Marker create(MarkerAPI markerApi, MarkerSet markerset, String markerId) {
// CREATE Marker ret = markerset.createMarker(markerId, this.label, this.world, this.x, this.y, this.z, getMarkerIcon(markerApi, this.iconName), false // not persistent
// -------------------------------------------- // );
public Marker create(MarkerAPI markerApi, MarkerSet markerset, String markerId) if (ret == null) {
{ return null;
Marker ret = markerset.createMarker( }
markerId,
this.label,
this.world,
this.x,
this.y,
this.z,
getMarkerIcon(markerApi, this.iconName),
false // not persistent
);
if (ret == null) return null; ret.setDescription(this.description);
ret.setDescription(this.description); return ret;
}
return ret; // -------------------------------------------- //
} // UPDATE
// -------------------------------------------- //
// -------------------------------------------- // public void update(MarkerAPI markerApi, Marker marker) {
// UPDATE if (!this.world.equals(marker.getWorld()) || this.x != marker.getX() || this.y != marker.getY() || this.z != marker.getZ()) {
// -------------------------------------------- // marker.setLocation(this.world, this.x, this.y, this.z);
}
public void update(MarkerAPI markerApi, Marker marker) if (!marker.getLabel().equals(this.label)) {
{ marker.setLabel(this.label);
if (!this.world.equals(marker.getWorld()) || this.x != marker.getX() || this.y != marker.getY() || this.z != marker.getZ()) }
{
marker.setLocation(
this.world,
this.x,
this.y,
this.z
);
}
if (!marker.getLabel().equals(this.label)) MarkerIcon icon = getMarkerIcon(markerApi, this.iconName);
{ if (marker.getMarkerIcon() == null || marker.getMarkerIcon().equals(icon)) {
marker.setLabel(this.label); marker.setMarkerIcon(icon);
} }
MarkerIcon icon = getMarkerIcon(markerApi, this.iconName); if (!marker.getDescription().equals(this.description)) {
if (marker.getMarkerIcon()==null||marker.getMarkerIcon().equals(icon)) marker.setDescription(this.description);
{ }
marker.setMarkerIcon(icon); }
}
if (!marker.getDescription().equals(this.description)) // -------------------------------------------- //
{ // UTIL
marker.setDescription(this.description); // -------------------------------------------- //
}
}
// -------------------------------------------- // public static MarkerIcon getMarkerIcon(MarkerAPI markerApi, String name) {
// UTIL MarkerIcon ret = markerApi.getMarkerIcon(name);
// -------------------------------------------- // if (ret == null) {
ret = markerApi.getMarkerIcon(Conf.DYNMAP_STYLE_HOME_MARKER);
public static MarkerIcon getMarkerIcon(MarkerAPI markerApi, String name) }
{ return ret;
MarkerIcon ret = markerApi.getMarkerIcon(name); }
if (ret == null) ret = markerApi.getMarkerIcon(Conf.DYNMAP_STYLE_HOME_MARKER);
return ret;
}
} }

View File

@ -3,60 +3,53 @@ package com.massivecraft.factions.integration.dynmap;
import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerAPI;
import org.dynmap.markers.MarkerSet; import org.dynmap.markers.MarkerSet;
public class TempMarkerSet public class TempMarkerSet {
{
public String label; public String label;
public int minimumZoom; public int minimumZoom;
public int priority; public int priority;
public boolean hideByDefault; public boolean hideByDefault;
public MarkerSet create(MarkerAPI markerApi, String id) public MarkerSet create(MarkerAPI markerApi, String id) {
{ MarkerSet ret = markerApi.createMarkerSet(id, this.label, null, false); // ("null, false" at the end means "all icons allowed, not perisistent")
MarkerSet ret = markerApi.createMarkerSet(id, this.label, null, false); // ("null, false" at the end means "all icons allowed, not perisistent")
if (ret == null) return null; if (ret == null) {
return null;
}
// Minimum Zoom // Minimum Zoom
if (this.minimumZoom > 0) if (this.minimumZoom > 0) {
{ ret.setMinZoom(this.minimumZoom);
ret.setMinZoom(this.minimumZoom); }
}
// Priority // Priority
ret.setLayerPriority(this.priority); ret.setLayerPriority(this.priority);
// Hide by Default // Hide by Default
ret.setHideByDefault(this.hideByDefault); ret.setHideByDefault(this.hideByDefault);
return ret; return ret;
} }
public void update(MarkerSet markerset) public void update(MarkerSet markerset) {
{ // Name
// Name if (!markerset.getMarkerSetLabel().equals(this.label)) {
if (!markerset.getMarkerSetLabel().equals(this.label)) markerset.setMarkerSetLabel(this.label);
{ }
markerset.setMarkerSetLabel(this.label);
}
if (this.minimumZoom > 0) if (this.minimumZoom > 0) {
{ if (markerset.getMinZoom() != this.minimumZoom) {
if (markerset.getMinZoom()!=this.minimumZoom) markerset.setMinZoom(this.minimumZoom);
{ }
markerset.setMinZoom(this.minimumZoom); }
}
}
if (markerset.getLayerPriority()!=this.priority) if (markerset.getLayerPriority() != this.priority) {
{ markerset.setLayerPriority(this.priority);
markerset.setLayerPriority(this.priority); }
}
if (markerset.getHideByDefault()!=this.hideByDefault) if (markerset.getHideByDefault() != this.hideByDefault) {
{ markerset.setHideByDefault(this.hideByDefault);
markerset.setHideByDefault(this.hideByDefault); }
} }
}
} }

View File

@ -99,9 +99,9 @@ public class FactionsBlockListener implements Listener {
Location targetLoc = event.getRetractLocation(); Location targetLoc = event.getRetractLocation();
Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(targetLoc)); Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(targetLoc));
// Check if the piston is moving in a faction's territory. This disables pistons entirely in faction territory. // Check if the piston is moving in a faction's territory. This disables pistons entirely in faction territory.
if(otherFaction.isNormal() && P.p.getConfig().getBoolean("disable-pistons-in-territory", false)) { if (otherFaction.isNormal() && P.p.getConfig().getBoolean("disable-pistons-in-territory", false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }

View File

@ -36,7 +36,8 @@ public class BufferedObjective {
Method addEntryMethodLookup = null; Method addEntryMethodLookup = null;
try { try {
addEntryMethodLookup = Team.class.getMethod("addEntry", String.class); addEntryMethodLookup = Team.class.getMethod("addEntry", String.class);
} catch (NoSuchMethodException ignored) {} } catch (NoSuchMethodException ignored) {
}
addEntryMethod = addEntryMethodLookup; addEntryMethod = addEntryMethodLookup;
@ -130,7 +131,8 @@ public class BufferedObjective {
try { try {
addEntryMethod.invoke(team, name); addEntryMethod.invoke(team, name);
} catch (ReflectiveOperationException ignored) {} } catch (ReflectiveOperationException ignored) {
}
buffer.getScore(name).setScore(entry.getKey()); buffer.getScore(name).setScore(entry.getKey());
} else { } else {
buffer.getScore(entry.getValue()).setScore(entry.getKey()); buffer.getScore(entry.getValue()).setScore(entry.getKey());

View File

@ -2,7 +2,6 @@ package com.massivecraft.factions.util;
import com.massivecraft.factions.*; import com.massivecraft.factions.*;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -11,7 +11,6 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.logging.Level;
public abstract class MemoryBoard extends Board { public abstract class MemoryBoard extends Board {
@ -48,8 +47,8 @@ public abstract class MemoryBoard extends Board {
public void removeAt(FLocation flocation) { public void removeAt(FLocation flocation) {
Faction faction = getFactionAt(flocation); Faction faction = getFactionAt(flocation);
for(LazyLocation loc : faction.getWarps().values()) { for (LazyLocation loc : faction.getWarps().values()) {
if(flocation.isInChunk(loc.getLocation())) { if (flocation.isInChunk(loc.getLocation())) {
faction.removeWarp(loc); faction.removeWarp(loc);
} }
} }

View File

@ -93,7 +93,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
} }
public boolean removeWarp(LazyLocation loc) { public boolean removeWarp(LazyLocation loc) {
if(warps.containsValue(loc)) { if (warps.containsValue(loc)) {
warps.remove(loc); warps.remove(loc);
return true; return true;
} }