Add hide-by-default attribute to marker sets, /dmarker updateset

This commit is contained in:
Mike Primm 2011-09-09 11:02:32 +08:00 committed by mikeprimm
parent 4c50bd502c
commit 6d2193d597
6 changed files with 84 additions and 9 deletions

View File

@ -86,4 +86,14 @@ public interface MarkerSet {
* Delete marker set * Delete marker set
*/ */
public void deleteMarkerSet(); 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();
} }

View File

@ -123,9 +123,11 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
/* Load persistence */ /* Load persistence */
api.loadMarkers(); api.loadMarkers();
/* Initialize default marker set, if needed */ /* Initialize default marker set, if needed */
if(api.getMarkerSet(MarkerSet.DEFAULT) == null) { MarkerSet set = api.getMarkerSet(MarkerSet.DEFAULT);
api.createMarkerSet(MarkerSet.DEFAULT, "Markers", null, true); if(set == null) {
set = api.createMarkerSet(MarkerSet.DEFAULT, "Markers", null, true);
} }
/* Build paths for markers */ /* Build paths for markers */
api.markerdir = new File(plugin.getDataFolder(), "markers"); api.markerdir = new File(plugin.getDataFolder(), "markers");
if(api.markerdir.isDirectory() == false) { 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[] { 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 */ /* 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"); sender.sendMessage("Error creating marker set");
} }
else { 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() + ")"); 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"); 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")) { else if(c.equals("deleteset") && plugin.checkPlayerPermission(sender, "marker.deleteset")) {
if(args.length > 1) { if(args.length > 1) {
/* Parse arguements */ /* Parse arguements */
@ -757,7 +803,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
else if(c.equals("listsets") && plugin.checkPlayerPermission(sender, "marker.listsets")) { else if(c.equals("listsets") && plugin.checkPlayerPermission(sender, "marker.listsets")) {
Set<MarkerSet> sets = api.getMarkerSets(); Set<MarkerSet> sets = api.getMarkerSets();
for(MarkerSet set : sets) { for(MarkerSet set : sets) {
sender.sendMessage(set.getMarkerSetID() + ": label:\"" + set.getMarkerSetLabel() + "\""); sender.sendMessage(set.getMarkerSetID() + ": label:\"" + set.getMarkerSetLabel() + "\", hide=" + set.getHideByDefault());
} }
} }
/* Add new icon */ /* Add new icon */
@ -826,6 +872,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
for(MarkerSet ms : markersets.values()) { for(MarkerSet ms : markersets.values()) {
HashMap<String, Object> msdata = new HashMap<String, Object>(); HashMap<String, Object> msdata = new HashMap<String, Object>();
msdata.put("label", ms.getMarkerSetLabel()); msdata.put("label", ms.getMarkerSetLabel());
msdata.put("hide", ms.getHideByDefault());
HashMap<String, Object> markers = new HashMap<String, Object>(); HashMap<String, Object> markers = new HashMap<String, Object>();
for(Marker m : ms.getMarkers()) { for(Marker m : ms.getMarkers()) {
if(m.getWorld().equals(wname) == false) continue; if(m.getWorld().equals(wname) == false) continue;

View File

@ -20,7 +20,7 @@ class MarkerSetImpl implements MarkerSet {
private String setid; private String setid;
private String label; private String label;
private HashMap<String, MarkerIconImpl> allowedicons = null; private HashMap<String, MarkerIconImpl> allowedicons = null;
private boolean hide_by_def;
private boolean ispersistent; private boolean ispersistent;
MarkerSetImpl(String id) { MarkerSetImpl(String id) {
@ -204,6 +204,7 @@ class MarkerSetImpl implements MarkerSet {
setnode.put("allowedicons", allowed); setnode.put("allowedicons", allowed);
} }
setnode.put("markers", node); setnode.put("markers", node);
setnode.put("hide", hide_by_def);
return setnode; return setnode;
} }
@ -236,8 +237,22 @@ class MarkerSetImpl implements MarkerSet {
Log.info("Error loading allowed icon '" + id + "' for set '" + setid + "'"); Log.info("Error loading allowed icon '" + id + "' for set '" + setid + "'");
} }
} }
hide_by_def = node.getBoolean("hide", false);
ispersistent = true; ispersistent = true;
return 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;
}
} }

View File

@ -47,8 +47,6 @@ components:
#showlabel: true #showlabel: true
# If set, enables support for using signs for markers # If set, enables support for using signs for markers
#enablesigns: true #enablesigns: true
# If set, make markers layer hidden by default
#hidebydefault: true
# If set, show spawn points on each world # If set, show spawn points on each world
showspawn: true showspawn: true
# Marker used for spawn point # Marker used for spawn point

View File

@ -66,6 +66,7 @@ permissions:
dynmap.marker.icons: true dynmap.marker.icons: true
dynmap.marker.sign: true dynmap.marker.sign: true
dynmap.marker.addset: true dynmap.marker.addset: true
dynmap.marker.updateset: true
dynmap.marker.deleteset: true dynmap.marker.deleteset: true
dynmap.marker.listsets: true dynmap.marker.listsets: true
dynmap.marker.addicon: true dynmap.marker.addicon: true
@ -126,6 +127,9 @@ permissions:
dynmap.marker.addset: dynmap.marker.addset:
description: Allows /dmarker addset description: Allows /dmarker addset
default: op default: op
dynmap.marker.updateset:
description: Allows /dmarker updateset
default: op
dynmap.marker.deleteset: dynmap.marker.deleteset:
description: Allows /dmarker deleteset description: Allows /dmarker deleteset
default: op default: op

View File

@ -20,7 +20,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
$.each(data.sets, function(name, markerset) { $.each(data.sets, function(name, markerset) {
var ms = dynmapmarkersets[name]; var ms = dynmapmarkersets[name];
if(!ms) { if(!ms) {
ms = { label: markerset.label, markers: {} } ; ms = { label: markerset.label, hide: markerset.hide, markers: {} } ;
createMarkerSet(ms, ts); createMarkerSet(ms, ts);
} }
else { else {
@ -30,6 +30,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
dynmap.layercontrol.addOverlay(ms.layergroup, ms.label); dynmap.layercontrol.addOverlay(ms.layergroup, ms.label);
} }
ms.markers = {}; ms.markers = {};
ms.hide = markerset.hide;
ms.timestamp = ts; ms.timestamp = ts;
} }
dynmapmarkersets[name] = ms; dynmapmarkersets[name] = ms;
@ -70,7 +71,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
function createMarkerSet(set, ts) { function createMarkerSet(set, ts) {
set.layergroup = new L.LayerGroup(); set.layergroup = new L.LayerGroup();
set.timestamp = ts; set.timestamp = ts;
if(!configuration.hidebydefault) if(!set.hide)
dynmap.map.addLayer(set.layergroup); dynmap.map.addLayer(set.layergroup);
dynmap.layercontrol.addOverlay(set.layergroup, set.label); dynmap.layercontrol.addOverlay(set.layergroup, set.label);
} }