Initial work on greeting/farewall title support for areas

This commit is contained in:
Mike Primm 2020-05-25 01:14:20 -05:00
parent 2be20f4c78
commit 14f55bd6a8
14 changed files with 269 additions and 19 deletions

View File

@ -13,4 +13,7 @@ public class DynmapLocation {
world = w; world = w;
this.x = x; this.y = y; this.z = z; this.x = x; this.y = y; this.z = z;
} }
public String toString() {
return String.format("{%s,%f,%f,%f}", world, x, y, z);
}
} }

View File

@ -11,6 +11,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -32,6 +33,9 @@ import org.dynmap.common.DynmapListenerManager.EventType;
import org.dynmap.debug.Debug; import org.dynmap.debug.Debug;
import org.dynmap.exporter.OBJExport; import org.dynmap.exporter.OBJExport;
import org.dynmap.hdmap.HDMapManager; 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.renderer.DynmapBlockState;
import org.dynmap.storage.MapStorage; import org.dynmap.storage.MapStorage;
import org.dynmap.storage.MapStorageBaseTileEnumCB; import org.dynmap.storage.MapStorageBaseTileEnumCB;
@ -930,7 +934,46 @@ public class MapManager {
scheduleDelayedJob(this, 1000); /* Once per second */ scheduleDelayedJob(this, 1000); /* Once per second */
} }
} }
private HashMap<UUID, HashSet<EnterExitMarker>> entersetstate = new HashMap<UUID, HashSet<EnterExitMarker>>();
private class DoUserMoveProcessing implements Runnable {
public void run() {
HashMap<UUID, HashSet<EnterExitMarker>> newstate = new HashMap<UUID, HashSet<EnterExitMarker>>();
DynmapPlayer[] pl = core.playerList.getOnlinePlayers();
for (DynmapPlayer player : pl) {
if (player == null) continue;
UUID puuid = player.getUUID();
HashSet<EnterExitMarker> newset = new HashSet<EnterExitMarker>();
DynmapLocation dl = player.getLocation();
if (dl != null) {
MarkerAPIImpl.getEnteredMarkers(dl.world, dl.x, dl.y, dl.z, newset);
}
HashSet<EnterExitMarker> 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) { private void addNextTilesToUpdate(int cnt) {
ArrayList<MapTile> tiles = new ArrayList<MapTile>(); ArrayList<MapTile> tiles = new ArrayList<MapTile>();
TileFlags.TileCoord coord = new TileFlags.TileCoord(); TileFlags.TileCoord coord = new TileFlags.TileCoord();
@ -1458,6 +1501,7 @@ public class MapManager {
scheduleDelayedJob(new DoZoomOutProcessing(), 60000); scheduleDelayedJob(new DoZoomOutProcessing(), 60000);
scheduleDelayedJob(new CheckWorldTimes(), 5000); scheduleDelayedJob(new CheckWorldTimes(), 5000);
scheduleDelayedJob(new DoTouchProcessing(), 1000); scheduleDelayedJob(new DoTouchProcessing(), 1000);
scheduleDelayedJob(new DoUserMoveProcessing(), 1000);
/* Resume pending jobs */ /* Resume pending jobs */
for(FullWorldRenderState job : active_renders.values()) { for(FullWorldRenderState job : active_renders.values()) {
scheduleDelayedJob(job, 5000); scheduleDelayedJob(job, 5000);

View File

@ -7,6 +7,7 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -119,7 +120,11 @@ public class PlayerList {
} }
} }
} }
public DynmapPlayer[] getOnlinePlayers() {
return Arrays.copyOf(online, online.length);
}
public List<DynmapPlayer> getVisiblePlayers(String worldName) { public List<DynmapPlayer> getVisiblePlayers(String worldName) {
ArrayList<DynmapPlayer> visiblePlayers = new ArrayList<DynmapPlayer>(); ArrayList<DynmapPlayer> visiblePlayers = new ArrayList<DynmapPlayer>();
DynmapPlayer[] onlinePlayers = online; /* Use copied list - we don't call from server thread */ DynmapPlayer[] onlinePlayers = online; /* Use copied list - we don't call from server thread */

View File

@ -8,14 +8,16 @@ import java.util.concurrent.ConcurrentHashMap;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapWorld; import org.dynmap.DynmapWorld;
import org.dynmap.Log;
import org.dynmap.MapManager; import org.dynmap.MapManager;
import org.dynmap.hdmap.HDPerspective; import org.dynmap.hdmap.HDPerspective;
import org.dynmap.markers.AreaMarker; import org.dynmap.markers.AreaMarker;
import org.dynmap.markers.EnterExitMarker;
import org.dynmap.markers.MarkerSet; import org.dynmap.markers.MarkerSet;
import org.dynmap.markers.impl.MarkerAPIImpl.MarkerUpdate; import org.dynmap.markers.impl.MarkerAPIImpl.MarkerUpdate;
import org.dynmap.utils.Vector3D; import org.dynmap.utils.Vector3D;
class AreaMarkerImpl implements AreaMarker { class AreaMarkerImpl implements AreaMarker, EnterExitMarker {
private String markerid; private String markerid;
private String label; private String label;
private boolean markup; private boolean markup;
@ -35,6 +37,9 @@ class AreaMarkerImpl implements AreaMarker {
private boolean boostflag = false; private boolean boostflag = false;
private int minzoom; private int minzoom;
private int maxzoom; private int maxzoom;
private EnterExitText greeting;
private EnterExitText farewell;
private static class Coord { private static class Coord {
double x, z; double x, z;
@ -85,6 +90,8 @@ class AreaMarkerImpl implements AreaMarker {
} }
this.minzoom = -1; this.minzoom = -1;
this.maxzoom = -1; this.maxzoom = -1;
this.greeting = null;
this.farewell = null;
} }
/** /**
* Make bare area marker - used for persistence load * Make bare area marker - used for persistence load
@ -101,6 +108,8 @@ class AreaMarkerImpl implements AreaMarker {
world = normalized_world = "world"; world = normalized_world = "world";
this.minzoom = -1; this.minzoom = -1;
this.maxzoom = -1; this.maxzoom = -1;
this.greeting = null;
this.farewell = null;
} }
/** /**
* Load marker from configuration node * Load marker from configuration node
@ -132,7 +141,21 @@ class AreaMarkerImpl implements AreaMarker {
boostflag = node.getBoolean("boostFlag", false); boostflag = node.getBoolean("boostFlag", false);
minzoom = node.getInteger("minzoom", -1); minzoom = node.getInteger("minzoom", -1);
maxzoom = node.getInteger("maxzoom", -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 */ ispersistent = true; /* Loaded from config, so must be */
return true; return true;
@ -223,6 +246,23 @@ class AreaMarkerImpl implements AreaMarker {
if (maxzoom >= 0) { if (maxzoom >= 0) {
node.put("maxzoom", maxzoom); 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; return node;
} }
@Override @Override
@ -522,4 +562,80 @@ class AreaMarkerImpl implements AreaMarker {
if(ispersistent) if(ispersistent)
MarkerAPIImpl.saveMarkers(); 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;
}
} }

View File

@ -36,6 +36,7 @@ import org.dynmap.common.DynmapPlayer;
import org.dynmap.hdmap.HDPerspective; import org.dynmap.hdmap.HDPerspective;
import org.dynmap.markers.AreaMarker; import org.dynmap.markers.AreaMarker;
import org.dynmap.markers.CircleMarker; import org.dynmap.markers.CircleMarker;
import org.dynmap.markers.EnterExitMarker;
import org.dynmap.markers.Marker; import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerAPI;
import org.dynmap.markers.MarkerDescription; import org.dynmap.markers.MarkerDescription;
@ -3216,4 +3217,18 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
} }
return false; 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<EnterExitMarker> entered) {
if (api == null) return;
for(MarkerSetImpl ms : api.markersets.values()) {
ms.addEnteredMarkers(entered, worldid, x, y, z);
}
}
} }

View File

@ -14,6 +14,7 @@ import org.dynmap.Log;
import org.dynmap.hdmap.HDPerspective; import org.dynmap.hdmap.HDPerspective;
import org.dynmap.markers.AreaMarker; import org.dynmap.markers.AreaMarker;
import org.dynmap.markers.CircleMarker; import org.dynmap.markers.CircleMarker;
import org.dynmap.markers.EnterExitMarker;
import org.dynmap.markers.PolyLineMarker; import org.dynmap.markers.PolyLineMarker;
import org.dynmap.markers.Marker; import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerIcon; import org.dynmap.markers.MarkerIcon;
@ -27,6 +28,7 @@ class MarkerSetImpl implements MarkerSet {
private ConcurrentHashMap<String, CircleMarkerImpl> circlemarkers = new ConcurrentHashMap<String, CircleMarkerImpl>(); private ConcurrentHashMap<String, CircleMarkerImpl> circlemarkers = new ConcurrentHashMap<String, CircleMarkerImpl>();
private ConcurrentHashMap<String, AreaMarkerImpl> boostingareamarkers = null; private ConcurrentHashMap<String, AreaMarkerImpl> boostingareamarkers = null;
private ConcurrentHashMap<String, CircleMarkerImpl> boostingcirclemarkers = null; private ConcurrentHashMap<String, CircleMarkerImpl> boostingcirclemarkers = null;
private ConcurrentHashMap<String, EnterExitMarker> enterexitmarkers = null;
private String setid; private String setid;
private String label; private String label;
private ConcurrentHashMap<String, MarkerIconImpl> allowedicons = null; private ConcurrentHashMap<String, MarkerIconImpl> allowedicons = null;
@ -80,6 +82,10 @@ class MarkerSetImpl implements MarkerSet {
boostingcirclemarkers.clear(); boostingcirclemarkers.clear();
boostingcirclemarkers = null; boostingcirclemarkers = null;
} }
if (enterexitmarkers != null) {
enterexitmarkers.clear();
enterexitmarkers = null;
}
deficon = null; deficon = null;
} }
@ -268,6 +274,12 @@ class MarkerSetImpl implements MarkerSet {
} }
boostingareamarkers.put(marker.getMarkerID(), marker); boostingareamarkers.put(marker.getMarkerID(), marker);
} }
if ((marker.getGreetingText() != null) || (marker.getFarewellText() != null)) {
if (enterexitmarkers == null) {
enterexitmarkers = new ConcurrentHashMap<String, EnterExitMarker>();
}
enterexitmarkers.put(marker.getMarkerID(), marker);
}
if(ispersistent && marker.isPersistentMarker()) { /* If persistent */ if(ispersistent && marker.isPersistentMarker()) { /* If persistent */
MarkerAPIImpl.saveMarkers(); /* Drive save */ MarkerAPIImpl.saveMarkers(); /* Drive save */
} }
@ -286,7 +298,13 @@ class MarkerSetImpl implements MarkerSet {
boostingareamarkers = null; 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.saveMarkers(); /* Drive save */
} }
MarkerAPIImpl.areaMarkerUpdated(marker, MarkerUpdate.DELETED); MarkerAPIImpl.areaMarkerUpdated(marker, MarkerUpdate.DELETED);
@ -446,6 +464,12 @@ class MarkerSetImpl implements MarkerSet {
} }
boostingareamarkers.put(id, marker); boostingareamarkers.put(id, marker);
} }
if ((marker.getGreetingText() != null) || (marker.getFarewellText() != null)) {
if (enterexitmarkers == null) {
enterexitmarkers = new ConcurrentHashMap<String, EnterExitMarker>();
}
enterexitmarkers.put(marker.getMarkerID(), marker);
}
} }
else { else {
Log.info("Error loading area marker '" + id + "' for set '" + setid + "'"); Log.info("Error loading area marker '" + id + "' for set '" + setid + "'");
@ -745,5 +769,16 @@ class MarkerSetImpl implements MarkerSet {
} }
return false; return false;
} }
/**
* Add entered markers to set based on given coordinates
*/
@Override
public void addEnteredMarkers(Set<EnterExitMarker> 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);
}
}
}
} }

View File

@ -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);
};

View File

@ -256,4 +256,8 @@ public interface MarkerSet {
* @return default marker * @return default marker
*/ */
public MarkerIcon getDefaultMarkerIcon(); public MarkerIcon getDefaultMarkerIcon();
/**
* Add entered markers to set based on given coordinates
*/
public void addEnteredMarkers(Set<EnterExitMarker> entered, String worldid, double x, double y, double z);
} }

View File

@ -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 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

View File

@ -62,9 +62,6 @@ shadowJar {
} }
archiveName = "Dynmap-${parent.version}-forge-1.13.2.jar" archiveName = "Dynmap-${parent.version}-forge-1.13.2.jar"
destinationDir = file '../target' destinationDir = file '../target'
manifest {
attributes 'FMLAT': 'dynmap_at.cfg'
}
} }
shadowJar.doLast { shadowJar.doLast {

View File

@ -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

View File

@ -60,9 +60,6 @@ shadowJar {
} }
archiveName = "Dynmap-${parent.version}-forge-1.14.4.jar" archiveName = "Dynmap-${parent.version}-forge-1.14.4.jar"
destinationDir = file '../target' destinationDir = file '../target'
manifest {
attributes 'FMLAT': 'dynmap_at.cfg'
}
} }
shadowJar.doLast { shadowJar.doLast {

View File

@ -1 +1,3 @@
/build/ /build/
/.gradle/
/bin/

View File

@ -60,9 +60,6 @@ shadowJar {
} }
archiveName = "Dynmap-${parent.version}-forge-1.15.2.jar" archiveName = "Dynmap-${parent.version}-forge-1.15.2.jar"
destinationDir = file '../target' destinationDir = file '../target'
manifest {
attributes 'FMLAT': 'dynmap_at.cfg'
}
} }
shadowJar.doLast { shadowJar.doLast {