Add /dmarker addicon command

This commit is contained in:
Mike Primm 2011-09-07 22:40:09 -05:00
parent 009c3a9429
commit 8a4e1ebfc2
2 changed files with 52 additions and 2 deletions

View File

@ -404,7 +404,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"
"add", "movehere", "update", "delete", "list", "icons", "addset", "deleteset", "listsets", "addicon"
}));
/* Parse argument strings : handle 'attrib:value' and quoted strings */
@ -760,6 +760,51 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
sender.sendMessage(set.getMarkerSetID() + ": label:\"" + set.getMarkerSetLabel() + "\"");
}
}
/* Add new icon */
else if(c.equals("addicon") && plugin.checkPlayerPermission(sender, "marker.addicon")) {
if(args.length > 1) {
/* Parse arguements */
Map<String,String> parms = parseArgs(args, sender);
if(parms == null) return true;
if(parms.get("id") == null) {
sender.sendMessage("id:<icon-id> required");
return true;
}
if(parms.get("file") == null) {
sender.sendMessage("file:\"filename\" required");
return true;
}
String id = parms.get("id");
if(parms.get("label") == null)
parms.put("label", id);
MarkerIcon ico = api.getMarkerIcon(id);
if(ico != null) {
sender.sendMessage("Icon '" + id + "' already defined.");
return true;
}
/* Open stream to filename */
File iconf = new File(parms.get("file"));
FileInputStream fis = null;
try {
fis = new FileInputStream(iconf);
/* Create new icon */
MarkerIcon mi = api.createMarkerIcon(parms.get("id"), parms.get("label"), fis);
if(mi == null) {
sender.sendMessage("Error creating icon");
return true;
}
} catch (IOException iox) {
sender.sendMessage("Error loading icon file - " + iox);
} finally {
if(fis != null) {
try { fis.close(); } catch (IOException iox) {}
}
}
}
else {
sender.sendMessage("id:<set-id> and file:\"filename\" required");
}
}
else {
return false;
}

View File

@ -40,6 +40,7 @@ commands:
/<command> deleteset <label> - delete marker set with given label
/<command> deleteset id:<id> - delete marker set with given ID
/<command> listsets - list all marker sets
/<command> addicon id:<id> <label> file:"filename" - install new icon
permissions:
dynmap.*:
@ -67,6 +68,7 @@ permissions:
dynmap.marker.addset: true
dynmap.marker.deleteset: true
dynmap.marker.listsets: true
dynmap.marker.addicon: true
dynmap.render:
description: Allows /dynmap render command
default: true
@ -130,4 +132,7 @@ permissions:
dynmap.marker.listsets:
description: Allows /dmarker listsets
default: true
dynmap.marker.addicon:
description: Allows /dmarker addicon
default: op