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();
/* Initialize marker API, if not already done */
MarkerAPI m_api = getMarkerAPI();
/* Load block models */
HDBlockModels.loadModels(dataDirectory);
/* Load texture mappings */
@ -254,6 +252,8 @@ public class DynmapPlugin extends JavaPlugin {
if (!tilesDirectory.isDirectory() && !tilesDirectory.mkdirs()) {
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.load();

View File

@ -1,6 +1,7 @@
package org.dynmap.markers;
import java.io.File;
import java.io.InputStream;
import java.util.Set;
/**
@ -42,8 +43,8 @@ public interface MarkerAPI {
* Register a new marker icon
* @param id - ID of marker icon (must be unique among marker icons - letters, numbers, periods, underscores only)
* @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
*/
public MarkerIcon createMarkerIcon(String id, String label, File markerfile);
public MarkerIcon createMarkerIcon(String id, String label, InputStream marker_png);
}

View File

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

View File

@ -1,6 +1,11 @@
package org.dynmap.markers.impl;
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.HashMap;
import java.util.HashSet;
@ -25,11 +30,25 @@ import org.dynmap.markers.MarkerSet;
*/
public class MarkerAPIImpl implements MarkerAPI {
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, MarkerSetImpl> markersets = new HashMap<String, MarkerSetImpl>();
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
*/
@ -43,12 +62,29 @@ public class MarkerAPIImpl implements MarkerAPI {
/* Load persistence */
api.loadMarkers();
/* Fill in default icons and sets, if needed */
if(api.getMarkerIcon(MarkerIcon.DEFAULT) == null) {
api.createMarkerIcon(MarkerIcon.DEFAULT, "Marker", null);
for(int i = 0; i < builtin_icons.length; i++) {
String id = builtin_icons[i];
if(api.getMarkerIcon(id) == null) {
api.createBuiltinMarkerIcon(id, id);
}
}
if(api.getMarkerSet(MarkerSet.DEFAULT) == null) {
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;
}
@ -64,6 +100,54 @@ public class MarkerAPIImpl implements MarkerAPI {
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
public Set<MarkerSet> getMarkerSets() {
return new HashSet<MarkerSet>(markersets.values());
@ -100,12 +184,30 @@ public class MarkerAPIImpl implements MarkerAPI {
}
@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? */
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 */
/* Publish the marker */
publishMarkerIcon(ico);
saveMarkers(); /* Save results */
return ico;

View File

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