Add default marker set
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
BIN
src/main/resources/markers/anchor.png
Normal file
After Width: | Height: | Size: 831 B |
BIN
src/main/resources/markers/bank.png
Normal file
After Width: | Height: | Size: 771 B |
BIN
src/main/resources/markers/basket.png
Normal file
After Width: | Height: | Size: 639 B |
BIN
src/main/resources/markers/beer.png
Normal file
After Width: | Height: | Size: 609 B |
BIN
src/main/resources/markers/bighouse.png
Normal file
After Width: | Height: | Size: 756 B |
BIN
src/main/resources/markers/blueflag.png
Normal file
After Width: | Height: | Size: 726 B |
BIN
src/main/resources/markers/bomb.png
Normal file
After Width: | Height: | Size: 871 B |
BIN
src/main/resources/markers/bookshelf.png
Normal file
After Width: | Height: | Size: 719 B |
BIN
src/main/resources/markers/bricks.png
Normal file
After Width: | Height: | Size: 959 B |
BIN
src/main/resources/markers/bronzemedal.png
Normal file
After Width: | Height: | Size: 657 B |
BIN
src/main/resources/markers/bronzestar.png
Normal file
After Width: | Height: | Size: 692 B |
BIN
src/main/resources/markers/building.png
Normal file
After Width: | Height: | Size: 630 B |
BIN
src/main/resources/markers/cake.png
Normal file
After Width: | Height: | Size: 792 B |
BIN
src/main/resources/markers/camera.png
Normal file
After Width: | Height: | Size: 729 B |
BIN
src/main/resources/markers/cart.png
Normal file
After Width: | Height: | Size: 745 B |
BIN
src/main/resources/markers/caution.png
Normal file
After Width: | Height: | Size: 543 B |
BIN
src/main/resources/markers/chest.png
Normal file
After Width: | Height: | Size: 476 B |
BIN
src/main/resources/markers/church.png
Normal file
After Width: | Height: | Size: 608 B |
BIN
src/main/resources/markers/coins.png
Normal file
After Width: | Height: | Size: 672 B |
BIN
src/main/resources/markers/comment.png
Normal file
After Width: | Height: | Size: 695 B |
BIN
src/main/resources/markers/compass.png
Normal file
After Width: | Height: | Size: 906 B |
BIN
src/main/resources/markers/construction.png
Normal file
After Width: | Height: | Size: 654 B |
BIN
src/main/resources/markers/cross.png
Normal file
After Width: | Height: | Size: 473 B |
BIN
src/main/resources/markers/cup.png
Normal file
After Width: | Height: | Size: 724 B |
BIN
src/main/resources/markers/cutlery.png
Normal file
After Width: | Height: | Size: 584 B |
BIN
src/main/resources/markers/default.png
Normal file
After Width: | Height: | Size: 781 B |
BIN
src/main/resources/markers/diamond.png
Normal file
After Width: | Height: | Size: 555 B |
BIN
src/main/resources/markers/dog.png
Normal file
After Width: | Height: | Size: 879 B |
BIN
src/main/resources/markers/door.png
Normal file
After Width: | Height: | Size: 606 B |
BIN
src/main/resources/markers/down.png
Normal file
After Width: | Height: | Size: 381 B |
BIN
src/main/resources/markers/drink.png
Normal file
After Width: | Height: | Size: 773 B |
BIN
src/main/resources/markers/exclamation.png
Normal file
After Width: | Height: | Size: 732 B |
BIN
src/main/resources/markers/factory.png
Normal file
After Width: | Height: | Size: 710 B |
BIN
src/main/resources/markers/fire.png
Normal file
After Width: | Height: | Size: 637 B |
BIN
src/main/resources/markers/flower.png
Normal file
After Width: | Height: | Size: 920 B |
BIN
src/main/resources/markers/gear.png
Normal file
After Width: | Height: | Size: 777 B |
BIN
src/main/resources/markers/goldmedal.png
Normal file
After Width: | Height: | Size: 664 B |
BIN
src/main/resources/markers/goldstar.png
Normal file
After Width: | Height: | Size: 699 B |
BIN
src/main/resources/markers/greenflag.png
Normal file
After Width: | Height: | Size: 722 B |
BIN
src/main/resources/markers/hammer.png
Normal file
After Width: | Height: | Size: 814 B |
BIN
src/main/resources/markers/heart.png
Normal file
After Width: | Height: | Size: 742 B |
BIN
src/main/resources/markers/house.png
Normal file
After Width: | Height: | Size: 727 B |
BIN
src/main/resources/markers/key.png
Normal file
After Width: | Height: | Size: 664 B |
BIN
src/main/resources/markers/king.png
Normal file
After Width: | Height: | Size: 691 B |
BIN
src/main/resources/markers/left.png
Normal file
After Width: | Height: | Size: 371 B |
BIN
src/main/resources/markers/lightbulb.png
Normal file
After Width: | Height: | Size: 685 B |
BIN
src/main/resources/markers/lighthouse.png
Normal file
After Width: | Height: | Size: 781 B |
BIN
src/main/resources/markers/lock.png
Normal file
After Width: | Height: | Size: 689 B |
BIN
src/main/resources/markers/orangeflag.png
Normal file
After Width: | Height: | Size: 709 B |
BIN
src/main/resources/markers/pin.png
Normal file
After Width: | Height: | Size: 521 B |
BIN
src/main/resources/markers/pinkflag.png
Normal file
After Width: | Height: | Size: 711 B |
BIN
src/main/resources/markers/pirateflag.png
Normal file
After Width: | Height: | Size: 753 B |
BIN
src/main/resources/markers/pointdown.png
Normal file
After Width: | Height: | Size: 659 B |
BIN
src/main/resources/markers/pointleft.png
Normal file
After Width: | Height: | Size: 617 B |
BIN
src/main/resources/markers/pointright.png
Normal file
After Width: | Height: | Size: 620 B |
BIN
src/main/resources/markers/pointup.png
Normal file
After Width: | Height: | Size: 637 B |
BIN
src/main/resources/markers/purpleflag.png
Normal file
After Width: | Height: | Size: 744 B |
BIN
src/main/resources/markers/queen.png
Normal file
After Width: | Height: | Size: 694 B |
BIN
src/main/resources/markers/redflag.png
Normal file
After Width: | Height: | Size: 737 B |
BIN
src/main/resources/markers/right.png
Normal file
After Width: | Height: | Size: 363 B |
BIN
src/main/resources/markers/ruby.png
Normal file
After Width: | Height: | Size: 568 B |
BIN
src/main/resources/markers/scales.png
Normal file
After Width: | Height: | Size: 664 B |
BIN
src/main/resources/markers/shield.png
Normal file
After Width: | Height: | Size: 704 B |
BIN
src/main/resources/markers/sign.png
Normal file
After Width: | Height: | Size: 650 B |
BIN
src/main/resources/markers/silvermedal.png
Normal file
After Width: | Height: | Size: 635 B |
BIN
src/main/resources/markers/silverstar.png
Normal file
After Width: | Height: | Size: 717 B |
BIN
src/main/resources/markers/skull.png
Normal file
After Width: | Height: | Size: 798 B |
BIN
src/main/resources/markers/star.png
Normal file
After Width: | Height: | Size: 611 B |
BIN
src/main/resources/markers/sun.png
Normal file
After Width: | Height: | Size: 621 B |
BIN
src/main/resources/markers/temple.png
Normal file
After Width: | Height: | Size: 627 B |
BIN
src/main/resources/markers/theater.png
Normal file
After Width: | Height: | Size: 815 B |
BIN
src/main/resources/markers/tornado.png
Normal file
After Width: | Height: | Size: 854 B |
BIN
src/main/resources/markers/tower.png
Normal file
After Width: | Height: | Size: 747 B |
BIN
src/main/resources/markers/tree.png
Normal file
After Width: | Height: | Size: 716 B |
BIN
src/main/resources/markers/truck.png
Normal file
After Width: | Height: | Size: 623 B |
BIN
src/main/resources/markers/up.png
Normal file
After Width: | Height: | Size: 391 B |
BIN
src/main/resources/markers/walk.png
Normal file
After Width: | Height: | Size: 700 B |
BIN
src/main/resources/markers/warning.png
Normal file
After Width: | Height: | Size: 652 B |
BIN
src/main/resources/markers/world.png
Normal file
After Width: | Height: | Size: 910 B |
BIN
src/main/resources/markers/wrench.png
Normal file
After Width: | Height: | Size: 660 B |
BIN
src/main/resources/markers/yellowflag.png
Normal file
After Width: | Height: | Size: 671 B |