mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-01 06:33:38 +01:00
Add hide-by-default attribute to marker sets, /dmarker updateset
This commit is contained in:
parent
e54c1fa7d8
commit
3d868d4700
@ -86,4 +86,14 @@ public interface MarkerSet {
|
||||
* Delete marker set
|
||||
*/
|
||||
public void deleteMarkerSet();
|
||||
/**
|
||||
* Set hide/show default
|
||||
* @param hide - if true, layer for set will be hidden by default
|
||||
*/
|
||||
public void setHideByDefault(boolean hide);
|
||||
/**
|
||||
* Get hide/show default
|
||||
* @return true if layer for set will be hidden by default
|
||||
*/
|
||||
public boolean getHideByDefault();
|
||||
}
|
||||
|
@ -123,9 +123,11 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
/* Load persistence */
|
||||
api.loadMarkers();
|
||||
/* Initialize default marker set, if needed */
|
||||
if(api.getMarkerSet(MarkerSet.DEFAULT) == null) {
|
||||
api.createMarkerSet(MarkerSet.DEFAULT, "Markers", null, true);
|
||||
MarkerSet set = api.getMarkerSet(MarkerSet.DEFAULT);
|
||||
if(set == null) {
|
||||
set = api.createMarkerSet(MarkerSet.DEFAULT, "Markers", null, true);
|
||||
}
|
||||
|
||||
/* Build paths for markers */
|
||||
api.markerdir = new File(plugin.getDataFolder(), "markers");
|
||||
if(api.markerdir.isDirectory() == false) {
|
||||
@ -404,7 +406,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
}
|
||||
|
||||
private static final Set<String> commands = new HashSet<String>(Arrays.asList(new String[] {
|
||||
"add", "movehere", "update", "delete", "list", "icons", "addset", "deleteset", "listsets", "addicon"
|
||||
"add", "movehere", "update", "delete", "list", "icons", "addset", "updateset", "deleteset", "listsets", "addicon"
|
||||
}));
|
||||
|
||||
/* Parse argument strings : handle 'attrib:value' and quoted strings */
|
||||
@ -708,6 +710,9 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
sender.sendMessage("Error creating marker set");
|
||||
}
|
||||
else {
|
||||
String h = parms.get("hide");
|
||||
if((h != null) && (h.equals("true")))
|
||||
set.setHideByDefault(true);
|
||||
sender.sendMessage("Added marker set id:'" + set.getMarkerSetID() + "' (" + set.getMarkerSetLabel() + ")");
|
||||
}
|
||||
}
|
||||
@ -715,6 +720,47 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
sender.sendMessage("<label> or id:<set-id> required");
|
||||
}
|
||||
}
|
||||
else if(c.equals("updateset") && plugin.checkPlayerPermission(sender, "marker.updateset")) {
|
||||
if(args.length > 1) {
|
||||
/* Parse arguements */
|
||||
Map<String,String> parms = parseArgs(args, sender);
|
||||
if(parms == null) return true;
|
||||
if((parms.get("id") == null) && (parms.get("label") == null)) {
|
||||
sender.sendMessage("<label> or id:<marker-id> required");
|
||||
return true;
|
||||
}
|
||||
MarkerSet set = null;
|
||||
if(parms.get("id") != null) {
|
||||
set = api.getMarkerSet(parms.get("id"));
|
||||
if(set == null) {
|
||||
sender.sendMessage("Error: set does not exist - id:" + set.getMarkerSetID());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Set<MarkerSet> sets = api.getMarkerSets();
|
||||
for(MarkerSet s : sets) {
|
||||
if(s.getMarkerSetLabel().equals(parms.get("label"))) {
|
||||
set = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(set == null) {
|
||||
sender.sendMessage("Error: matching set not found");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(parms.get("newLabel") != null) {
|
||||
set.setMarkerSetLabel(parms.get("netlabel"));
|
||||
}
|
||||
if(parms.get("hide") != null) {
|
||||
set.setHideByDefault(parms.get("hide").equals("true"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage("<label> or id:<set-id> required");
|
||||
}
|
||||
}
|
||||
else if(c.equals("deleteset") && plugin.checkPlayerPermission(sender, "marker.deleteset")) {
|
||||
if(args.length > 1) {
|
||||
/* Parse arguements */
|
||||
@ -757,7 +803,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
else if(c.equals("listsets") && plugin.checkPlayerPermission(sender, "marker.listsets")) {
|
||||
Set<MarkerSet> sets = api.getMarkerSets();
|
||||
for(MarkerSet set : sets) {
|
||||
sender.sendMessage(set.getMarkerSetID() + ": label:\"" + set.getMarkerSetLabel() + "\"");
|
||||
sender.sendMessage(set.getMarkerSetID() + ": label:\"" + set.getMarkerSetLabel() + "\", hide=" + set.getHideByDefault());
|
||||
}
|
||||
}
|
||||
/* Add new icon */
|
||||
@ -826,6 +872,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
for(MarkerSet ms : markersets.values()) {
|
||||
HashMap<String, Object> msdata = new HashMap<String, Object>();
|
||||
msdata.put("label", ms.getMarkerSetLabel());
|
||||
msdata.put("hide", ms.getHideByDefault());
|
||||
HashMap<String, Object> markers = new HashMap<String, Object>();
|
||||
for(Marker m : ms.getMarkers()) {
|
||||
if(m.getWorld().equals(wname) == false) continue;
|
||||
|
@ -20,7 +20,7 @@ class MarkerSetImpl implements MarkerSet {
|
||||
private String setid;
|
||||
private String label;
|
||||
private HashMap<String, MarkerIconImpl> allowedicons = null;
|
||||
|
||||
private boolean hide_by_def;
|
||||
private boolean ispersistent;
|
||||
|
||||
MarkerSetImpl(String id) {
|
||||
@ -204,6 +204,7 @@ class MarkerSetImpl implements MarkerSet {
|
||||
setnode.put("allowedicons", allowed);
|
||||
}
|
||||
setnode.put("markers", node);
|
||||
setnode.put("hide", hide_by_def);
|
||||
return setnode;
|
||||
}
|
||||
|
||||
@ -236,8 +237,22 @@ class MarkerSetImpl implements MarkerSet {
|
||||
Log.info("Error loading allowed icon '" + id + "' for set '" + setid + "'");
|
||||
}
|
||||
}
|
||||
hide_by_def = node.getBoolean("hide", false);
|
||||
ispersistent = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void setHideByDefault(boolean hide) {
|
||||
if(hide_by_def != hide) {
|
||||
hide_by_def = hide;
|
||||
MarkerAPIImpl.markerSetUpdated(this, MarkerUpdate.UPDATED);
|
||||
if(ispersistent)
|
||||
MarkerAPIImpl.saveMarkers();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean getHideByDefault() {
|
||||
return hide_by_def;
|
||||
}
|
||||
}
|
||||
|
@ -47,8 +47,6 @@ components:
|
||||
#showlabel: true
|
||||
# If set, enables support for using signs for markers
|
||||
#enablesigns: true
|
||||
# If set, make markers layer hidden by default
|
||||
#hidebydefault: true
|
||||
# If set, show spawn points on each world
|
||||
showspawn: true
|
||||
# Marker used for spawn point
|
||||
|
@ -66,6 +66,7 @@ permissions:
|
||||
dynmap.marker.icons: true
|
||||
dynmap.marker.sign: true
|
||||
dynmap.marker.addset: true
|
||||
dynmap.marker.updateset: true
|
||||
dynmap.marker.deleteset: true
|
||||
dynmap.marker.listsets: true
|
||||
dynmap.marker.addicon: true
|
||||
@ -126,6 +127,9 @@ permissions:
|
||||
dynmap.marker.addset:
|
||||
description: Allows /dmarker addset
|
||||
default: op
|
||||
dynmap.marker.updateset:
|
||||
description: Allows /dmarker updateset
|
||||
default: op
|
||||
dynmap.marker.deleteset:
|
||||
description: Allows /dmarker deleteset
|
||||
default: op
|
||||
|
@ -20,7 +20,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||
$.each(data.sets, function(name, markerset) {
|
||||
var ms = dynmapmarkersets[name];
|
||||
if(!ms) {
|
||||
ms = { label: markerset.label, markers: {} } ;
|
||||
ms = { label: markerset.label, hide: markerset.hide, markers: {} } ;
|
||||
createMarkerSet(ms, ts);
|
||||
}
|
||||
else {
|
||||
@ -30,6 +30,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||
dynmap.layercontrol.addOverlay(ms.layergroup, ms.label);
|
||||
}
|
||||
ms.markers = {};
|
||||
ms.hide = markerset.hide;
|
||||
ms.timestamp = ts;
|
||||
}
|
||||
dynmapmarkersets[name] = ms;
|
||||
@ -70,7 +71,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||
function createMarkerSet(set, ts) {
|
||||
set.layergroup = new L.LayerGroup();
|
||||
set.timestamp = ts;
|
||||
if(!configuration.hidebydefault)
|
||||
if(!set.hide)
|
||||
dynmap.map.addLayer(set.layergroup);
|
||||
dynmap.layercontrol.addOverlay(set.layergroup, set.label);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user