From 14f55bd6a8813810b5b8f59daa0d3d017bb8d7c8 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Mon, 25 May 2020 01:14:20 -0500 Subject: [PATCH] Initial work on greeting/farewall title support for areas --- .../main/java/org/dynmap/DynmapLocation.java | 3 + .../src/main/java/org/dynmap/MapManager.java | 44 +++++++ .../src/main/java/org/dynmap/PlayerList.java | 7 +- .../dynmap/markers/impl/AreaMarkerImpl.java | 120 +++++++++++++++++- .../dynmap/markers/impl/MarkerAPIImpl.java | 15 +++ .../dynmap/markers/impl/MarkerSetImpl.java | 39 +++++- .../org/dynmap/markers/EnterExitMarker.java | 28 ++++ .../java/org/dynmap/markers/MarkerSet.java | 4 + .../org.eclipse.buildship.core.prefs | 13 +- forge-1.13.2/build.gradle | 3 - forge-1.13.2/src/main/resources/dynmap_at.cfg | 4 - forge-1.14.4/build.gradle | 3 - forge-1.15.2/.gitignore | 2 + forge-1.15.2/build.gradle | 3 - 14 files changed, 269 insertions(+), 19 deletions(-) create mode 100644 DynmapCoreAPI/src/main/java/org/dynmap/markers/EnterExitMarker.java delete mode 100644 forge-1.13.2/src/main/resources/dynmap_at.cfg diff --git a/DynmapCore/src/main/java/org/dynmap/DynmapLocation.java b/DynmapCore/src/main/java/org/dynmap/DynmapLocation.java index 89f41e8c..1f60c8ee 100644 --- a/DynmapCore/src/main/java/org/dynmap/DynmapLocation.java +++ b/DynmapCore/src/main/java/org/dynmap/DynmapLocation.java @@ -13,4 +13,7 @@ public class DynmapLocation { world = w; this.x = x; this.y = y; this.z = z; } + public String toString() { + return String.format("{%s,%f,%f,%f}", world, x, y, z); + } } diff --git a/DynmapCore/src/main/java/org/dynmap/MapManager.java b/DynmapCore/src/main/java/org/dynmap/MapManager.java index 5fbed325..1dd60898 100644 --- a/DynmapCore/src/main/java/org/dynmap/MapManager.java +++ b/DynmapCore/src/main/java/org/dynmap/MapManager.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.ConcurrentHashMap; @@ -32,6 +33,9 @@ import org.dynmap.common.DynmapListenerManager.EventType; import org.dynmap.debug.Debug; import org.dynmap.exporter.OBJExport; import org.dynmap.hdmap.HDMapManager; +import org.dynmap.markers.EnterExitMarker; +import org.dynmap.markers.EnterExitMarker.EnterExitText; +import org.dynmap.markers.impl.MarkerAPIImpl; import org.dynmap.renderer.DynmapBlockState; import org.dynmap.storage.MapStorage; import org.dynmap.storage.MapStorageBaseTileEnumCB; @@ -930,7 +934,46 @@ public class MapManager { scheduleDelayedJob(this, 1000); /* Once per second */ } } + + private HashMap> entersetstate = new HashMap>(); + private class DoUserMoveProcessing implements Runnable { + public void run() { + HashMap> newstate = new HashMap>(); + DynmapPlayer[] pl = core.playerList.getOnlinePlayers(); + for (DynmapPlayer player : pl) { + if (player == null) continue; + UUID puuid = player.getUUID(); + HashSet newset = new HashSet(); + DynmapLocation dl = player.getLocation(); + if (dl != null) { + MarkerAPIImpl.getEnteredMarkers(dl.world, dl.x, dl.y, dl.z, newset); + } + HashSet oldset = entersetstate.get(puuid); + // See which we just entered + for (EnterExitMarker m : newset) { + EnterExitText txt = m.getGreetingText(); + if ((txt != null) && ((oldset == null) || (oldset.contains(m) == false))) { + Log.info(String.format("User %s enter: %s - %s", player.getName(), txt.title, txt.subtitle)); + } + } + // See which we just left + if (oldset != null) { + for (EnterExitMarker m : oldset) { + EnterExitText txt = m.getFarewellText(); + if ((txt != null) && (newset.contains(m) == false)) { + Log.info(String.format("User %s exit: %s - %s", player.getName(), txt.title, txt.subtitle)); + } + } + } + newstate.put(puuid, newset); + } + entersetstate = newstate; // Replace old with new + + scheduleDelayedJob(this, 1000); /* Once per second */ + } + } + private void addNextTilesToUpdate(int cnt) { ArrayList tiles = new ArrayList(); TileFlags.TileCoord coord = new TileFlags.TileCoord(); @@ -1458,6 +1501,7 @@ public class MapManager { scheduleDelayedJob(new DoZoomOutProcessing(), 60000); scheduleDelayedJob(new CheckWorldTimes(), 5000); scheduleDelayedJob(new DoTouchProcessing(), 1000); + scheduleDelayedJob(new DoUserMoveProcessing(), 1000); /* Resume pending jobs */ for(FullWorldRenderState job : active_renders.values()) { scheduleDelayedJob(job, 5000); diff --git a/DynmapCore/src/main/java/org/dynmap/PlayerList.java b/DynmapCore/src/main/java/org/dynmap/PlayerList.java index 7f3cec4e..bcf467a2 100644 --- a/DynmapCore/src/main/java/org/dynmap/PlayerList.java +++ b/DynmapCore/src/main/java/org/dynmap/PlayerList.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -119,7 +120,11 @@ public class PlayerList { } } } - + + public DynmapPlayer[] getOnlinePlayers() { + return Arrays.copyOf(online, online.length); + } + public List getVisiblePlayers(String worldName) { ArrayList visiblePlayers = new ArrayList(); DynmapPlayer[] onlinePlayers = online; /* Use copied list - we don't call from server thread */ 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 41f17ef6..e1464479 100644 --- a/DynmapCore/src/main/java/org/dynmap/markers/impl/AreaMarkerImpl.java +++ b/DynmapCore/src/main/java/org/dynmap/markers/impl/AreaMarkerImpl.java @@ -8,14 +8,16 @@ import java.util.concurrent.ConcurrentHashMap; import org.dynmap.ConfigurationNode; import org.dynmap.DynmapWorld; +import org.dynmap.Log; import org.dynmap.MapManager; import org.dynmap.hdmap.HDPerspective; import org.dynmap.markers.AreaMarker; +import org.dynmap.markers.EnterExitMarker; import org.dynmap.markers.MarkerSet; import org.dynmap.markers.impl.MarkerAPIImpl.MarkerUpdate; import org.dynmap.utils.Vector3D; -class AreaMarkerImpl implements AreaMarker { +class AreaMarkerImpl implements AreaMarker, EnterExitMarker { private String markerid; private String label; private boolean markup; @@ -35,6 +37,9 @@ class AreaMarkerImpl implements AreaMarker { private boolean boostflag = false; private int minzoom; private int maxzoom; + private EnterExitText greeting; + private EnterExitText farewell; + private static class Coord { double x, z; @@ -85,6 +90,8 @@ class AreaMarkerImpl implements AreaMarker { } this.minzoom = -1; this.maxzoom = -1; + this.greeting = null; + this.farewell = null; } /** * Make bare area marker - used for persistence load @@ -101,6 +108,8 @@ class AreaMarkerImpl implements AreaMarker { world = normalized_world = "world"; this.minzoom = -1; this.maxzoom = -1; + this.greeting = null; + this.farewell = null; } /** * Load marker from configuration node @@ -132,7 +141,21 @@ class AreaMarkerImpl implements AreaMarker { 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 */ return true; @@ -223,6 +246,23 @@ class AreaMarkerImpl implements AreaMarker { 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 @@ -522,4 +562,80 @@ class AreaMarkerImpl implements AreaMarker { 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; + } + // If Y is in range (if there is a range) + if ((ytop != ybottom) && ((y < ybottom) || (y > ytop))) { + return false; + } + // Test if inside polygon + int nvert = corners.size(); + int i, j; + Coord v0, v1; + boolean c = false; + if (nvert == 2) { // Diagonal corners (simple rectangle + v0 = corners.get(0); + v1 = corners.get(1); + if (((v0.x > x) != (v1.x > x)) && + ((v0.z > z) != (v1.z > z))) { + c = true; + } + } + else { + for (i = 0, j = nvert-1; i < nvert; j = i++) { + v0 = corners.get(i); + v1 = corners.get(j); + if (((v0.z > z) != (v1.z > z)) && + (((x - v0.x) * (v1.z - v0.z)) < + ((v1.x - v0.x) * (z - v0.z)))) { + c = !c; + } + } + } + return c; + } } 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 d22d7af3..3c660f8d 100644 --- a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java +++ b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java @@ -36,6 +36,7 @@ import org.dynmap.common.DynmapPlayer; import org.dynmap.hdmap.HDPerspective; import org.dynmap.markers.AreaMarker; import org.dynmap.markers.CircleMarker; +import org.dynmap.markers.EnterExitMarker; import org.dynmap.markers.Marker; import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerDescription; @@ -3216,4 +3217,18 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { } return false; } + /** + * Build entered marker set based on given location + * @param worldid - world + * @param x + * @param y + * @param z + * @param entered + */ + public static void getEnteredMarkers(String worldid, double x, double y, double z, Set entered) { + if (api == null) return; + for(MarkerSetImpl ms : api.markersets.values()) { + ms.addEnteredMarkers(entered, worldid, x, y, z); + } + } } 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 b6e6d536..5dd3e035 100644 --- a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java +++ b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java @@ -14,6 +14,7 @@ import org.dynmap.Log; import org.dynmap.hdmap.HDPerspective; import org.dynmap.markers.AreaMarker; import org.dynmap.markers.CircleMarker; +import org.dynmap.markers.EnterExitMarker; import org.dynmap.markers.PolyLineMarker; import org.dynmap.markers.Marker; import org.dynmap.markers.MarkerIcon; @@ -27,6 +28,7 @@ class MarkerSetImpl implements MarkerSet { private ConcurrentHashMap circlemarkers = new ConcurrentHashMap(); private ConcurrentHashMap boostingareamarkers = null; private ConcurrentHashMap boostingcirclemarkers = null; + private ConcurrentHashMap enterexitmarkers = null; private String setid; private String label; private ConcurrentHashMap allowedicons = null; @@ -80,6 +82,10 @@ class MarkerSetImpl implements MarkerSet { boostingcirclemarkers.clear(); boostingcirclemarkers = null; } + if (enterexitmarkers != null) { + enterexitmarkers.clear(); + enterexitmarkers = null; + } deficon = null; } @@ -268,6 +274,12 @@ class MarkerSetImpl implements MarkerSet { } boostingareamarkers.put(marker.getMarkerID(), marker); } + if ((marker.getGreetingText() != null) || (marker.getFarewellText() != null)) { + if (enterexitmarkers == null) { + enterexitmarkers = new ConcurrentHashMap(); + } + enterexitmarkers.put(marker.getMarkerID(), marker); + } if(ispersistent && marker.isPersistentMarker()) { /* If persistent */ MarkerAPIImpl.saveMarkers(); /* Drive save */ } @@ -286,7 +298,13 @@ class MarkerSetImpl implements MarkerSet { boostingareamarkers = null; } } - if(ispersistent && marker.isPersistentMarker()) { /* If persistent */ + if (enterexitmarkers != null) { + enterexitmarkers.remove(marker.getMarkerID()); + if (enterexitmarkers.isEmpty()) { + enterexitmarkers = null; + } + } + if (ispersistent && marker.isPersistentMarker()) { /* If persistent */ MarkerAPIImpl.saveMarkers(); /* Drive save */ } MarkerAPIImpl.areaMarkerUpdated(marker, MarkerUpdate.DELETED); @@ -446,6 +464,12 @@ class MarkerSetImpl implements MarkerSet { } boostingareamarkers.put(id, marker); } + if ((marker.getGreetingText() != null) || (marker.getFarewellText() != null)) { + if (enterexitmarkers == null) { + enterexitmarkers = new ConcurrentHashMap(); + } + enterexitmarkers.put(marker.getMarkerID(), marker); + } } else { Log.info("Error loading area marker '" + id + "' for set '" + setid + "'"); @@ -745,5 +769,16 @@ class MarkerSetImpl implements MarkerSet { } return false; } - + /** + * Add entered markers to set based on given coordinates + */ + @Override + public void addEnteredMarkers(Set entered, String worldid, double x, double y, double z) { + if (enterexitmarkers == null) return; + for (EnterExitMarker m : enterexitmarkers.values()) { + if (m.testIfPointWithinMarker(worldid, x, y, z)) { + entered.add(m); + } + } + } } diff --git a/DynmapCoreAPI/src/main/java/org/dynmap/markers/EnterExitMarker.java b/DynmapCoreAPI/src/main/java/org/dynmap/markers/EnterExitMarker.java new file mode 100644 index 00000000..93b20372 --- /dev/null +++ b/DynmapCoreAPI/src/main/java/org/dynmap/markers/EnterExitMarker.java @@ -0,0 +1,28 @@ +package org.dynmap.markers; + +public interface EnterExitMarker { + public static class EnterExitText { + public String title; + public String subtitle; + }; + /** + * Greeting text, if defined + */ + public EnterExitText getGreetingText(); + /** + * Farewell text, if defined + */ + public EnterExitText getFarewellText(); + /** + * Set greeting text + */ + public void setGreetingText(String title, String subtitle); + /** + * Set greeting text + */ + public void setFarewellText(String title, String subtitle); + /** + * Test if point is inside marker volume + */ + public boolean testIfPointWithinMarker(String worldid, double x, double y, double z); +}; diff --git a/DynmapCoreAPI/src/main/java/org/dynmap/markers/MarkerSet.java b/DynmapCoreAPI/src/main/java/org/dynmap/markers/MarkerSet.java index 6a9f85a2..116b1402 100644 --- a/DynmapCoreAPI/src/main/java/org/dynmap/markers/MarkerSet.java +++ b/DynmapCoreAPI/src/main/java/org/dynmap/markers/MarkerSet.java @@ -256,4 +256,8 @@ public interface MarkerSet { * @return default marker */ public MarkerIcon getDefaultMarkerIcon(); + /** + * Add entered markers to set based on given coordinates + */ + public void addEnteredMarkers(Set entered, String worldid, double x, double y, double z); } diff --git a/bukkit-helper/.settings/org.eclipse.buildship.core.prefs b/bukkit-helper/.settings/org.eclipse.buildship.core.prefs index b1886adb..6579e31c 100644 --- a/bukkit-helper/.settings/org.eclipse.buildship.core.prefs +++ b/bukkit-helper/.settings/org.eclipse.buildship.core.prefs @@ -1,2 +1,13 @@ -connection.project.dir=.. +arguments= +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3)) +connection.project.dir= eclipse.preferences.version=1 +gradle.user.home= +java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/forge-1.13.2/build.gradle b/forge-1.13.2/build.gradle index 2a66e841..2ee6bce6 100644 --- a/forge-1.13.2/build.gradle +++ b/forge-1.13.2/build.gradle @@ -62,9 +62,6 @@ shadowJar { } archiveName = "Dynmap-${parent.version}-forge-1.13.2.jar" destinationDir = file '../target' - manifest { - attributes 'FMLAT': 'dynmap_at.cfg' - } } shadowJar.doLast { diff --git a/forge-1.13.2/src/main/resources/dynmap_at.cfg b/forge-1.13.2/src/main/resources/dynmap_at.cfg deleted file mode 100644 index e97eb6d8..00000000 --- a/forge-1.13.2/src/main/resources/dynmap_at.cfg +++ /dev/null @@ -1,4 +0,0 @@ -public net.minecraft.world.gen.ChunkProviderServer field_73247_e # chunkLoader -public net.minecraft.world.chunk.storage.AnvilChunkLoader field_75825_d # chunkSaveLocation -public net.minecraft.world.biome.Biome field_76791_y # biomeName -public net.minecraft.world.chunk.Chunk field_76641_n # lastSaveTime diff --git a/forge-1.14.4/build.gradle b/forge-1.14.4/build.gradle index dda0b11e..e6aa6f75 100644 --- a/forge-1.14.4/build.gradle +++ b/forge-1.14.4/build.gradle @@ -60,9 +60,6 @@ shadowJar { } archiveName = "Dynmap-${parent.version}-forge-1.14.4.jar" destinationDir = file '../target' - manifest { - attributes 'FMLAT': 'dynmap_at.cfg' - } } shadowJar.doLast { diff --git a/forge-1.15.2/.gitignore b/forge-1.15.2/.gitignore index 84c048a7..54603950 100644 --- a/forge-1.15.2/.gitignore +++ b/forge-1.15.2/.gitignore @@ -1 +1,3 @@ /build/ +/.gradle/ +/bin/ diff --git a/forge-1.15.2/build.gradle b/forge-1.15.2/build.gradle index 69a4646a..77ac57c2 100644 --- a/forge-1.15.2/build.gradle +++ b/forge-1.15.2/build.gradle @@ -60,9 +60,6 @@ shadowJar { } archiveName = "Dynmap-${parent.version}-forge-1.15.2.jar" destinationDir = file '../target' - manifest { - attributes 'FMLAT': 'dynmap_at.cfg' - } } shadowJar.doLast {