Add default marker set

This commit is contained in:
Mike Primm 2011-09-02 23:02:23 -05:00
parent f6a4f3e619
commit c486c42de8
86 changed files with 134 additions and 11 deletions

View File

@ -213,8 +213,6 @@ public class DynmapPlugin extends JavaPlugin {
dataDirectory = this.getDataFolder(); dataDirectory = this.getDataFolder();
/* Initialize marker API, if not already done */
MarkerAPI m_api = getMarkerAPI();
/* Load block models */ /* Load block models */
HDBlockModels.loadModels(dataDirectory); HDBlockModels.loadModels(dataDirectory);
/* Load texture mappings */ /* Load texture mappings */
@ -254,6 +252,8 @@ public class DynmapPlugin extends JavaPlugin {
if (!tilesDirectory.isDirectory() && !tilesDirectory.mkdirs()) { if (!tilesDirectory.isDirectory() && !tilesDirectory.mkdirs()) {
Log.warning("Could not create directory for tiles ('" + tilesDirectory + "')."); Log.warning("Could not create directory for tiles ('" + tilesDirectory + "').");
} }
/* Initialize marker API (after tilesDirectory is ready) */
MarkerAPI m_api = getMarkerAPI();
playerList = new PlayerList(getServer(), getFile("hiddenplayers.txt"), configuration); playerList = new PlayerList(getServer(), getFile("hiddenplayers.txt"), configuration);
playerList.load(); playerList.load();

View File

@ -1,6 +1,7 @@
package org.dynmap.markers; package org.dynmap.markers;
import java.io.File; import java.io.File;
import java.io.InputStream;
import java.util.Set; import java.util.Set;
/** /**
@ -42,8 +43,8 @@ public interface MarkerAPI {
* Register a new marker icon * Register a new marker icon
* @param id - ID of marker icon (must be unique among marker icons - letters, numbers, periods, underscores only) * @param id - ID of marker icon (must be unique among marker icons - letters, numbers, periods, underscores only)
* @param label - label for marker icon * @param label - label for marker icon
* @param markerfile - file containing PNG encoded icon for marker (will be copied) * @param marker_png - stream containing PNG encoded icon for marker (will be read and copied)
* @return marker icon object, or null if failed * @return marker icon object, or null if failed
*/ */
public MarkerIcon createMarkerIcon(String id, String label, File markerfile); public MarkerIcon createMarkerIcon(String id, String label, InputStream marker_png);
} }

View File

@ -6,7 +6,8 @@ package org.dynmap.markers;
public interface MarkerIcon { public interface MarkerIcon {
/** Default marker icon - always exists */ /** Default marker icon - always exists */
public static final String DEFAULT = "default"; public static final String DEFAULT = "default";
/** /**
* Get ID of the marker icon (unique among marker icons) * Get ID of the marker icon (unique among marker icons)
* @return ID * @return ID
@ -17,4 +18,9 @@ public interface MarkerIcon {
* @return icon label * @return icon label
*/ */
public String getMarkerIconLabel(); public String getMarkerIconLabel();
/**
* Is builtin marker
* @return true
*/
public boolean isBuiltIn();
} }

View File

@ -1,6 +1,11 @@
package org.dynmap.markers.impl; package org.dynmap.markers.impl;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -25,10 +30,24 @@ import org.dynmap.markers.MarkerSet;
*/ */
public class MarkerAPIImpl implements MarkerAPI { public class MarkerAPIImpl implements MarkerAPI {
private File markerpersist; private File markerpersist;
private File markerdir; /* Local store for markers (internal) */
private File markertiledir; /* Marker directory for web server (under tiles) */
private HashMap<String, MarkerIconImpl> markericons = new HashMap<String, MarkerIconImpl>(); private HashMap<String, MarkerIconImpl> markericons = new HashMap<String, MarkerIconImpl>();
private HashMap<String, MarkerSetImpl> markersets = new HashMap<String, MarkerSetImpl>(); private HashMap<String, MarkerSetImpl> markersets = new HashMap<String, MarkerSetImpl>();
static MarkerAPIImpl api; static MarkerAPIImpl api;
/* Built-in icons */
private static final String[] builtin_icons = {
"anchor", "bank", "basket", "beer", "bighouse", "blueflag", "bomb", "bookshelf", "bricks", "bronzemedal", "bronzestar",
"building", "cake", "camera", "cart", "caution", "chest", "church", "coins", "comment", "compass", "construction",
"cross", "cup", "cutlery", "default", "diamond", "dog", "door", "down", "drink", "exclamation", "factory",
"fire", "flower", "gear", "goldmedal", "goldstar", "greenflag", "hammer", "heart", "house", "key", "king",
"left", "lightbulb", "lighthouse", "lock", "orangeflag", "pin", "pinkflag", "pirateflag", "pointdown", "pointleft",
"pointright", "pointup", "purpleflag", "queen", "redflag", "right", "ruby", "scales", "skull", "shield", "sign",
"silvermedal", "silverstar", "star", "sun", "temple", "theater", "tornado", "tower", "tree", "truck", "up",
"walk", "warning", "world", "wrench", "yellowflag"
};
/** /**
* Singleton initializer * Singleton initializer
@ -43,12 +62,29 @@ public class MarkerAPIImpl implements MarkerAPI {
/* Load persistence */ /* Load persistence */
api.loadMarkers(); api.loadMarkers();
/* Fill in default icons and sets, if needed */ /* Fill in default icons and sets, if needed */
if(api.getMarkerIcon(MarkerIcon.DEFAULT) == null) { for(int i = 0; i < builtin_icons.length; i++) {
api.createMarkerIcon(MarkerIcon.DEFAULT, "Marker", null); String id = builtin_icons[i];
if(api.getMarkerIcon(id) == null) {
api.createBuiltinMarkerIcon(id, id);
}
} }
if(api.getMarkerSet(MarkerSet.DEFAULT) == null) { if(api.getMarkerSet(MarkerSet.DEFAULT) == null) {
api.createMarkerSet(MarkerSet.DEFAULT, "Markers", null, true); api.createMarkerSet(MarkerSet.DEFAULT, "Markers", null, true);
} }
/* Build paths for markers */
api.markerdir = new File(plugin.getDataFolder(), "markers");
if(api.markerdir.mkdirs() == false) { /* Create directory if needed */
Log.severe("Error creating markers directory - " + api.markerdir.getPath());
}
api.markertiledir = new File(DynmapPlugin.tilesDirectory, "_markers_");
if(api.markertiledir.mkdirs() == false) { /* Create directory if needed */
Log.severe("Error creating markers directory - " + api.markertiledir.getPath());
}
/* Now publish marker files to the tiles directory */
for(MarkerIcon ico : api.getMarkerIcons()) {
api.publishMarkerIcon(ico);
}
return api; return api;
} }
@ -63,6 +99,54 @@ public class MarkerAPIImpl implements MarkerAPI {
set.cleanup(); set.cleanup();
markersets.clear(); markersets.clear();
} }
private MarkerIcon createBuiltinMarkerIcon(String id, String label) {
if(markericons.containsKey(id)) return null; /* Exists? */
MarkerIconImpl ico = new MarkerIconImpl(id, label, true);
markericons.put(id, ico); /* Add to set */
return ico;
}
private void publishMarkerIcon(MarkerIcon ico) {
byte[] buf = new byte[512];
InputStream in = null;
File infile = new File(markerdir, ico.getMarkerIconID() + ".png"); /* Get source file name */
File outfile = new File(markertiledir, ico.getMarkerIconID() + ".png"); /* Destination */
OutputStream out = null;
try {
out = new FileOutputStream(outfile);
} catch (IOException iox) {
Log.severe("Cannot write marker to tilespath - " + outfile.getPath());
return;
}
if(ico.isBuiltIn()) {
in = getClass().getResourceAsStream("/markers/" + ico.getMarkerIconID() + ".png");
}
else if(infile.canRead()) { /* If it exists and is readable */
try {
in = new FileInputStream(infile);
} catch (IOException iox) {
Log.severe("Error opening marker " + infile.getPath() + " - " + iox);
}
}
if(in == null) { /* Not found, use default marker */
in = getClass().getResourceAsStream("/markers/marker.png");
if(in == null)
return;
}
/* Copy to destination */
try {
int len;
while((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} catch (IOException iox) {
Log.severe("Error writing marker to tilespath - " + outfile.getPath());
} finally {
if(in != null) try { in.close(); } catch (IOException x){}
if(out != null) try { out.close(); } catch (IOException x){}
}
}
@Override @Override
public Set<MarkerSet> getMarkerSets() { public Set<MarkerSet> getMarkerSets() {
@ -100,11 +184,29 @@ public class MarkerAPIImpl implements MarkerAPI {
} }
@Override @Override
public MarkerIcon createMarkerIcon(String id, String label, File markerfile) { public MarkerIcon createMarkerIcon(String id, String label, InputStream marker_png) {
if(markericons.containsKey(id)) return null; /* Exists? */ if(markericons.containsKey(id)) return null; /* Exists? */
MarkerIconImpl ico = new MarkerIconImpl(id, label); MarkerIconImpl ico = new MarkerIconImpl(id, label, false);
/* Copy icon resource into marker directory */
File f = new File(markerdir, id + ".png");
FileOutputStream fos = null;
try {
byte[] buf = new byte[512];
int len;
fos = new FileOutputStream(f);
while((len = marker_png.read(buf)) > 0) {
fos.write(buf, 0, len);
}
} catch (IOException iox) {
Log.severe("Error copying marker - " + f.getPath());
return null;
} finally {
if(fos != null) try { fos.close(); } catch (IOException x) {}
}
markericons.put(id, ico); /* Add to set */ markericons.put(id, ico); /* Add to set */
/* Publish the marker */
publishMarkerIcon(ico);
saveMarkers(); /* Save results */ saveMarkers(); /* Save results */

View File

@ -9,18 +9,21 @@ import org.dynmap.markers.MarkerIcon;
class MarkerIconImpl implements MarkerIcon { class MarkerIconImpl implements MarkerIcon {
private String iconid; private String iconid;
private String label; private String label;
private boolean is_builtin;
MarkerIconImpl(String id) { MarkerIconImpl(String id) {
iconid = id; iconid = id;
label = id; label = id;
is_builtin = false;
} }
MarkerIconImpl(String id, String lbl) { MarkerIconImpl(String id, String lbl, boolean is_builtin) {
iconid = id; iconid = id;
if(lbl != null) if(lbl != null)
label = lbl; label = lbl;
else else
label = id; label = id;
this.is_builtin = is_builtin;
} }
void cleanup() { void cleanup() {
@ -36,12 +39,20 @@ class MarkerIconImpl implements MarkerIcon {
public String getMarkerIconLabel() { public String getMarkerIconLabel() {
return label; return label;
} }
@Override
public boolean isBuiltIn() {
return is_builtin;
}
/** /**
* Get configuration node to be saved * Get configuration node to be saved
* @return node * @return node
*/ */
Map<String, Object> getPersistentData() { Map<String, Object> getPersistentData() {
if(is_builtin)
return null;
HashMap<String, Object> node = new HashMap<String, Object>(); HashMap<String, Object> node = new HashMap<String, Object>();
node.put("label", label); node.put("label", label);
@ -49,6 +60,9 @@ class MarkerIconImpl implements MarkerIcon {
} }
boolean loadPersistentData(ConfigurationNode node) { boolean loadPersistentData(ConfigurationNode node) {
if(is_builtin)
return false;
label = node.getString("label", iconid); label = node.getString("label", iconid);
return true; return true;

Binary file not shown.

After

Width:  |  Height:  |  Size: 831 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 871 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 959 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 729 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 906 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 710 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 920 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 722 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 691 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 689 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 709 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 659 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 737 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 568 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 650 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 716 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 652 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 910 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 660 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 671 B