From 395f45b0f9912e147b1d6c35d5628add765bfb14 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Mon, 25 May 2020 18:52:28 -0500 Subject: [PATCH] Add support for greeting/farewell on circle markers --- .../dynmap/markers/impl/AreaMarkerImpl.java | 10 ++ .../dynmap/markers/impl/CircleMarkerImpl.java | 97 ++++++++++++++++++- .../dynmap/markers/impl/MarkerAPIImpl.java | 33 ++++++- .../org/dynmap/markers/impl/MarkerImpl.java | 10 ++ .../dynmap/markers/impl/MarkerSetImpl.java | 24 ++++- .../markers/impl/PolyLineMarkerImpl.java | 10 ++ .../java/org/dynmap/markers/CircleMarker.java | 2 +- .../org/dynmap/markers/GenericMarker.java | 4 + 8 files changed, 183 insertions(+), 7 deletions(-) diff --git a/DynmapCore/src/main/java/org/dynmap/markers/impl/AreaMarkerImpl.java b/DynmapCore/src/main/java/org/dynmap/markers/impl/AreaMarkerImpl.java index 519389a9..1473712a 100644 --- a/DynmapCore/src/main/java/org/dynmap/markers/impl/AreaMarkerImpl.java +++ b/DynmapCore/src/main/java/org/dynmap/markers/impl/AreaMarkerImpl.java @@ -170,6 +170,16 @@ class AreaMarkerImpl implements AreaMarker, EnterExitMarker { bb_cache = null; } + @Override + public String getUniqueMarkerID() { + if (markerset != null) { + return markerset + ":area:" + markerid; + } + else { + return null; + } + } + @Override public String getMarkerID() { return markerid; diff --git a/DynmapCore/src/main/java/org/dynmap/markers/impl/CircleMarkerImpl.java b/DynmapCore/src/main/java/org/dynmap/markers/impl/CircleMarkerImpl.java index dab996d7..b339878b 100644 --- a/DynmapCore/src/main/java/org/dynmap/markers/impl/CircleMarkerImpl.java +++ b/DynmapCore/src/main/java/org/dynmap/markers/impl/CircleMarkerImpl.java @@ -8,11 +8,13 @@ import org.dynmap.ConfigurationNode; import org.dynmap.DynmapWorld; import org.dynmap.hdmap.HDPerspective; import org.dynmap.markers.CircleMarker; +import org.dynmap.markers.EnterExitMarker; import org.dynmap.markers.MarkerSet; +import org.dynmap.markers.EnterExitMarker.EnterExitText; import org.dynmap.markers.impl.MarkerAPIImpl.MarkerUpdate; import org.dynmap.utils.Vector3D; -class CircleMarkerImpl implements CircleMarker { +class CircleMarkerImpl implements CircleMarker, EnterExitMarker { private String markerid; private String label; private boolean markup; @@ -34,6 +36,8 @@ class CircleMarkerImpl implements CircleMarker { private boolean boostflag = false; private int minzoom = -1; private int maxzoom = -1; + private EnterExitText greeting; + private EnterExitText farewell; private static class BoundingBox { double xmin, xmax; @@ -118,6 +122,20 @@ class CircleMarkerImpl implements CircleMarker { boostflag = node.getBoolean("boostFlag", false); minzoom = node.getInteger("minzoom", -1); maxzoom = node.getInteger("maxzoom", -1); + String gt = node.getString("greeting", null); + String gst = node.getString("greetingsub", null); + if ((gt != null) || (gst != null)) { + greeting = new EnterExitText(); + greeting.title = gt; + greeting.subtitle = gst; + } + String ft = node.getString("farewell", null); + String fst = node.getString("farewellsub", null); + if ((ft != null) || (fst != null)) { + farewell = new EnterExitText(); + farewell.title = ft; + farewell.subtitle = fst; + } ispersistent = true; /* Loaded from config, so must be */ @@ -129,6 +147,16 @@ class CircleMarkerImpl implements CircleMarker { bb_cache = null; } + @Override + public String getUniqueMarkerID() { + if (markerset != null) { + return markerset + ":circle:" + markerid; + } + else { + return null; + } + } + @Override public String getMarkerID() { return markerid; @@ -202,6 +230,22 @@ class CircleMarkerImpl implements CircleMarker { if (maxzoom >= 0) { node.put("maxzoom", maxzoom); } + if (greeting != null) { + if (greeting.title != null) { + node.put("greeting", greeting.title); + } + if (greeting.subtitle != null) { + node.put("greetingsub", greeting.subtitle); + } + } + if (farewell != null) { + if (farewell.title != null) { + node.put("farewell", farewell.title); + } + if (farewell.subtitle != null) { + node.put("farewellsub", farewell.subtitle); + } + } return node; } @Override @@ -450,4 +494,55 @@ class CircleMarkerImpl implements CircleMarker { if(ispersistent) MarkerAPIImpl.saveMarkers(); } + @Override + public EnterExitText getGreetingText() { + return greeting; + } + @Override + public EnterExitText getFarewellText() { + return farewell; + } + @Override + public void setGreetingText(String title, String subtitle) { + if ((title != null) || (subtitle != null)) { + greeting = new EnterExitText(); + greeting.title = title; + greeting.subtitle = subtitle; + } + else { + greeting = null; + } + if (markerset != null) { + setMarkerSet(markerset); + } + if(ispersistent) + MarkerAPIImpl.saveMarkers(); + } + @Override + public void setFarewellText(String title, String subtitle) { + if ((title != null) || (subtitle != null)) { + farewell = new EnterExitText(); + farewell.title = title; + farewell.subtitle = subtitle; + } + else { + farewell = null; + } + if (markerset != null) { + setMarkerSet(markerset); + } + if(ispersistent) + MarkerAPIImpl.saveMarkers(); + } + @Override + public boolean testIfPointWithinMarker(String worldid, double x, double y, double z) { + // Wrong world + if (!worldid.equals(this.world)) { + return false; + } + // Test if inside ellipse + double dx = ((x - this.x) * (x - this.x)) / (xr * xr); + double dz = ((z - this.z) * (z - this.z)) / (zr * zr); + return (dx + dz) <= 1.0; + } } diff --git a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java index f6543372..427c3f51 100644 --- a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java +++ b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java @@ -948,7 +948,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { } private static boolean processCircleArgs(DynmapCommandSender sender, CircleMarker marker, Map parms) { - String val = null; + String val = null, val2 = null; try { int scolor = marker.getLineColor(); int fcolor = marker.getFillColor(); @@ -964,6 +964,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { boolean boost = marker.getBoostFlag(); int minzoom = marker.getMinZoom(); int maxzoom = marker.getMaxZoom(); + EnterExitText greet = marker.getGreetingText(); + EnterExitText farew = marker.getFarewellText(); val = parms.get(ARG_STROKECOLOR); if(val != null) @@ -1026,6 +1028,23 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { marker.setBoostFlag(boost); marker.setMinZoom(minzoom); marker.setMaxZoom(maxzoom); + // Handle greeting + val = parms.get(ARG_GREETING); + val2 = parms.get(ARG_GREETINGSUB); + if ((val != null) || (val2 != null)) { + String title = (val != null) ? ((val.length() > 0) ? val : null) : ((greet != null) ? greet.title : null); + String subtitle = (val2 != null) ? ((val2.length() > 0) ? val2 : null) : ((greet != null) ? greet.subtitle : null); + marker.setGreetingText(title, subtitle); + } + // Handle farewell + val = parms.get(ARG_FAREWELL); + val2 = parms.get(ARG_FAREWELLSUB); + if ((val != null) || (val2 != null)) { + String title = (val != null) ? ((val.length() > 0) ? val : null) : ((farew != null) ? farew.title : null); + String subtitle = (val2 != null) ? ((val2.length() > 0) ? val2 : null) : ((farew != null) ? farew.subtitle : null); + marker.setFarewellText(title, subtitle); + } + } catch (NumberFormatException nfx) { sender.sendMessage("Invalid parameter format: " + val); return false; @@ -2625,7 +2644,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { CircleMarker m = sortmarkers.get(s); String msg = m.getMarkerID() + ": label:\"" + m.getLabel() + "\", set:" + m.getMarkerSet().getMarkerSetID() + ", world:" + m.getWorld() + ", center:" + m.getCenterX() + "/" + m.getCenterY() + "/" + m.getCenterZ() + - ", radius:" + m.getRadiusX() + "/" + m.getRadiusZ() + + ", radiusx:" + m.getRadiusX() + ", radiusz:" + m.getRadiusZ() + ", weight: " + m.getLineWeight() + ", color:" + String.format("%06x", m.getLineColor()) + ", opacity: " + m.getLineOpacity() + ", fillcolor: " + String.format("%06x", m.getFillColor()) + ", fillopacity: " + m.getFillOpacity() + ", boost:" + m.getBoostFlag() + ", markup:" + m.isLabelMarkup(); @@ -2635,6 +2654,16 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { if (m.getMaxZoom() >= 0) { msg += ", maxzoom:" + m.getMaxZoom(); } + EnterExitText t = m.getGreetingText(); + if (t != null) { + if (t.title != null) msg += ", greeting='" + t.title + "'"; + if (t.subtitle != null) msg += ", greetingsub='" + t.subtitle + "'"; + } + t = m.getFarewellText(); + if (t != null) { + if (t.title != null) msg += ", farewell='" + t.title + "'"; + if (t.subtitle != null) msg += ", farewellsub='" + t.subtitle + "'"; + } sender.sendMessage(msg); } return true; diff --git a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerImpl.java b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerImpl.java index c698cfdc..d9ef4512 100644 --- a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerImpl.java +++ b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerImpl.java @@ -98,6 +98,16 @@ class MarkerImpl implements Marker { markerset = null; } + @Override + public String getUniqueMarkerID() { + if (markerset != null) { + return markerset + ":marker:" + markerid; + } + else { + return null; + } + } + @Override public String getMarkerID() { return markerid; diff --git a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java index 5dd3e035..0708a36e 100644 --- a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java +++ b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java @@ -278,7 +278,7 @@ class MarkerSetImpl implements MarkerSet { if (enterexitmarkers == null) { enterexitmarkers = new ConcurrentHashMap(); } - enterexitmarkers.put(marker.getMarkerID(), marker); + enterexitmarkers.put(marker.getUniqueMarkerID(), marker); } if(ispersistent && marker.isPersistentMarker()) { /* If persistent */ MarkerAPIImpl.saveMarkers(); /* Drive save */ @@ -299,7 +299,7 @@ class MarkerSetImpl implements MarkerSet { } } if (enterexitmarkers != null) { - enterexitmarkers.remove(marker.getMarkerID()); + enterexitmarkers.remove(marker.getUniqueMarkerID()); if (enterexitmarkers.isEmpty()) { enterexitmarkers = null; } @@ -346,6 +346,12 @@ class MarkerSetImpl implements MarkerSet { } boostingcirclemarkers.put(marker.getMarkerID(), marker); } + if ((marker.getGreetingText() != null) || (marker.getFarewellText() != null)) { + if (enterexitmarkers == null) { + enterexitmarkers = new ConcurrentHashMap(); + } + enterexitmarkers.put(marker.getUniqueMarkerID(), marker); + } if(ispersistent && marker.isPersistentMarker()) { /* If persistent */ MarkerAPIImpl.saveMarkers(); /* Drive save */ } @@ -364,6 +370,12 @@ class MarkerSetImpl implements MarkerSet { boostingcirclemarkers = null; } } + if (enterexitmarkers != null) { + enterexitmarkers.remove(marker.getUniqueMarkerID()); + if (enterexitmarkers.isEmpty()) { + enterexitmarkers = null; + } + } if(ispersistent && marker.isPersistentMarker()) { /* If persistent */ MarkerAPIImpl.saveMarkers(); /* Drive save */ } @@ -468,7 +480,7 @@ class MarkerSetImpl implements MarkerSet { if (enterexitmarkers == null) { enterexitmarkers = new ConcurrentHashMap(); } - enterexitmarkers.put(marker.getMarkerID(), marker); + enterexitmarkers.put(marker.getUniqueMarkerID(), marker); } } else { @@ -502,6 +514,12 @@ class MarkerSetImpl implements MarkerSet { } boostingcirclemarkers.put(id, marker); } + if ((marker.getGreetingText() != null) || (marker.getFarewellText() != null)) { + if (enterexitmarkers == null) { + enterexitmarkers = new ConcurrentHashMap(); + } + enterexitmarkers.put(marker.getUniqueMarkerID(), marker); + } } else { Log.info("Error loading circle marker '" + id + "' for set '" + setid + "'"); diff --git a/DynmapCore/src/main/java/org/dynmap/markers/impl/PolyLineMarkerImpl.java b/DynmapCore/src/main/java/org/dynmap/markers/impl/PolyLineMarkerImpl.java index 5a5a7647..6575ed29 100644 --- a/DynmapCore/src/main/java/org/dynmap/markers/impl/PolyLineMarkerImpl.java +++ b/DynmapCore/src/main/java/org/dynmap/markers/impl/PolyLineMarkerImpl.java @@ -118,6 +118,16 @@ class PolyLineMarkerImpl implements PolyLineMarker { markerset = null; } + @Override + public String getUniqueMarkerID() { + if (markerset != null) { + return markerset + ":poly:" + markerid; + } + else { + return null; + } + } + @Override public String getMarkerID() { return markerid; diff --git a/DynmapCoreAPI/src/main/java/org/dynmap/markers/CircleMarker.java b/DynmapCoreAPI/src/main/java/org/dynmap/markers/CircleMarker.java index 27536b09..a5871884 100644 --- a/DynmapCoreAPI/src/main/java/org/dynmap/markers/CircleMarker.java +++ b/DynmapCoreAPI/src/main/java/org/dynmap/markers/CircleMarker.java @@ -3,7 +3,7 @@ package org.dynmap.markers; /** * This defines the public interface to a circle marker object, for use with the MarkerAPI */ -public interface CircleMarker extends MarkerDescription { +public interface CircleMarker extends MarkerDescription, EnterExitMarker { /** * Get center X coordinate * @return x coordinate diff --git a/DynmapCoreAPI/src/main/java/org/dynmap/markers/GenericMarker.java b/DynmapCoreAPI/src/main/java/org/dynmap/markers/GenericMarker.java index c24300cd..49011fb7 100644 --- a/DynmapCoreAPI/src/main/java/org/dynmap/markers/GenericMarker.java +++ b/DynmapCoreAPI/src/main/java/org/dynmap/markers/GenericMarker.java @@ -4,6 +4,10 @@ package org.dynmap.markers; * This defines the public interface to a generic marker object, for use with the MarkerAPI */ public interface GenericMarker { + /** + * Get unique ID of the marker (markersetid:type:markerid) + */ + public String getUniqueMarkerID(); /** * Get ID of the marker (unique string within the MarkerSet) * @return id of marker