Add /dmarker updateicon, /dmarker deleteicon - add APIs for updating icon file and deleting icons

This commit is contained in:
Mike Primm 2011-09-13 11:31:16 +08:00 committed by mikeprimm
parent 09637f293e
commit a369f02083
6 changed files with 342 additions and 94 deletions

View File

@ -1,5 +1,7 @@
package org.dynmap.markers; package org.dynmap.markers;
import java.io.InputStream;
/** /**
* This defines the public interface to a marker icon, for use with the MarkerAPI * This defines the public interface to a marker icon, for use with the MarkerAPI
*/ */
@ -21,6 +23,19 @@ public interface MarkerIcon {
* @return icon label * @return icon label
*/ */
public String getMarkerIconLabel(); public String getMarkerIconLabel();
/**
* Set label for marker icon
*/
public void setMarkerIconLabel(String lbl);
/**
* Replace icon image for icon
* @param in - input stream for PNG file
*/
public void setMarkerIconImage(InputStream in);
/**
* Delete icon (not functional on builtin icons)
*/
public void deleteIcon();
/** /**
* Is builtin marker * Is builtin marker
* @return true * @return true

View File

@ -71,6 +71,11 @@ public interface MarkerSet {
* @param icon - icon to be added * @param icon - icon to be added
*/ */
public void addAllowedMarkerIcon(MarkerIcon icon); public void addAllowedMarkerIcon(MarkerIcon icon);
/**
* Remove marker icon from allowed set (must have been created restricted)
* @param icon - icon to be added
*/
public void removeAllowedMarkerIcon(MarkerIcon icon);
/** /**
* Test if marker icon is allowed * Test if marker icon is allowed
* @param icon - marker icon * @param icon - marker icon

View File

@ -12,6 +12,8 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
@ -174,7 +176,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
return ico; return ico;
} }
private void publishMarkerIcon(MarkerIcon ico) { void publishMarkerIcon(MarkerIcon ico) {
byte[] buf = new byte[512]; byte[] buf = new byte[512];
InputStream in = null; InputStream in = null;
File infile = new File(markerdir, ico.getMarkerIconID() + ".png"); /* Get source file name */ File infile = new File(markerdir, ico.getMarkerIconID() + ".png"); /* Get source file name */
@ -250,10 +252,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
return markericons.get(id); return markericons.get(id);
} }
@Override boolean loadMarkerIconStream(String id, InputStream in) {
public MarkerIcon createMarkerIcon(String id, String label, InputStream marker_png) {
if(markericons.containsKey(id)) return null; /* Exists? */
MarkerIconImpl ico = new MarkerIconImpl(id, label, false);
/* Copy icon resource into marker directory */ /* Copy icon resource into marker directory */
File f = new File(markerdir, id + ".png"); File f = new File(markerdir, id + ".png");
FileOutputStream fos = null; FileOutputStream fos = null;
@ -261,15 +260,24 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
byte[] buf = new byte[512]; byte[] buf = new byte[512];
int len; int len;
fos = new FileOutputStream(f); fos = new FileOutputStream(f);
while((len = marker_png.read(buf)) > 0) { while((len = in.read(buf)) > 0) {
fos.write(buf, 0, len); fos.write(buf, 0, len);
} }
} catch (IOException iox) { } catch (IOException iox) {
Log.severe("Error copying marker - " + f.getPath()); Log.severe("Error copying marker - " + f.getPath());
return null; return false;
} finally { } finally {
if(fos != null) try { fos.close(); } catch (IOException x) {} if(fos != null) try { fos.close(); } catch (IOException x) {}
} }
return true;
}
@Override
public MarkerIcon createMarkerIcon(String id, String label, InputStream marker_png) {
if(markericons.containsKey(id)) return null; /* Exists? */
MarkerIconImpl ico = new MarkerIconImpl(id, label, false);
/* Copy icon resource into marker directory */
if(!loadMarkerIconStream(id, marker_png))
return null;
markericons.put(id, ico); /* Add to set */ markericons.put(id, ico); /* Add to set */
/* Publish the marker */ /* Publish the marker */
@ -406,8 +414,16 @@ 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", "updateset", "deleteset", "listsets", "addicon" "add", "movehere", "update", "delete", "list", "icons", "addset", "updateset", "deleteset", "listsets", "addicon", "updateicon",
"deleteicon"
})); }));
private static final String ARG_LABEL = "label";
private static final String ARG_ID = "id";
private static final String ARG_NEWLABEL = "newlabel";
private static final String ARG_FILE = "file";
private static final String ARG_HIDE = "hide";
private static final String ARG_ICON = "icon";
private static final String ARG_SET = "set";
/* 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) {
@ -426,7 +442,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
if(c == '\"') { /* End quote */ if(c == '\"') { /* End quote */
inquote = false; inquote = false;
if(varid == null) { /* No varid? */ if(varid == null) { /* No varid? */
rslt.put("label", sb.toString()); rslt.put(ARG_LABEL, sb.toString());
} }
else { else {
rslt.put(varid, sb.toString()); rslt.put(varid, sb.toString());
@ -448,7 +464,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
else if(c == ' ') { /* Ending space? */ else if(c == ' ') { /* Ending space? */
if(varid == null) { /* No varid? */ if(varid == null) { /* No varid? */
if(sb.length() > 0) { if(sb.length() > 0) {
rslt.put("label", sb.toString()); rslt.put(ARG_LABEL, sb.toString());
} }
} }
else { else {
@ -468,7 +484,11 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
return rslt; return rslt;
} }
public static boolean onCommand(DynmapPlugin plugin, CommandSender sender, Command cmd, String commandLabel, String[] args) { public static boolean onCommand(DynmapPlugin plugin, CommandSender sender, Command cmd, String commandLabel, String[] args) {
String id, setid, file, label, newlabel, iconid;
if(api == null) { if(api == null) {
sender.sendMessage("Markers component is not enabled."); sender.sendMessage("Markers component is not enabled.");
return false; return false;
@ -492,27 +512,31 @@ 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;
iconid = parms.get(ARG_ICON);
setid = parms.get(ARG_SET);
id = parms.get(ARG_ID);
label = parms.get(ARG_LABEL);
Location loc = player.getLocation(); Location loc = player.getLocation();
/* Fill in defaults for missing parameters */ /* Fill in defaults for missing parameters */
if(parms.get("icon") == null) { if(iconid == null) {
parms.put("icon", MarkerIcon.DEFAULT); iconid = MarkerIcon.DEFAULT;
} }
if(parms.get("set") == null) { if(setid == null) {
parms.put("set", MarkerSet.DEFAULT); setid = MarkerSet.DEFAULT;
} }
/* Add new marker */ /* Add new marker */
MarkerSet set = api.getMarkerSet(parms.get("set")); MarkerSet set = api.getMarkerSet(setid);
if(set == null) { if(set == null) {
sender.sendMessage("Error: invalid marker set - " + parms.get("set")); sender.sendMessage("Error: invalid marker set - " + setid);
return true; return true;
} }
MarkerIcon ico = api.getMarkerIcon(parms.get("icon")); MarkerIcon ico = api.getMarkerIcon(iconid);
if(ico == null) { if(ico == null) {
sender.sendMessage("Error: invalid icon - " + parms.get("icon")); sender.sendMessage("Error: invalid icon - " + iconid);
return true; return true;
} }
Marker m = set.createMarker(parms.get("id"), parms.get("label"), Marker m = set.createMarker(id, label,
loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), ico, true); loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), ico, true);
if(m == null) { if(m == null) {
sender.sendMessage("Error creating marker"); sender.sendMessage("Error creating marker");
@ -534,30 +558,33 @@ 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) && (parms.get("label") == null)) { id = parms.get(ARG_ID);
label = parms.get(ARG_LABEL);
setid = parms.get(ARG_SET);
if((id == null) && (label == null)) {
sender.sendMessage("<label> or id:<marker-id> required"); sender.sendMessage("<label> or id:<marker-id> required");
return true; return true;
} }
if(parms.get("set") == null) { if(setid == null) {
parms.put("set", MarkerSet.DEFAULT); setid = MarkerSet.DEFAULT;
} }
MarkerSet set = api.getMarkerSet(parms.get("set")); MarkerSet set = api.getMarkerSet(setid);
if(set == null) { if(set == null) {
sender.sendMessage("Error: invalid marker set - " + parms.get("set")); sender.sendMessage("Error: invalid marker set - " + setid);
return true; return true;
} }
Marker marker; Marker marker;
if(parms.get("id") != null) { if(id != null) {
marker = set.findMarker(parms.get("id")); marker = set.findMarker(id);
if(marker == null) { /* No marker */ if(marker == null) { /* No marker */
sender.sendMessage("Error: marker not found - " + parms.get("id")); sender.sendMessage("Error: marker not found - " + id);
return true; return true;
} }
} }
else { else {
marker = set.findMarkerByLabel(parms.get("label")); marker = set.findMarkerByLabel(label);
if(marker == null) { /* No marker */ if(marker == null) { /* No marker */
sender.sendMessage("Error: marker not found - " + parms.get("label")); sender.sendMessage("Error: marker not found - " + label);
return true; return true;
} }
} }
@ -575,40 +602,45 @@ 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) && (parms.get("label") == null)) { id = parms.get(ARG_ID);
label = parms.get(ARG_LABEL);
setid = parms.get(ARG_SET);
if((id == null) && (label == null)) {
sender.sendMessage("<label> or id:<marker-id> required"); sender.sendMessage("<label> or id:<marker-id> required");
return true; return true;
} }
if(parms.get("set") == null) { if(setid == null) {
parms.put("set", MarkerSet.DEFAULT); setid = MarkerSet.DEFAULT;
} }
MarkerSet set = api.getMarkerSet(parms.get("set")); MarkerSet set = api.getMarkerSet(setid);
if(set == null) { if(set == null) {
sender.sendMessage("Error: invalid marker set - " + parms.get("set")); sender.sendMessage("Error: invalid marker set - " + setid);
return true; return true;
} }
Marker marker; Marker marker;
if(parms.get("id") != null) { if(id != null) {
marker = set.findMarker(parms.get("id")); marker = set.findMarker(id);
if(marker == null) { /* No marker */ if(marker == null) { /* No marker */
sender.sendMessage("Error: marker not found - " + parms.get("id")); sender.sendMessage("Error: marker not found - " + id);
return true; return true;
} }
} }
else { else {
marker = set.findMarkerByLabel(parms.get("label")); marker = set.findMarkerByLabel(label);
if(marker == null) { /* No marker */ if(marker == null) { /* No marker */
sender.sendMessage("Error: marker not found - " + parms.get("label")); sender.sendMessage("Error: marker not found - " + label);
return true; return true;
} }
} }
if(parms.get("newlabel") != null) { /* Label set? */ newlabel = parms.get(ARG_NEWLABEL);
marker.setLabel(parms.get("newlabel")); if(newlabel != null) { /* Label set? */
marker.setLabel(newlabel);
} }
if(parms.get("icon") != null) { iconid = parms.get(ARG_ICON);
MarkerIcon ico = api.getMarkerIcon(parms.get("icon")); if(iconid != null) {
MarkerIcon ico = api.getMarkerIcon(iconid);
if(ico == null) { if(ico == null) {
sender.sendMessage("Error: invalid icon - " + parms.get("icon")); sender.sendMessage("Error: invalid icon - " + iconid);
return true; return true;
} }
marker.setMarkerIcon(ico); marker.setMarkerIcon(ico);
@ -625,30 +657,33 @@ 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) && (parms.get("label") == null)) { id = parms.get(ARG_ID);
label = parms.get(ARG_LABEL);
setid = parms.get(ARG_SET);
if((id == null) && (label == null)) {
sender.sendMessage("<label> or id:<marker-id> required"); sender.sendMessage("<label> or id:<marker-id> required");
return true; return true;
} }
if(parms.get("set") == null) { if(setid == null) {
parms.put("set", MarkerSet.DEFAULT); setid = MarkerSet.DEFAULT;
} }
MarkerSet set = api.getMarkerSet(parms.get("set")); MarkerSet set = api.getMarkerSet(setid);
if(set == null) { if(set == null) {
sender.sendMessage("Error: invalid marker set - " + parms.get("set")); sender.sendMessage("Error: invalid marker set - " + setid);
return true; return true;
} }
Marker marker; Marker marker;
if(parms.get("id") != null) { if(id != null) {
marker = set.findMarker(parms.get("id")); marker = set.findMarker(id);
if(marker == null) { /* No marker */ if(marker == null) { /* No marker */
sender.sendMessage("Error: marker not found - " + parms.get("id")); sender.sendMessage("Error: marker not found - " + id);
return true; return true;
} }
} }
else { else {
marker = set.findMarkerByLabel(parms.get("label")); marker = set.findMarkerByLabel(label);
if(marker == null) { /* No marker */ if(marker == null) { /* No marker */
sender.sendMessage("Error: marker not found - " + parms.get("label")); sender.sendMessage("Error: marker not found - " + label);
return true; return true;
} }
} }
@ -664,24 +699,31 @@ 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("set") == null) { setid = parms.get(ARG_SET);
parms.put("set", MarkerSet.DEFAULT); if(setid == null) {
setid = MarkerSet.DEFAULT;
} }
MarkerSet set = api.getMarkerSet(parms.get("set")); MarkerSet set = api.getMarkerSet(setid);
if(set == null) { if(set == null) {
sender.sendMessage("Error: invalid marker set - " + parms.get("set")); sender.sendMessage("Error: invalid marker set - " + setid);
return true; return true;
} }
Set<Marker> markers = set.getMarkers(); Set<Marker> markers = set.getMarkers();
TreeMap<String, Marker> sortmarkers = new TreeMap<String, Marker>();
for(Marker m : markers) { for(Marker m : markers) {
sortmarkers.put(m.getMarkerID(), m);
}
for(String s : sortmarkers.keySet()) {
Marker m = sortmarkers.get(s);
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<String> iconids = new TreeSet<String>(api.markericons.keySet());
for(MarkerIcon ico : icons) { for(String s : iconids) {
MarkerIcon ico = api.markericons.get(s);
sender.sendMessage(ico.getMarkerIconID() + ": label:\"" + ico.getMarkerIconLabel() + "\", builtin:" + ico.isBuiltIn()); sender.sendMessage(ico.getMarkerIconID() + ": label:\"" + ico.getMarkerIconLabel() + "\", builtin:" + ico.isBuiltIn());
} }
} }
@ -690,27 +732,29 @@ 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) && (parms.get("label") == null)) { id = parms.get(ARG_ID);
label = parms.get(ARG_LABEL);
if((id == null) && (label == null)) {
sender.sendMessage("<label> or id:<marker-id> required"); sender.sendMessage("<label> or id:<marker-id> required");
return true; return true;
} }
if(parms.get("label") == null) if(label == null)
parms.put("label", parms.get("id")); label = id;
if(parms.get("id") == null) if(id == null)
parms.put("id", parms.get("label")); id = label;
/* See if marker set exists */ /* See if marker set exists */
MarkerSet set = api.getMarkerSet(parms.get("id")); MarkerSet set = api.getMarkerSet(id);
if(set != null) { if(set != null) {
sender.sendMessage("Error: set already exists - id:" + set.getMarkerSetID()); sender.sendMessage("Error: set already exists - id:" + set.getMarkerSetID());
return true; return true;
} }
/* Create new set */ /* Create new set */
set = api.createMarkerSet(parms.get("id"), parms.get("label"), null, true); set = api.createMarkerSet(id, label, null, true);
if(set == null) { if(set == null) {
sender.sendMessage("Error creating marker set"); sender.sendMessage("Error creating marker set");
} }
else { else {
String h = parms.get("hide"); String h = parms.get(ARG_HIDE);
if((h != null) && (h.equals("true"))) if((h != null) && (h.equals("true")))
set.setHideByDefault(true); set.setHideByDefault(true);
sender.sendMessage("Added marker set id:'" + set.getMarkerSetID() + "' (" + set.getMarkerSetLabel() + ")"); sender.sendMessage("Added marker set id:'" + set.getMarkerSetID() + "' (" + set.getMarkerSetLabel() + ")");
@ -725,22 +769,24 @@ 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) && (parms.get("label") == null)) { id = parms.get(ARG_ID);
label = parms.get(ARG_LABEL);
if((id == null) && (label == null)) {
sender.sendMessage("<label> or id:<marker-id> required"); sender.sendMessage("<label> or id:<marker-id> required");
return true; return true;
} }
MarkerSet set = null; MarkerSet set = null;
if(parms.get("id") != null) { if(id != null) {
set = api.getMarkerSet(parms.get("id")); set = api.getMarkerSet(id);
if(set == null) { if(set == null) {
sender.sendMessage("Error: set does not exist - id:" + set.getMarkerSetID()); sender.sendMessage("Error: set does not exist - id:" + id);
return true; return true;
} }
} }
else { else {
Set<MarkerSet> sets = api.getMarkerSets(); Set<MarkerSet> sets = api.getMarkerSets();
for(MarkerSet s : sets) { for(MarkerSet s : sets) {
if(s.getMarkerSetLabel().equals(parms.get("label"))) { if(s.getMarkerSetLabel().equals(label)) {
set = s; set = s;
break; break;
} }
@ -750,12 +796,15 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
return true; return true;
} }
} }
if(parms.get("newLabel") != null) { newlabel = parms.get(ARG_NEWLABEL);
set.setMarkerSetLabel(parms.get("netlabel")); if(newlabel != null) {
set.setMarkerSetLabel(newlabel);
} }
if(parms.get("hide") != null) { String hide = parms.get(ARG_HIDE);
set.setHideByDefault(parms.get("hide").equals("true")); if(hide != null) {
set.setHideByDefault(hide.equals("true"));
} }
sender.sendMessage("Marker set '" + set.getMarkerSetID() + "' updated");
} }
else { else {
sender.sendMessage("<label> or id:<set-id> required"); sender.sendMessage("<label> or id:<set-id> required");
@ -766,14 +815,16 @@ 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) && (parms.get("label") == null)) { id = parms.get(ARG_ID);
sender.sendMessage("<label> or id:<marker-id> required"); label = parms.get(ARG_LABEL);
if((id == null) && (label == null)) {
sender.sendMessage("<label> or id:<set-id> required");
return true; return true;
} }
if(parms.get("id") != null) { if(id != null) {
MarkerSet set = api.getMarkerSet(parms.get("id")); MarkerSet set = api.getMarkerSet(id);
if(set == null) { if(set == null) {
sender.sendMessage("Error: set does not exist - id:" + set.getMarkerSetID()); sender.sendMessage("Error: set does not exist - id:" + id);
return true; return true;
} }
set.deleteMarkerSet(); set.deleteMarkerSet();
@ -782,7 +833,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
Set<MarkerSet> sets = api.getMarkerSets(); Set<MarkerSet> sets = api.getMarkerSets();
MarkerSet set = null; MarkerSet set = null;
for(MarkerSet s : sets) { for(MarkerSet s : sets) {
if(s.getMarkerSetLabel().equals(parms.get("label"))) { if(s.getMarkerSetLabel().equals(label)) {
set = s; set = s;
break; break;
} }
@ -801,8 +852,9 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
} }
/* List sets */ /* List sets */
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<String> setids = new TreeSet<String>(api.markersets.keySet());
for(MarkerSet set : sets) { for(String s : setids) {
MarkerSet set = api.markersets.get(s);
sender.sendMessage(set.getMarkerSetID() + ": label:\"" + set.getMarkerSetLabel() + "\", hide=" + set.getHideByDefault()); sender.sendMessage(set.getMarkerSetID() + ": label:\"" + set.getMarkerSetLabel() + "\", hide=" + set.getHideByDefault());
} }
} }
@ -812,29 +864,31 @@ 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) { id = parms.get(ARG_ID);
file = parms.get(ARG_FILE);
label = parms.get(ARG_LABEL);
if(id == null) {
sender.sendMessage("id:<icon-id> required"); sender.sendMessage("id:<icon-id> required");
return true; return true;
} }
if(parms.get("file") == null) { if(file == null) {
sender.sendMessage("file:\"filename\" required"); sender.sendMessage("file:\"filename\" required");
return true; return true;
} }
String id = parms.get("id"); if(label == null)
if(parms.get("label") == null) label = id;
parms.put("label", id);
MarkerIcon ico = api.getMarkerIcon(id); MarkerIcon ico = api.getMarkerIcon(id);
if(ico != null) { if(ico != null) {
sender.sendMessage("Icon '" + id + "' already defined."); sender.sendMessage("Icon '" + id + "' already defined.");
return true; return true;
} }
/* Open stream to filename */ /* Open stream to filename */
File iconf = new File(parms.get("file")); File iconf = new File(file);
FileInputStream fis = null; FileInputStream fis = null;
try { try {
fis = new FileInputStream(iconf); fis = new FileInputStream(iconf);
/* Create new icon */ /* Create new icon */
MarkerIcon mi = api.createMarkerIcon(parms.get("id"), parms.get("label"), fis); MarkerIcon mi = api.createMarkerIcon(id, label, fis);
if(mi == null) { if(mi == null) {
sender.sendMessage("Error creating icon"); sender.sendMessage("Error creating icon");
return true; return true;
@ -848,7 +902,105 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
} }
} }
else { else {
sender.sendMessage("id:<set-id> and file:\"filename\" required"); sender.sendMessage("id:<icon-id> and file:\"filename\" required");
}
}
else if(c.equals("updateicon") && plugin.checkPlayerPermission(sender, "marker.updateicon")) {
if(args.length > 1) {
/* Parse arguements */
Map<String,String> parms = parseArgs(args, sender);
if(parms == null) return true;
id = parms.get(ARG_ID);
label = parms.get(ARG_LABEL);
newlabel = parms.get(ARG_NEWLABEL);
file = parms.get(ARG_FILE);
if((id == null) && (label == null)) {
sender.sendMessage("<label> or id:<icon-id> required");
return true;
}
MarkerIcon ico = null;
if(id != null) {
ico = api.getMarkerIcon(id);
if(ico == null) {
sender.sendMessage("Error: icon does not exist - id:" + id);
return true;
}
}
else {
Set<MarkerIcon> icons = api.getMarkerIcons();
for(MarkerIcon ic : icons) {
if(ic.getMarkerIconLabel().equals(label)) {
ico = ic;
break;
}
}
if(ico == null) {
sender.sendMessage("Error: matching icon not found");
return true;
}
}
if(newlabel != null) {
ico.setMarkerIconLabel(newlabel);
}
/* Handle new file */
if(file != null) {
File iconf = new File(file);
FileInputStream fis = null;
try {
fis = new FileInputStream(iconf);
ico.setMarkerIconImage(fis);
} catch (IOException iox) {
sender.sendMessage("Error loading icon file - " + iox);
} finally {
if(fis != null) {
try { fis.close(); } catch (IOException iox) {}
}
}
}
sender.sendMessage("Icon '" + ico.getMarkerIconID() + "' updated");
}
else {
sender.sendMessage("<label> or id:<icon-id> required");
}
}
else if(c.equals("deleteicon") && plugin.checkPlayerPermission(sender, "marker.deleteicon")) {
if(args.length > 1) {
/* Parse arguements */
Map<String,String> parms = parseArgs(args, sender);
if(parms == null) return true;
id = parms.get(ARG_ID);
label = parms.get(ARG_LABEL);
if((id == null) && (label == null)) {
sender.sendMessage("<label> or id:<icon-id> required");
return true;
}
if(id != null) {
MarkerIcon ico = api.getMarkerIcon(id);
if(ico == null) {
sender.sendMessage("Error: icon does not exist - id:" + id);
return true;
}
ico.deleteIcon();
}
else {
Set<MarkerIcon> icos = api.getMarkerIcons();
MarkerIcon ico = null;
for(MarkerIcon ic : icos) {
if(ic.getMarkerIconLabel().equals(label)) {
ico = ic;
break;
}
}
if(ico == null) {
sender.sendMessage("Error: matching icon not found");
return true;
}
ico.deleteIcon();
}
sender.sendMessage("Deleted marker icon");
}
else {
sender.sendMessage("<label> or id:<icon-id> required");
} }
} }
else { else {
@ -912,4 +1064,31 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
/* Update markers for now-active world */ /* Update markers for now-active world */
writeMarkersFile(t.world.getName()); writeMarkersFile(t.world.getName());
} }
/* Remove icon */
static void removeIcon(MarkerIcon ico) {
MarkerIcon def = api.getMarkerIcon(MarkerIcon.DEFAULT);
/* Need to scrub all uses of this icon from markers */
for(MarkerSet s : api.markersets.values()) {
for(Marker m : s.getMarkers()) {
if(m.getMarkerIcon() == ico) {
m.setMarkerIcon(def); /* Set to default */
}
}
Set<MarkerIcon> allowed = s.getAllowedMarkerIcons();
if((allowed != null) && (allowed.contains(ico))) {
s.removeAllowedMarkerIcon(ico);
}
}
/* Remove files */
File f = new File(api.markerdir, ico.getMarkerIconID() + ".png");
f.delete();
f = new File(api.markertiledir, ico.getMarkerIconID() + ".png");
f.delete();
/* Remove from marker icons */
api.markericons.remove(ico.getMarkerIconID());
saveMarkers();
}
} }

View File

@ -1,9 +1,14 @@
package org.dynmap.markers.impl; package org.dynmap.markers.impl;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.util.config.ConfigurationNode; import org.bukkit.util.config.ConfigurationNode;
import org.dynmap.Log;
import org.dynmap.markers.MarkerIcon; import org.dynmap.markers.MarkerIcon;
class MarkerIconImpl implements MarkerIcon { class MarkerIconImpl implements MarkerIcon {
@ -40,6 +45,26 @@ class MarkerIconImpl implements MarkerIcon {
return label; return label;
} }
@Override
public void setMarkerIconLabel(String lbl) {
if(lbl == null) lbl = iconid;
if(label.equals(lbl) == false) {
label = lbl;
MarkerAPIImpl.saveMarkers();
}
}
@Override
public void setMarkerIconImage(InputStream in) {
if(MarkerAPIImpl.api.loadMarkerIconStream(this.iconid, in))
MarkerAPIImpl.api.publishMarkerIcon(this);
}
@Override
public void deleteIcon() {
MarkerAPIImpl.removeIcon(this);
}
@Override @Override
public boolean isBuiltIn() { public boolean isBuiltIn() {
return is_builtin; return is_builtin;

View File

@ -142,6 +142,16 @@ class MarkerSetImpl implements MarkerSet {
MarkerAPIImpl.saveMarkers(); MarkerAPIImpl.saveMarkers();
} }
@Override
public void removeAllowedMarkerIcon(MarkerIcon icon) {
if(!(icon instanceof MarkerIconImpl)) return;
if(allowedicons == null) return;
allowedicons.remove(icon.getMarkerIconID());
MarkerAPIImpl.markerSetUpdated(this, MarkerUpdate.UPDATED);
if(ispersistent)
MarkerAPIImpl.saveMarkers();
}
@Override @Override
public boolean isAllowedMarkerIcon(MarkerIcon icon) { public boolean isAllowedMarkerIcon(MarkerIcon icon) {
if(allowedicons == null) return true; if(allowedicons == null) return true;

View File

@ -37,10 +37,16 @@ commands:
/<command> icons - list details of all icons /<command> icons - list details of all icons
/<command> addset <label> - add marker set with given label (ID=label) /<command> addset <label> - add marker set with given label (ID=label)
/<command> addset id:<id> <label> - add marker set with given ID and label /<command> addset id:<id> <label> - add marker set with given ID and label
/<command> updateset id:<id> newlabel:<label> - update marker set with given ID
/<command> updateset <label> newlabel:<label> - update marker set with given label
/<command> deleteset <label> - delete marker set with given label /<command> deleteset <label> - delete marker set with given label
/<command> deleteset id:<id> - delete marker set with given ID /<command> deleteset id:<id> - delete marker set with given ID
/<command> listsets - list all marker sets /<command> listsets - list all marker sets
/<command> addicon id:<id> <label> file:"filename" - install new icon /<command> addicon id:<id> <label> file:"filename" - install new icon
/<command> updateicon id:<id> newlabel:<label> file:"filename" - update existing icon
/<command> updateicon <label> newlabel:<label> file:"filename" - update existing icon
/<command> deleteicon id:<id> - remove icon
/<command> deleteicon <label> - remove icon
permissions: permissions:
dynmap.*: dynmap.*:
@ -70,6 +76,8 @@ permissions:
dynmap.marker.deleteset: true dynmap.marker.deleteset: true
dynmap.marker.listsets: true dynmap.marker.listsets: true
dynmap.marker.addicon: true dynmap.marker.addicon: true
dynmap.marker.updateicon: true
dynmap.marker.deleteicon: true
dynmap.render: dynmap.render:
description: Allows /dynmap render command description: Allows /dynmap render command
default: true default: true
@ -139,4 +147,10 @@ permissions:
dynmap.marker.addicon: dynmap.marker.addicon:
description: Allows /dmarker addicon description: Allows /dmarker addicon
default: op default: op
dynmap.marker.updateicon:
description: Allows /dmarker updateicon
default: op
dynmap.marker.deleteicon:
description: Allows /dmarker deleteicon
default: op