diff --git a/MapListener.java b/MapListener.java index cb8e75d3..7ecf94c5 100644 --- a/MapListener.java +++ b/MapListener.java @@ -6,8 +6,7 @@ import java.util.logging.Logger; public class MapListener extends PluginListener { private static final Logger log = Logger.getLogger("Minecraft"); private MapManager mgr; - private ArrayList markers; - + public MapListener(MapManager mgr) { this.mgr = mgr; @@ -76,58 +75,58 @@ public class MapListener extends PluginListener { return true; } - if(split[0].equals("/addmarker")) { + if(split[0].equals("/addsign")) { if(split.length < 2) { - player.sendMessage("Map> " + Colors.Red + "Usage: /map_addmarker [name]"); + player.sendMessage("Map> " + Colors.Red + "Usage: /addsign [name]"); } else { - if (mgr.addMapMarker(player, split[1], player.getX(), player.getY(), player.getZ())) + if (mgr.addSign(player, split[1], player.getX(), player.getY(), player.getZ())) { - player.sendMessage("Map> " + Colors.White + "Marker \"" + split[1] + "\" added successfully"); + player.sendMessage("Map> " + Colors.White + "Sign \"" + split[1] + "\" added successfully"); } } return true; } - if(split[0].equals("/removemarker")) { + if(split[0].equals("/removesign")) { if(split.length < 2) { - player.sendMessage("Map> " + Colors.Red + "Usage: /map_removemarker [name]"); + player.sendMessage("Map> " + Colors.Red + "Usage: /removesign [name]"); } else { - if (mgr.removeMapMarker(player, split[1])) + if (mgr.removeSign(player, split[1])) { - player.sendMessage("Map> " + Colors.White + "Marker \"" + split[1] + "\" removed successfully"); + player.sendMessage("Map> " + Colors.White + "Sign \"" + split[1] + "\" removed successfully"); } } return true; } - if(split[0].equals("/listmarkers")) { + if(split[0].equals("/listsigns")) { String msg = ""; - Collection values = mgr.markers.values(); - Iterator it = values.iterator(); + Collection values = mgr.signs.values(); + Iterator it = values.iterator(); while(it.hasNext()) { - MapMarker marker = it.next(); - String line = " - " + marker.name + " (" + marker.owner + ")\t"; + Warp sign = it.next(); + String line = " - " + sign.Name + "\t"; msg += line; } player.sendMessage("" + Colors.White + msg); return true; } - if(split[0].equals("/tpmarker")) { + if(split[0].equals("/tpsign")) { if(split.length < 2) { - player.sendMessage("Map> " + Colors.Red + "Usage: /map_tpmarker [name]"); + player.sendMessage("Map> " + Colors.Red + "Usage: /tpsign [name]"); } else { - if (mgr.teleportToMapMarker(player, split[1])) + if (mgr.teleportToSign(player, split[1])) { //player.sendMessage("Map> " + Colors.White + ""); } diff --git a/MapManager.java b/MapManager.java index ebaeb411..7a1acbb6 100644 --- a/MapManager.java +++ b/MapManager.java @@ -1,6 +1,5 @@ import java.awt.Color; import java.awt.Graphics2D; -import java.util.List; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.awt.image.WritableRaster; @@ -18,6 +17,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; +import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import java.util.Scanner; @@ -65,8 +65,8 @@ public class MapManager extends Thread { /* path to image tile directory */ public String tilepath = "tiles/"; - /* path to markers file */ - public String markerpath = "markers.txt"; + /* path to signs file */ + public String signspath = "signs.txt"; /* port to run web server on */ public int serverport = 8123; @@ -83,14 +83,27 @@ public class MapManager extends Thread { /* map debugging mode (send debugging messages to this player) */ public String debugPlayer = null; - /* hashmap of markers */ - public HashMap markers = null; + /* hashmap of signs */ + public HashMap signs = null; /* cache this many zoomed-out tiles */ public static final int zoomCacheSize = 64; /* zoomed-out tile cache */ public Cache zoomCache; + + /* data source */ + public String datasource = "flatfile"; + + /* which markers to show (spawn,homes,warps,signs,players,all,none) */ + public String showmarkers = "all"; + + /* booleans designating what to show on the map */ + public Boolean showSpawn = false; + public Boolean showHomes = false; + public Boolean showWarps = false; + public Boolean showSigns = false; + public Boolean showPlayers = false; public void debug(String msg) { @@ -110,8 +123,10 @@ public class MapManager extends Thread { try { tilepath = properties.getString("map-tilepath", "tiles/"); colorsetpath = properties.getString("map-colorsetpath", "colors.txt"); - markerpath = properties.getString("map-markerpath", "markers.txt"); + signspath = properties.getString("map-signspath", "signs.txt"); serverport = Integer.parseInt(properties.getString("map-serverport", "8123")); + datasource = properties.getString("data-source", "flatfile"); + showmarkers = properties.getString("map-showmarkers", "all"); } catch(Exception ex) { log.log(Level.SEVERE, "Exception while reading properties for dynamic map", ex); } @@ -121,7 +136,9 @@ public class MapManager extends Thread { tileUpdates = new LinkedList(); zoomCache = new Cache(zoomCacheSize); - markers = new HashMap(); + signs = new HashMap(); + + loadShowOptions(); } /* tile X for position x */ @@ -169,7 +186,7 @@ public class MapManager extends Thread { /* load colorset */ File cfile = new File(colorsetpath); - loadMapMarkers(); + loadSigns(); try { Scanner scanner = new Scanner(cfile); @@ -566,116 +583,124 @@ public class MapManager extends Thread { return good; } - /* adds a marker to the map */ - public boolean addMapMarker(Player player, String name, double px, double py, double pz) + /* adds a sign to the map */ + public boolean addSign(Player player, String name, double px, double py, double pz) { - if (markers.containsKey(name)) + if (signs.containsKey(name)) { - player.sendMessage("Map> " + Colors.Red + "Marker \"" + name + "\" already exists."); + player.sendMessage("Map> " + Colors.Red + "Sign \"" + name + "\" already exists."); return false; } - MapMarker marker = new MapMarker(); - marker.name = name; - marker.owner = player.getName(); - marker.px = px; - marker.py = py; - marker.pz = pz; - markers.put(name, marker); + Warp sign = new Warp(); + sign.Name = name; + sign.Location = new Location(px,py,pz); + signs.put(name, sign); try { - saveMapMarkers(); + saveSigns(); return true; } catch(IOException e) { - log.log(Level.SEVERE, "Failed to save markers.txt", e); + log.log(Level.SEVERE, "Failed to save signs.txt", e); } return false; } - /* removes a marker from the map */ - public boolean removeMapMarker(Player player, String name) + /* removes a sign from the map */ + public boolean removeSign(Player player, String name) { - if (markers.containsKey(name)) + if (signs.containsKey(name)) { - MapMarker marker = markers.get(name); - if (marker.owner.equalsIgnoreCase(player.getName())) - { - markers.remove(name); - - try - { - saveMapMarkers(); - return true; - } - catch(IOException e) - { - log.log(Level.SEVERE, "Failed to save markers.txt", e); - } - } - else - { - player.sendMessage("Map> " + Colors.Red + "Marker \"" + name + "\" does not belong to you."); - } - } - else - { - player.sendMessage("Map> " + Colors.Red + "Marker \"" + name + "\" does not exist."); - } - - return false; - } - - /* teleports a user to a marker */ - public boolean teleportToMapMarker(Player player, String name) - { - if (markers.containsKey(name)) - { - MapMarker marker = markers.get(name); + Warp sign = signs.get(name); - player.teleportTo(marker.px, marker.py, marker.pz, 0, 0); + signs.remove(name); + + try + { + saveSigns(); + return true; + } + catch(IOException e) + { + log.log(Level.SEVERE, "Failed to save signs.txt", e); + } } else { - player.sendMessage("Map> " + Colors.Red + "Marker \"" + name + "\" does not exist."); + player.sendMessage("Map> " + Colors.Red + "Sign \"" + name + "\" does not exist."); } return false; } - /* load the map marker file */ - private void loadMapMarkers() + /* teleports a user to a sign */ + public boolean teleportToSign(Player player, String name) + { + if (signs.containsKey(name)) + { + Warp sign = signs.get(name); + + player.teleportTo(sign.Location.x, sign.Location.y, sign.Location.z, 0, 0); + } + else + { + player.sendMessage("Map> " + Colors.Red + "Sign \"" + name + "\" does not exist."); + } + + return false; + } + + /* load the map sign file */ + private void loadSigns() { Scanner scanner = null; try { - scanner = new Scanner(new FileInputStream(markerpath), "UTF-8"); + scanner = new Scanner(new FileInputStream(signspath), "UTF-8"); while (scanner.hasNextLine()) { String line = scanner.nextLine(); String[] values = line.split(":"); + String name = ""; + Double x = 0.0,y = 0.0,z = 0.0; + // If user has old style of file (CSV) - if (values.length != 5) + if (values.length == 1) { values = line.split(","); } + // If user has old style of file (owners) if (values.length == 5) { - MapMarker marker = new MapMarker(); - marker.name = values[0]; - marker.owner = values[1]; - marker.px = Double.parseDouble(values[2]); - marker.py = Double.parseDouble(values[3]); - marker.pz = Double.parseDouble(values[4]); - markers.put(marker.name, marker); + name = values[0]; + x = Double.parseDouble(values[2]); + y = Double.parseDouble(values[3]); + z = Double.parseDouble(values[4]); + } + else if (values.length == 4) + { + name = values[0]; + x = Double.parseDouble(values[1]); + y = Double.parseDouble(values[2]); + z = Double.parseDouble(values[3]); } else { - log.log(Level.INFO, "Failed to load marker: " + values[0]); + log.log(Level.INFO, "Failed to load sign: " + values[0]); + } + + // If a sign was loaded, add it to the hash + if (name.isEmpty() == false && x != 0.0 && y != 0.0 && z != 0.0) + { + Warp sign = new Warp(); + sign.Name = name; + sign.Location = new Location(x, y, z); + signs.put(sign.Name, sign); } } } @@ -689,19 +714,19 @@ public class MapManager extends Thread { } } - /* save the map marker file */ - private void saveMapMarkers() throws IOException + /* save the map sign file */ + private void saveSigns() throws IOException { Writer out = null; try { - out = new OutputStreamWriter(new FileOutputStream(markerpath), "UTF-8"); - Collection values = markers.values(); - Iterator it = values.iterator(); + out = new OutputStreamWriter(new FileOutputStream(signspath), "UTF-8"); + Collection values = signs.values(); + Iterator it = values.iterator(); while(it.hasNext()) { - MapMarker marker = it.next(); - String line = marker.name + ":" + marker.owner + ":" + marker.px + ":" + marker.py + ":" + marker.pz + "\n"; + Warp sign = it.next(); + String line = sign.Name + ":" + sign.Location.x + ":" + sign.Location.y + ":" + sign.Location.z + "\n"; out.write(line); } } @@ -711,7 +736,7 @@ public class MapManager extends Thread { } catch(FileNotFoundException e) { - log.log(Level.SEVERE, "markers.txt not found", e); + log.log(Level.SEVERE, "signs.txt not found", e); } finally { @@ -723,23 +748,19 @@ public class MapManager extends Thread { protected List loadWarps() { - PropertiesFile props = new PropertiesFile("server.properties"); - List warps = null; - if (props.getString("data-source").equals("flatfile")) { - DMFlatFileSource dataSource = new DMFlatFileSource(); - dataSource.initialize(); - dataSource.loadWarps(); - dataSource.loadHomes(); - warps = dataSource.getAllWarps(); + if (datasource.equals("flatfile")) { + DMFlatFileSource ds = new DMFlatFileSource(); + ds.initialize(); + ds.loadWarps(); + warps = ds.getAllWarps(); } - else if (props.getString("data-source").equals("mysql")) { - DMMySQLSource dataSource = new DMMySQLSource(); - dataSource.initialize(); - dataSource.loadWarps(); - dataSource.loadHomes(); - warps = dataSource.getAllWarps(); + else if (datasource.equals("mysql")) { + DMMySQLSource ds = new DMMySQLSource(); + ds.initialize(); + ds.loadWarps(); + warps = ds.getAllWarps(); } return warps; @@ -747,25 +768,68 @@ public class MapManager extends Thread { protected List loadHomes() { - PropertiesFile props = new PropertiesFile("server.properties"); - List homes = null; - if (props.getString("data-source").equals("flatfile")) { - DMFlatFileSource dataSource = new DMFlatFileSource(); - dataSource.initialize(); - dataSource.loadWarps(); - dataSource.loadHomes(); - homes = dataSource.getAllHomes(); + if (datasource.equals("flatfile")) { + DMFlatFileSource ds = new DMFlatFileSource(); + ds.initialize(); + ds.loadHomes(); + homes = ds.getAllHomes(); } - else if (props.getString("data-source").equals("mysql")) { - DMMySQLSource dataSource = new DMMySQLSource(); - dataSource.initialize(); - dataSource.loadWarps(); - dataSource.loadHomes(); - homes = dataSource.getAllHomes(); + else if (datasource.equals("mysql")) { + DMMySQLSource ds = new DMMySQLSource(); + ds.initialize(); + ds.loadHomes(); + homes = ds.getAllHomes(); } return homes; } + + private void loadShowOptions() + { + String[] values = showmarkers.split(","); + + for (int i = 0; i < values.length; i++) + { + String opt = values[i]; + + if (opt.equals("all")) + { + showSpawn = true; + showHomes = true; + showWarps = true; + showSigns = true; + showPlayers = true; + } + else if (opt.equals("none")) + { + showSpawn = false; + showHomes = false; + showWarps = false; + showSigns = false; + showPlayers = false; + } + else if (opt.equals("spawn")) + { + showSpawn = true; + } + else if (opt.equals("homes")) + { + showHomes = true; + } + else if (opt.equals("warps")) + { + showWarps = true; + } + else if (opt.equals("signs")) + { + showSigns = true; + } + else if (opt.equals("players")) + { + showPlayers = true; + } + } + } } diff --git a/MapMarker.java b/MapMarker.java deleted file mode 100644 index f1dab5c2..00000000 --- a/MapMarker.java +++ /dev/null @@ -1,4 +0,0 @@ -public class MapMarker { - public double px, py, pz; - public String name, owner; -} diff --git a/WebServerRequest.java b/WebServerRequest.java index 464ad0b0..bcf2f6d5 100644 --- a/WebServerRequest.java +++ b/WebServerRequest.java @@ -72,33 +72,44 @@ public class WebServerRequest extends Thread { StringBuilder sb = new StringBuilder(); sb.append(current + "\n"); - for(Player player : etc.getServer().getPlayerList()) { - sb.append(player.getName() + " " + player.getX() + " " + player.getY() + " " + player.getZ() + "\n"); + if (mgr.showPlayers) { + for(Player player : etc.getServer().getPlayerList()) { + sb.append(player.getName() + " player " + player.getX() + " " + player.getY() + " " + player.getZ() + "\n"); + } } - for(MapMarker marker : mgr.markers.values()) - { - sb.append(marker.name + " marker " + marker.owner + " " + marker.px + " " + marker.py + " " + marker.pz + "\n"); + if (mgr.showSigns) { + for(Warp sign : mgr.signs.values()) + { + sb.append(sign.Name + " sign " + sign.Location.x + " " + sign.Location.y + " " + sign.Location.z + "\n"); + } } - List warps = mgr.loadWarps(); - List homes = mgr.loadHomes(); - - Location spawnLocation = etc.getServer().getSpawnLocation(); - - if (warps != null) { - for(Warp warp : warps) { - sb.append(warp.Name + " warp unknown " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n"); + if (mgr.showWarps) { + List warps = mgr.loadWarps(); + + if (warps != null) { + for(Warp warp : warps) { + sb.append(warp.Name + " warp " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n"); + } } } - if (homes != null) { - for(Warp warp : homes) { - sb.append(warp.Name + " home " + warp.Name + " " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n"); + if (mgr.showHomes) { + List homes = mgr.loadHomes(); + + if (homes != null) { + for(Warp warp : homes) { + sb.append(warp.Name + " home " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n"); + } } } - sb.append("Spawn spawn none " + spawnLocation.x + " " + spawnLocation.y + " " + spawnLocation.z + "\n"); + if (mgr.showSpawn) { + Location spawnLocation = etc.getServer().getSpawnLocation(); + + sb.append("Spawn spawn " + spawnLocation.x + " " + spawnLocation.y + " " + spawnLocation.z + "\n"); + } synchronized(mgr.lock) { for(TileUpdate tu : mgr.tileUpdates) { diff --git a/dist/DynamicMap.rar b/dist/DynamicMap.rar index ad5247fb..e836ce7e 100644 Binary files a/dist/DynamicMap.rar and b/dist/DynamicMap.rar differ diff --git a/map.java b/map.java index 84ed9ef2..ca34b426 100644 --- a/map.java +++ b/map.java @@ -48,9 +48,9 @@ public class map extends Plugin { etc.getInstance().addCommand("/map_regen", " - regenerate entire map"); etc.getInstance().addCommand("/map_debug", " - send map debugging messages"); etc.getInstance().addCommand("/map_nodebug", " - disable map debugging messages"); - etc.getInstance().addCommand("/addmarker", " [name] - adds a named marker to the map"); - etc.getInstance().addCommand("/removemarker", " [name] - removes a named marker to the map"); - etc.getInstance().addCommand("/listmarkers", " - list all named markers"); - etc.getInstance().addCommand("/tpmarker", " [name] - teleport to a named marker"); + etc.getInstance().addCommand("/addsign", " [name] - adds a named sign to the map"); + etc.getInstance().addCommand("/removesign", " [name] - removes a named sign to the map"); + etc.getInstance().addCommand("/listsigns", " - list all named signs"); + etc.getInstance().addCommand("/tpsign", " [name] - teleport to a named sign"); } } diff --git a/readme.txt b/readme.txt index 04950052..64ea26a6 100644 --- a/readme.txt +++ b/readme.txt @@ -7,14 +7,15 @@ Commands /map_nodebug - disable map debugging messages /map_regenzoom - regenerates zoom-out tiles -/addmarker [name] - adds a named marker to the map -/removemarker [name] - removes a named marker to the map -/listmarkers - list all named markers -/tpmarker [name] - teleport to a named marker +/addsign [name] - adds a named sign to the map +/removesign [name] - removes a named sign to the map +/listsigns - list all named signs +/tpsign [name] - teleport to a named sign server.properties -------------------------------------------------- map-colorsetpath - point to colors.txt map-tilepath - point to web/tiles folder -map-markerpath - point to markers.csv file (do not need to create the file, one will be created when you create a marker) -map-serverport - the port the web server runs on (default is 8123) \ No newline at end of file +map-signspath - point to signs.txt file (do not need to create the file, one will be created when you create a sign) +map-serverport - the port the web server runs on (default is 8123) +map-showmarkers - a list of which markers to show on the map, comma separated if multiple (spawn, homes, warps, signs, players, all, none) \ No newline at end of file diff --git a/web/index.html b/web/index.html index dff45480..7d78421c 100644 --- a/web/index.html +++ b/web/index.html @@ -20,15 +20,23 @@
[Connecting]
-
- Warps -
- Markers -
- Homes -
- Spawn -
+ +
+ Warps + +
+
+ Signs +
+
+
+ Homes +
+
+
+ Spawn +
+
diff --git a/web/map.js b/web/map.js index 5d014da4..0c30fcfc 100644 --- a/web/map.js +++ b/web/map.js @@ -565,7 +565,7 @@ function makeRequest(url, func, type, fail, post, contenttype) var rows = res.split('\n'); var loggedin = new Array(); var showWarps = document.getElementById('showWarps').checked; - var showMarkers = document.getElementById('showMarkers').checked; + var showSigns = document.getElementById('showSigns').checked; var showHomes = document.getElementById('showHomes').checked; var showSpawn = document.getElementById('showSpawn').checked; @@ -573,55 +573,49 @@ function makeRequest(url, func, type, fail, post, contenttype) delete rows[0]; var playerlst = '' + var numwarps = 0; + var numsigns = 0; + var numhomes = 0; + var numspawns = 0; + var numplayers = 0; for(var line in rows) { var p = rows[line].split(' '); - // Hack to keep duplicate markers/warps/players from conflicting with eachother - if(p.length == 6) { + if(p[0] == '') continue; + + // Hack to keep duplicate markers from conflicting with eachother + if (p[1] != 'player') { p[0] = p[0] + '' + p[1] + ''; } loggedin[p[0]] = 1; - if(p[0] == '') continue; - - if(p.length == 4) { + + if (p[1] == 'player') { if(playerlst != '') playerlst += '
'; playerlst += ' ' + p[0] + ''; + } - if(p[0] == followPlayer) { - map.setCenter(fromWorldToLatLng(p[1], p[2], p[3])); - } - - if(p[0] in markers) { - var m = markers[p[0]]; - var converted = fromWorldToLatLng(p[1], p[2], p[3]); - m.setPosition(converted); - } else { - var converted = fromWorldToLatLng(p[1], p[2], p[3]); - var marker = new MarkerWithLabel({ - position: converted, - map: map, - labelContent: p[0], - labelAnchor: new google.maps.Point(-14, 10), - labelClass: "labels", - clickable: false, - flat: true, - icon: new google.maps.MarkerImage('player.png', new google.maps.Size(28, 28), new google.maps.Point(0, 0), new google.maps.Point(14, 14)) - }); - - markers[p[0]] = marker; - } - } else if(p.length == 6) { + if(p.length == 5) { var image = p[1] + '.png'; + if (p[1] == 'warp') numwarps++; + if (p[1] == 'sign') numsigns++; + if (p[1] == 'home') numhomes++; + if (p[1] == 'spawn') numspawns++; + if (p[1] == 'player') numplayers++; + var hideMarker = ( (p[1] == 'warp' && showWarps == false) || - (p[1] == 'marker' && showMarkers == false) || + (p[1] == 'sign' && showSigns == false) || (p[1] == 'home' && showHomes == false) || (p[1] == 'spawn' && showSpawn == false) ); + if(p[0] == followPlayer) { + map.panTo(fromWorldToLatLng(p[2], p[3], p[4])); + } + if(p[0] in markers) { var m = markers[p[0]]; @@ -633,14 +627,14 @@ function makeRequest(url, func, type, fail, post, contenttype) m.setMap(map); } - var converted = fromWorldToLatLng(p[3], p[4], p[5]); + var converted = fromWorldToLatLng(p[2], p[3], p[4]); m.setPosition(converted); } else { if (hideMarker) { continue; } - var converted = fromWorldToLatLng(p[3], p[4], p[5]); + var converted = fromWorldToLatLng(p[2], p[3], p[4]); var marker = new MarkerWithLabel({ position: converted, map: map, @@ -674,6 +668,15 @@ function makeRequest(url, func, type, fail, post, contenttype) delete markers[m]; } } + + document.getElementById('warpsDiv').style.display = (numwarps == 0)?'none':''; + document.getElementById('signsDiv').style.display = (numsigns == 0)?'none':''; + document.getElementById('homesDiv').style.display = (numhomes == 0)?'none':''; + document.getElementById('spawnsDiv').style.display = (numspawns == 0)?'none':''; + + document.getElementById('plist').style.display = (numplayers == 0)?'none':''; + + document.getElementById('controls').style.display = ((numwarps + numsigns + numhomes + numspawns) == 0)?'none':''; setTimeout(mapUpdate, config.updateRate); }, 'text', function() { alert('failed to get update data'); } ); diff --git a/web/marker.png b/web/sign.png similarity index 100% rename from web/marker.png rename to web/sign.png