Makes all faction warps show up as markers
Some checks failed
EpicKnarvik97/Dynmap-Factions/pipeline/head There was a failure building this commit

This commit is contained in:
Kristian Knarvik 2024-05-14 17:52:37 +02:00
parent 4ad841c867
commit 91fef8d349
3 changed files with 85 additions and 37 deletions

View File

@ -16,10 +16,12 @@ import org.jetbrains.annotations.Nullable;
* @param fillOpacity <p>The opacity of the filled-in area</p> * @param fillOpacity <p>The opacity of the filled-in area</p>
* @param homeMarker <p>The name of the icon to use for marking faction homes</p> * @param homeMarker <p>The name of the icon to use for marking faction homes</p>
* @param homeIcon <p>The icon to use for marking faction homes</p> * @param homeIcon <p>The icon to use for marking faction homes</p>
* @param boost * @param warpIcon <p>The icon to use for marking other faction warps</p>
* @param boost <p>Whether to boost the priority of this area style, I guess</p>
*/ */
public record AreaStyle(String strokeColor, double strokeOpacity, int strokeWeight, String fillColor, public record AreaStyle(String strokeColor, double strokeOpacity, int strokeWeight, String fillColor,
double fillOpacity, String homeMarker, MarkerIcon homeIcon, boolean boost) { double fillOpacity, String homeMarker, MarkerIcon homeIcon, MarkerIcon warpIcon,
boolean boost) {
/** /**
* Instantiates a new area style * Instantiates a new area style
@ -38,6 +40,7 @@ public record AreaStyle(String strokeColor, double strokeOpacity, int strokeWeig
cfg.getDouble(path + ".fillOpacity", def.fillOpacity), cfg.getDouble(path + ".fillOpacity", def.fillOpacity),
cfg.getString(path + ".homeIcon", def.homeMarker), cfg.getString(path + ".homeIcon", def.homeMarker),
getHomeIcon(dynmapFactionsPlugin, cfg.getString(path + ".homeIcon", def.homeMarker)), getHomeIcon(dynmapFactionsPlugin, cfg.getString(path + ".homeIcon", def.homeMarker)),
getWarpIcon(dynmapFactionsPlugin, cfg.getString(path + ".warpIcon", def.homeMarker)),
cfg.getBoolean(path + ".boost", def.boost)); cfg.getBoolean(path + ".boost", def.boost));
} }
@ -57,6 +60,7 @@ public record AreaStyle(String strokeColor, double strokeOpacity, int strokeWeig
cfg.getDouble(path + ".fillOpacity", 0.35), cfg.getDouble(path + ".fillOpacity", 0.35),
cfg.getString(path + ".homeIcon", null), cfg.getString(path + ".homeIcon", null),
getHomeIcon(dynmapFactionsPlugin, cfg.getString(path + ".homeIcon", null)), getHomeIcon(dynmapFactionsPlugin, cfg.getString(path + ".homeIcon", null)),
getWarpIcon(dynmapFactionsPlugin, cfg.getString(path + ".warpIcon", null)),
cfg.getBoolean(path + ".boost", false)); cfg.getBoolean(path + ".boost", false));
} }
@ -70,12 +74,38 @@ public record AreaStyle(String strokeColor, double strokeOpacity, int strokeWeig
@Nullable @Nullable
private static MarkerIcon getHomeIcon(@NotNull DynmapFactionsPlugin dynmapFactionsPlugin, private static MarkerIcon getHomeIcon(@NotNull DynmapFactionsPlugin dynmapFactionsPlugin,
@Nullable String homeMarker) { @Nullable String homeMarker) {
return getIcon(dynmapFactionsPlugin, homeMarker, "redflag");
}
/**
* Gets the icon to use for marking a faction warp
*
* @param dynmapFactionsPlugin <p>An instance of the dynmap factions plugin</p>
* @param warpMarker <p>The name of the marker to get</p>
* @return <p>The marker, or null if it does not exist</p>
*/
@Nullable
private static MarkerIcon getWarpIcon(@NotNull DynmapFactionsPlugin dynmapFactionsPlugin,
@Nullable String warpMarker) {
return getIcon(dynmapFactionsPlugin, warpMarker, "orangeflag");
}
/**
* Gets the icon to use for marking a faction warp
*
* @param dynmapFactionsPlugin <p>An instance of the dynmap factions plugin</p>
* @param warpMarker <p>The name of the marker to get</p>
* @return <p>The marker, or null if it does not exist</p>
*/
@Nullable
private static MarkerIcon getIcon(@NotNull DynmapFactionsPlugin dynmapFactionsPlugin,
@Nullable String warpMarker, @NotNull String defaultIcon) {
MarkerIcon homeIcon = null; MarkerIcon homeIcon = null;
if (homeMarker != null) { if (warpMarker != null) {
homeIcon = dynmapFactionsPlugin.getMarkerAPI().getMarkerIcon(homeMarker); homeIcon = dynmapFactionsPlugin.getMarkerAPI().getMarkerIcon(warpMarker);
if (homeIcon == null) { if (homeIcon == null) {
DynmapFactionsPlugin.severe("Invalid home icon: " + homeMarker); DynmapFactionsPlugin.severe("Invalid icon: " + warpMarker);
homeIcon = dynmapFactionsPlugin.getMarkerAPI().getMarkerIcon("blueicon"); homeIcon = dynmapFactionsPlugin.getMarkerAPI().getMarkerIcon(defaultIcon);
} }
} }
return homeIcon; return homeIcon;

View File

@ -108,35 +108,9 @@ public class FactionsUpdate implements Runnable {
/* Now, add marker for home location */ /* Now, add marker for home location */
EntityInternalMap<Warp> warps = faction.getWarps(); EntityInternalMap<Warp> warps = faction.getWarps();
Warp home = null; for (String warpId : warps.keySet()) {
for (String warp : warps.keySet()) { Warp warp = warps.get(warpId);
if (warp.equalsIgnoreCase("home")) { markWarp(warp, fc, faction, newMarkers, warp.getName().equalsIgnoreCase("home"));
home = warps.get(warp);
}
}
if (home == null) {
continue;
}
PS homeLocation = home.getLocation();
if (homeLocation != null) {
String markId = fc.getUniverse() + "_" + factionName + "__home";
MarkerIcon ico = getMarkerIcon(factionName);
if (ico != null) {
Marker homeMarker = dynmapFactionsPlugin.getFactionMarkers().remove(markId);
String lbl = factionName + " [home]";
if (homeMarker == null) {
homeMarker = dynmapFactionsPlugin.getSet().createMarker(markId, lbl, homeLocation.getWorld(),
homeLocation.getLocationX(), homeLocation.getLocationY(), homeLocation.getLocationZ(), ico, false);
} else {
homeMarker.setLocation(homeLocation.getWorld(), homeLocation.getLocationX(), homeLocation.getLocationY(), homeLocation.getLocationZ());
homeMarker.setLabel(lbl); /* Update label */
homeMarker.setMarkerIcon(ico);
}
if (homeMarker != null) {
homeMarker.setDescription(formatInfoWindow(faction)); /* Set popup */
newMarkers.put(markId, homeMarker);
}
}
} }
} }
blocksByFaction.clear(); blocksByFaction.clear();
@ -151,7 +125,45 @@ public class FactionsUpdate implements Runnable {
/* And replace with new map */ /* And replace with new map */
dynmapFactionsPlugin.setFactionAreaMarkers(newMap); dynmapFactionsPlugin.setFactionAreaMarkers(newMap);
dynmapFactionsPlugin.setFactionMarkers(newMarkers); dynmapFactionsPlugin.setFactionMarkers(newMarkers);
}
/**
* Marks a faction warp with an icon
*
* @param warp <p>The warp to mark</p>
* @param fc <p>The FactionColl to get info from</p>
* @param faction <p>The faction the warp belongs to</p>
* @param newMarkers <p>The new markers map to add the marker to</p>
* @param isHome <p>Whether the warp is the home warp</p>
*/
private void markWarp(Warp warp, FactionColl fc, Faction faction, Map<String, Marker> newMarkers, boolean isHome) {
String factionName = faction.getName();
PS warpLocation = warp.getLocation();
if (warpLocation == null) {
return;
}
String markId = fc.getUniverse() + "_" + factionName + "__" + warp.getName();
MarkerIcon markerIcon = getMarkerIcon(factionName, isHome);
if (markerIcon == null) {
return;
}
Marker warpMarker = dynmapFactionsPlugin.getFactionMarkers().remove(markId);
String label = factionName + " [" + warp.getName() + "]";
if (warpMarker == null) {
warpMarker = dynmapFactionsPlugin.getSet().createMarker(markId, label, warpLocation.getWorld(),
warpLocation.getLocationX(), warpLocation.getLocationY(), warpLocation.getLocationZ(), markerIcon, false);
} else {
warpMarker.setLocation(warpLocation.getWorld(), warpLocation.getLocationX(), warpLocation.getLocationY(),
warpLocation.getLocationZ());
warpMarker.setLabel(label); /* Update label */
warpMarker.setMarkerIcon(markerIcon);
}
if (warpMarker != null) {
warpMarker.setDescription(formatInfoWindow(faction)); /* Set popup */
newMarkers.put(markId, warpMarker);
}
} }
/* Handle specific faction on specific world */ /* Handle specific faction on specific world */
@ -356,12 +368,16 @@ public class FactionsUpdate implements Runnable {
areaMarker.setBoostFlag(as.boost()); areaMarker.setBoostFlag(as.boost());
} }
private MarkerIcon getMarkerIcon(String factionName) { private MarkerIcon getMarkerIcon(String factionName, boolean isHome) {
AreaStyle as = dynmapFactionsPlugin.getCustomStyle().get(factionName); AreaStyle as = dynmapFactionsPlugin.getCustomStyle().get(factionName);
if (as == null) { if (as == null) {
as = dynmapFactionsPlugin.getDefaultStyle(); as = dynmapFactionsPlugin.getDefaultStyle();
} }
if (isHome) {
return as.homeIcon(); return as.homeIcon();
} else {
return as.warpIcon();
}
} }
private boolean isVisible(String id, String worldName) { private boolean isVisible(String id, String worldName) {

View File

@ -19,6 +19,7 @@ infoWindow: '<div class="infoWindow"><span style="font-size:120%;">%regionName%<
# Allow players in faction to see one another on dynmap (only relevant if dynmap has 'player-info-protected' enabled) # Allow players in faction to see one another on dynmap (only relevant if dynmap has 'player-info-protected' enabled)
visibilityByFaction: true visibilityByFaction: true
# The default style for all faction regions
regionStyle: regionStyle:
strokeColor: "#FF0000" strokeColor: "#FF0000"
strokeOpacity: 0.8 strokeOpacity: 0.8
@ -26,6 +27,7 @@ regionStyle:
fillColor: "#FF0000" fillColor: "#FF0000"
fillOpacity: 0.35 fillOpacity: 0.35
homeIcon: "redflag" homeIcon: "redflag"
warpIcon: "orangeflag"
boost: false boost: false
# Optional setting to limit which regions to show, by name - if commented out, all regions are shown # Optional setting to limit which regions to show, by name - if commented out, all regions are shown