diff --git a/src/main/java/org/dynmap/DynmapAPI.java b/src/main/java/org/dynmap/DynmapAPI.java new file mode 100644 index 00000000..e884a05a --- /dev/null +++ b/src/main/java/org/dynmap/DynmapAPI.java @@ -0,0 +1,32 @@ +package org.dynmap; + +import org.dynmap.markers.MarkerAPI; + +/** + * This is the interface representing the published API for the Dynmap plugin. Public methods of the + * DynmapPlugin class that are not defined in this interface are subject to change without notice, so + * be careful with forming dependencies beyond these. Plugins accessing dynmap 0.24 or later should + * do so by casting the Plugin to this interface. + * + */ +public interface DynmapAPI { + /** + * This method can return null if the 'markers' component has not been configured - + * a warning message will be issued to the server.log in this event. + * + * @return MarkerAPI, or null if not configured + */ + public MarkerAPI getMarkerAPI(); + /** + * Test if the marker API has been initialized yet + * + * @return true if it has been initialized + */ + public boolean markerAPIInitialized(); + /** + * Send generic message to all web users + * @param sender - label for sender of message ("Message from :") - if null, no from notice + * @param msg - message to be sent + */ + public boolean sendBroadcastToWeb(String sender, String msg); +} diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 6146f5b1..4bce7b1d 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -66,7 +66,7 @@ import org.dynmap.web.HttpServer; import org.dynmap.web.handlers.ClientConfigurationHandler; import org.dynmap.web.handlers.FilesystemHandler; -public class DynmapPlugin extends JavaPlugin { +public class DynmapPlugin extends JavaPlugin implements DynmapAPI { public HttpServer webServer = null; public MapManager mapManager = null; public PlayerList playerList; @@ -723,7 +723,8 @@ public class DynmapPlugin extends JavaPlugin { "radiusrender", "reload", "stats", - "resetstats" })); + "resetstats", + "sendtoweb" })); @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { @@ -859,6 +860,12 @@ public class DynmapPlugin extends JavaPlugin { mapManager.resetStats(sender, null); else mapManager.resetStats(sender, args[1]); + } else if (c.equals("sendtoweb") && checkPlayerPermission(sender, "sendtoweb")) { + String msg = ""; + for(int i = 1; i < args.length; i++) { + msg += args[i] + " "; + } + this.sendBroadcastToWeb("dynmap", msg); } return true; } @@ -1287,6 +1294,18 @@ public class DynmapPlugin extends JavaPlugin { public boolean markerAPIInitialized() { return (markerapi != null); } + /** + * Send generic message to all web users + * @param sender - label for sender of message ("[] nessage") - if null, no from notice + * @param msg - message to be sent + */ + public boolean sendBroadcastToWeb(String sender, String msg) { + if(mapManager != null) { + mapManager.pushUpdate(new Client.ChatMessage("plugin", sender, "", msg, "")); + return true; + } + return false; + } /** * Register markers API - used by component to supply marker API to plugin */ diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a2811973..8f5f8340 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -23,6 +23,8 @@ commands: / stats world - Show render statistics for maps on world 'world'. / resetstats - Reset render statistics. / resetstats world - Reset render statistics for maps on world 'world'. + / sendtoweb msg - Send message to web users + dmarker: description: Manipulate map markers usage: | @@ -74,6 +76,7 @@ permissions: dynmap.reload: true dynmap.stats: true dynmap.resetstats: true + dynmap.sendtoweb: true dynmap.marker.add: true dynmap.marker.update: true dynmap.marker.movehere: true @@ -125,6 +128,9 @@ permissions: dynmap.resetstats: description: Allows /dynmap resetstats or /dynmap resetstats default: op + dynmap.sendtoweb: + description: Allows /dynmap sendtoweb + default: op dynmap.marker.add: description: Allows /dmarker add default: op diff --git a/web/js/chatbox.js b/web/js/chatbox.js index c13142b8..ab7b1d53 100644 --- a/web/js/chatbox.js +++ b/web/js/chatbox.js @@ -97,10 +97,11 @@ componentconstructors['chatbox'] = function(dynmap, configuration) { .appendTo(messageRow); } - var playerNameContainer = $('') - .addClass('messagetext') - .text(' '+message.name+': '); - + var playerNameContainer = ''; + if(message.name) { + playerNameContainer = $('').addClass('messagetext').text(' '+message.name+': '); + } + var playerMessageContainer = $('') .addClass('messagetext') .text(message.text);