mirror of
https://github.com/webbukkit/dynmap.git
synced 2025-01-28 02:21:33 +01:00
Make all /dmarker command match-on-label as well as id:<id>
This commit is contained in:
parent
f0db205eb9
commit
f950fb4d85
@ -35,6 +35,12 @@ public interface MarkerSet {
|
|||||||
* @return marker, or null if cannot be found
|
* @return marker, or null if cannot be found
|
||||||
*/
|
*/
|
||||||
public Marker findMarker(String id);
|
public Marker findMarker(String id);
|
||||||
|
/**
|
||||||
|
* Find marker by label - best matching substring
|
||||||
|
* @param lbl - label to find (same = best match)
|
||||||
|
* @return marker, or null if none found
|
||||||
|
*/
|
||||||
|
public Marker findMarkerByLabel(String lbl);
|
||||||
/**
|
/**
|
||||||
* Get ID of marker set - unique among marker sets
|
* Get ID of marker set - unique among marker sets
|
||||||
* @return ID
|
* @return ID
|
||||||
|
@ -409,7 +409,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
|||||||
"add", "movehere", "update", "delete", "list", "icons"
|
"add", "movehere", "update", "delete", "list", "icons"
|
||||||
}));
|
}));
|
||||||
|
|
||||||
/* Parse argument strings : handle 'attrib=value' and quoted strings */
|
/* Parse argument strings : handle 'attrib:value' and quoted strings */
|
||||||
private static Map<String,String> parseArgs(String[] args, CommandSender snd) {
|
private static Map<String,String> parseArgs(String[] args, CommandSender snd) {
|
||||||
HashMap<String,String> rslt = new HashMap<String,String>();
|
HashMap<String,String> rslt = new HashMap<String,String>();
|
||||||
/* Build command line, so we can parse our way - make sure there is trailing space */
|
/* Build command line, so we can parse our way - make sure there is trailing space */
|
||||||
@ -438,7 +438,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
|||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(c == '=') { /* var=value */
|
else if(c == ':') { /* var:value */
|
||||||
varid = sb.toString(); /* Save variable ID */
|
varid = sb.toString(); /* Save variable ID */
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
}
|
}
|
||||||
@ -513,7 +513,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
|||||||
sender.sendMessage("Error creating marker");
|
sender.sendMessage("Error creating marker");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sender.sendMessage("Added marker id='" + m.getMarkerID() + "' (" + m.getLabel() + ") to set '" + set.getMarkerSetID() + "'");
|
sender.sendMessage("Added marker id:'" + m.getMarkerID() + "' (" + m.getLabel() + ") to set '" + set.getMarkerSetID() + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -529,8 +529,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
|||||||
/* Parse arguements */
|
/* Parse arguements */
|
||||||
Map<String,String> parms = parseArgs(args, sender);
|
Map<String,String> parms = parseArgs(args, sender);
|
||||||
if(parms == null) return true;
|
if(parms == null) return true;
|
||||||
if(parms.get("id") == null) {
|
if((parms.get("id") == null) && (parms.get("label") == null)) {
|
||||||
sender.sendMessage("id=<marker-id> required");
|
sender.sendMessage("<label> or id:<marker-id> required");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(parms.get("set") == null) {
|
if(parms.get("set") == null) {
|
||||||
@ -541,17 +541,27 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
|||||||
sender.sendMessage("Error: invalid marker set - " + parms.get("set"));
|
sender.sendMessage("Error: invalid marker set - " + parms.get("set"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Marker marker = set.findMarker(parms.get("id"));
|
Marker marker;
|
||||||
if(marker == null) { /* No marker */
|
if(parms.get("id") != null) {
|
||||||
sender.sendMessage("Error: marker not found - " + parms.get("id"));
|
marker = set.findMarker(parms.get("id"));
|
||||||
return true;
|
if(marker == null) { /* No marker */
|
||||||
|
sender.sendMessage("Error: marker not found - " + parms.get("id"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
marker = set.findMarkerByLabel(parms.get("label"));
|
||||||
|
if(marker == null) { /* No marker */
|
||||||
|
sender.sendMessage("Error: marker not found - " + parms.get("label"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Location loc = player.getLocation();
|
Location loc = player.getLocation();
|
||||||
marker.setLocation(loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ());
|
marker.setLocation(loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ());
|
||||||
sender.sendMessage("Updated location of marker id=" + parms.get("id") + " (" + marker.getLabel() + ")");
|
sender.sendMessage("Updated location of marker id:" + marker.getMarkerID() + " (" + marker.getLabel() + ")");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sender.sendMessage("id=<marker-id> required");
|
sender.sendMessage("<label> or id:<marker-id> required");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Update other attributes of marker - must have ID parameter */
|
/* Update other attributes of marker - must have ID parameter */
|
||||||
@ -560,8 +570,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
|||||||
/* Parse arguements */
|
/* Parse arguements */
|
||||||
Map<String,String> parms = parseArgs(args, sender);
|
Map<String,String> parms = parseArgs(args, sender);
|
||||||
if(parms == null) return true;
|
if(parms == null) return true;
|
||||||
if(parms.get("id") == null) {
|
if((parms.get("id") == null) && (parms.get("label") == null)) {
|
||||||
sender.sendMessage("id=<marker-id> required");
|
sender.sendMessage("<label> or id:<marker-id> required");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(parms.get("set") == null) {
|
if(parms.get("set") == null) {
|
||||||
@ -572,13 +582,23 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
|||||||
sender.sendMessage("Error: invalid marker set - " + parms.get("set"));
|
sender.sendMessage("Error: invalid marker set - " + parms.get("set"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Marker marker = set.findMarker(parms.get("id"));
|
Marker marker;
|
||||||
if(marker == null) { /* No marker */
|
if(parms.get("id") != null) {
|
||||||
sender.sendMessage("Error: marker not found - " + parms.get("id"));
|
marker = set.findMarker(parms.get("id"));
|
||||||
return true;
|
if(marker == null) { /* No marker */
|
||||||
|
sender.sendMessage("Error: marker not found - " + parms.get("id"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(parms.get("label") != null) { /* Label set? */
|
else {
|
||||||
marker.setLabel(parms.get("label"));
|
marker = set.findMarkerByLabel(parms.get("label"));
|
||||||
|
if(marker == null) { /* No marker */
|
||||||
|
sender.sendMessage("Error: marker not found - " + parms.get("label"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(parms.get("newlabel") != null) { /* Label set? */
|
||||||
|
marker.setLabel(parms.get("newlabel"));
|
||||||
}
|
}
|
||||||
if(parms.get("icon") != null) {
|
if(parms.get("icon") != null) {
|
||||||
MarkerIcon ico = api.getMarkerIcon(parms.get("icon"));
|
MarkerIcon ico = api.getMarkerIcon(parms.get("icon"));
|
||||||
@ -588,10 +608,10 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
|||||||
}
|
}
|
||||||
marker.setMarkerIcon(ico);
|
marker.setMarkerIcon(ico);
|
||||||
}
|
}
|
||||||
sender.sendMessage("Updated marker id=" + parms.get("id") + " (" + marker.getLabel() + ")");
|
sender.sendMessage("Updated marker id:" + marker.getMarkerID() + " (" + marker.getLabel() + ")");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sender.sendMessage("id=<marker-id> required");
|
sender.sendMessage("<label> or id:<marker-id> required");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Delete marker - must have ID parameter */
|
/* Delete marker - must have ID parameter */
|
||||||
@ -600,8 +620,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
|||||||
/* Parse arguements */
|
/* Parse arguements */
|
||||||
Map<String,String> parms = parseArgs(args, sender);
|
Map<String,String> parms = parseArgs(args, sender);
|
||||||
if(parms == null) return true;
|
if(parms == null) return true;
|
||||||
if(parms.get("id") == null) {
|
if((parms.get("id") == null) && (parms.get("label") == null)) {
|
||||||
sender.sendMessage("id=<marker-id> required");
|
sender.sendMessage("<label> or id:<marker-id> required");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(parms.get("set") == null) {
|
if(parms.get("set") == null) {
|
||||||
@ -612,16 +632,26 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
|||||||
sender.sendMessage("Error: invalid marker set - " + parms.get("set"));
|
sender.sendMessage("Error: invalid marker set - " + parms.get("set"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Marker marker = set.findMarker(parms.get("id"));
|
Marker marker;
|
||||||
if(marker == null) { /* No marker */
|
if(parms.get("id") != null) {
|
||||||
sender.sendMessage("Error: marker not found - " + parms.get("id"));
|
marker = set.findMarker(parms.get("id"));
|
||||||
return true;
|
if(marker == null) { /* No marker */
|
||||||
|
sender.sendMessage("Error: marker not found - " + parms.get("id"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
marker = set.findMarkerByLabel(parms.get("label"));
|
||||||
|
if(marker == null) { /* No marker */
|
||||||
|
sender.sendMessage("Error: marker not found - " + parms.get("label"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
marker.deleteMarker();
|
marker.deleteMarker();
|
||||||
sender.sendMessage("Deleted marker id=" + parms.get("id"));
|
sender.sendMessage("Deleted marker id:" + marker.getMarkerID() + " (" + marker.getLabel() + ")");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sender.sendMessage("id=<marker-id> required");
|
sender.sendMessage("<label> or id:<marker-id> required");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* List markers */
|
/* List markers */
|
||||||
@ -639,15 +669,15 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
|||||||
}
|
}
|
||||||
Set<Marker> markers = set.getMarkers();
|
Set<Marker> markers = set.getMarkers();
|
||||||
for(Marker m : markers) {
|
for(Marker m : markers) {
|
||||||
sender.sendMessage(m.getMarkerID() + ": label=\"" + m.getLabel() + "\", set=" + m.getMarkerSet().getMarkerSetID() +
|
sender.sendMessage(m.getMarkerID() + ": label:\"" + m.getLabel() + "\", set:" + m.getMarkerSet().getMarkerSetID() +
|
||||||
", world=" + m.getWorld() + ", x=" + m.getX() + ", y=" + m.getY() + ", z=" + m.getZ());
|
", world:" + m.getWorld() + ", x:" + m.getX() + ", y:" + m.getY() + ", z:" + m.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* List icons */
|
/* List icons */
|
||||||
else if(c.equals("icons") && plugin.checkPlayerPermission(sender, "marker.icons")) {
|
else if(c.equals("icons") && plugin.checkPlayerPermission(sender, "marker.icons")) {
|
||||||
Set<MarkerIcon> icons = api.getMarkerIcons();
|
Set<MarkerIcon> icons = api.getMarkerIcons();
|
||||||
for(MarkerIcon ico : icons) {
|
for(MarkerIcon ico : icons) {
|
||||||
sender.sendMessage(ico.getMarkerIconID() + ": label=\"" + ico.getMarkerIconLabel() + "\", builtin=" + ico.isBuiltIn());
|
sender.sendMessage(ico.getMarkerIconID() + ": label:\"" + ico.getMarkerIconLabel() + "\", builtin:" + ico.isBuiltIn());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -86,6 +86,21 @@ class MarkerSetImpl implements MarkerSet {
|
|||||||
return markers.get(id);
|
return markers.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Marker findMarkerByLabel(String lbl) {
|
||||||
|
Marker match = null;
|
||||||
|
int matchlen = Integer.MAX_VALUE;
|
||||||
|
for(Marker m : markers.values()) {
|
||||||
|
if(m.getLabel().contains(lbl)) {
|
||||||
|
if(matchlen > m.getLabel().length()) {
|
||||||
|
match = m;
|
||||||
|
matchlen = m.getLabel().length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMarkerSetID() {
|
public String getMarkerSetID() {
|
||||||
return setid;
|
return setid;
|
||||||
|
@ -26,11 +26,13 @@ commands:
|
|||||||
dmarker:
|
dmarker:
|
||||||
description: Manipulate map markers
|
description: Manipulate map markers
|
||||||
usage: |
|
usage: |
|
||||||
/<command> add <label> - add new marker with generated ID at current location (use double-quotes if spaces needed)
|
/<command> add <label> - add new marker with given label at current location (use double-quotes if spaces needed)
|
||||||
/<command> add id=<id> <label> - add new marker with given ID at current location (use double-quotes if spaces needed)
|
/<command> add id:<id> <label> - add new marker with given ID at current location (use double-quotes if spaces needed)
|
||||||
/<command> movehere id=<id> - move marker with given ID to current location
|
/<command> movehere <label> - move marker with given label to current location
|
||||||
/<command> update id=<id> <label> icon=<icon> - update marker with given ID with new label and/or icon
|
/<command> movehere id:<id> - move marker with given ID to current location
|
||||||
/<command> delete id=<id> - delete marker with given ID
|
/<command> update <label> icon:<icon> newlabel:<newlabel>- update marker with given ID with new label and/or icon
|
||||||
|
/<command> delete <label> - delete marker with given label
|
||||||
|
/<command> delete id:<id> - delete marker with given ID
|
||||||
/<command> list - list details of all markers
|
/<command> list - list details of all markers
|
||||||
/<command> icons - list details of all icons
|
/<command> icons - list details of all icons
|
||||||
|
|
||||||
|
@ -17,20 +17,25 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
|||||||
$.getJSON(dynmap.options.tileUrl+'_markers_/marker_'+world+'.json', function(data) {
|
$.getJSON(dynmap.options.tileUrl+'_markers_/marker_'+world+'.json', function(data) {
|
||||||
var ts = data.timestamp;
|
var ts = data.timestamp;
|
||||||
$.each(data.sets, function(name, markerset) {
|
$.each(data.sets, function(name, markerset) {
|
||||||
if(!dynmapmarkersets[name]) {
|
var ms = dynmapmarkersets[name];
|
||||||
dynmapmarkersets[name] = markerset;
|
if(!ms) {
|
||||||
createMarkerSet(markerset);
|
ms = { label: markerset.label, markers: {} } ;
|
||||||
|
createMarkerSet(ms, ts);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(dynmapmarkersets[name].label != markerset.label) {
|
if(ms.label != markerset.label) {
|
||||||
dynmapmarkersets[name].label = markerset.label;
|
ms.label = markerset.label;
|
||||||
dynmap.layercontrol.removeLayer(dynmapmarkersets[name].layergroup);
|
dynmap.layercontrol.removeLayer(ms.layergroup);
|
||||||
dynmap.layercontrol.addOverlay(dynmapmarkersets[name].layergroup, dynmapmarkersets[name].label);
|
dynmap.layercontrol.addOverlay(ms.layergroup, ms.label);
|
||||||
}
|
}
|
||||||
dynmapmarkersets[name].markers = markerset.markers;
|
ms.markers = {};
|
||||||
|
ms.timestamp = ts;
|
||||||
}
|
}
|
||||||
$.each(markerset.markers, function(name, marker) {
|
dynmapmarkersets[name] = ms;
|
||||||
createMarker(markerset, marker);
|
$.each(markerset.markers, function(mname, marker) {
|
||||||
|
ms.markers[mname] = { label: marker.label, x: marker.x, y: marker.y, z:marker.z,
|
||||||
|
icon: marker.icon };
|
||||||
|
createMarker(ms, ms.markers[mname], ts);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -40,7 +45,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
|||||||
return dynmap.getProjection().fromLocationToLatLng({ x: marker.x, y: marker.y, z: marker.z });
|
return dynmap.getProjection().fromLocationToLatLng({ x: marker.x, y: marker.y, z: marker.z });
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMarker(set, marker) {
|
function createMarker(set, marker, ts) {
|
||||||
var markerPosition = getPosition(marker);
|
var markerPosition = getPosition(marker);
|
||||||
marker.our_marker = new L.CustomMarker(markerPosition, { elementCreator: function() {
|
marker.our_marker = new L.CustomMarker(markerPosition, { elementCreator: function() {
|
||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
@ -57,22 +62,23 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
|||||||
.text(marker.label));
|
.text(marker.label));
|
||||||
return div;
|
return div;
|
||||||
}});
|
}});
|
||||||
|
marker.timestamp = ts;
|
||||||
set.layergroup.addLayer(marker.our_marker);
|
set.layergroup.addLayer(marker.our_marker);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMarkerSet(set) {
|
function createMarkerSet(set, ts) {
|
||||||
set.layergroup = new L.LayerGroup();
|
set.layergroup = new L.LayerGroup();
|
||||||
|
set.timestamp = ts;
|
||||||
dynmap.map.addLayer(set.layergroup);
|
dynmap.map.addLayer(set.layergroup);
|
||||||
dynmap.layercontrol.addOverlay(set.layergroup, set.label);
|
dynmap.layercontrol.addOverlay(set.layergroup, set.label);
|
||||||
}
|
}
|
||||||
|
|
||||||
$(dynmap).bind('component.markers', function(event, msg) {
|
$(dynmap).bind('component.markers', function(event, msg) {
|
||||||
console.log('got marker event - ' + msg.ctype + ', ' + msg.msg);
|
|
||||||
if(msg.msg == 'markerupdated') {
|
if(msg.msg == 'markerupdated') {
|
||||||
var marker = dynmapmarkersets[msg.set].markers[msg.id];
|
var marker = dynmapmarkersets[msg.set].markers[msg.id];
|
||||||
if(marker && marker.our_marker) {
|
if(marker && marker.our_marker) {
|
||||||
dynmapmarkersets[msg.set].layergroup.removeLayer(marker.our_marker);
|
dynmapmarkersets[msg.set].layergroup.removeLayer(marker.our_marker);
|
||||||
|
delete marker.our_marker;
|
||||||
}
|
}
|
||||||
marker = { x: msg.x, y: msg.y, z: msg.z, icon: msg.icon, label: msg.label };
|
marker = { x: msg.x, y: msg.y, z: msg.z, icon: msg.icon, label: msg.label };
|
||||||
dynmapmarkersets[msg.set].markers[msg.id] = marker;
|
dynmapmarkersets[msg.set].markers[msg.id] = marker;
|
||||||
|
Loading…
Reference in New Issue
Block a user