Add /dynmap sendtoweb command, and published API for sending web messages

This commit is contained in:
Mike Primm 2011-10-23 05:53:15 +08:00 committed by mikeprimm
parent f80cfee32c
commit 36d8a701e0
4 changed files with 64 additions and 6 deletions

View File

@ -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 <plugin>:") - if null, no from notice
* @param msg - message to be sent
*/
public boolean sendBroadcastToWeb(String sender, String msg);
}

View File

@ -66,7 +66,7 @@ import org.dynmap.web.HttpServer;
import org.dynmap.web.handlers.ClientConfigurationHandler; import org.dynmap.web.handlers.ClientConfigurationHandler;
import org.dynmap.web.handlers.FilesystemHandler; import org.dynmap.web.handlers.FilesystemHandler;
public class DynmapPlugin extends JavaPlugin { public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
public HttpServer webServer = null; public HttpServer webServer = null;
public MapManager mapManager = null; public MapManager mapManager = null;
public PlayerList playerList; public PlayerList playerList;
@ -723,7 +723,8 @@ public class DynmapPlugin extends JavaPlugin {
"radiusrender", "radiusrender",
"reload", "reload",
"stats", "stats",
"resetstats" })); "resetstats",
"sendtoweb" }));
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
@ -859,6 +860,12 @@ public class DynmapPlugin extends JavaPlugin {
mapManager.resetStats(sender, null); mapManager.resetStats(sender, null);
else else
mapManager.resetStats(sender, args[1]); 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; return true;
} }
@ -1287,6 +1294,18 @@ public class DynmapPlugin extends JavaPlugin {
public boolean markerAPIInitialized() { public boolean markerAPIInitialized() {
return (markerapi != null); return (markerapi != null);
} }
/**
* Send generic message to all web users
* @param sender - label for sender of message ("[<sender>] 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 * Register markers API - used by component to supply marker API to plugin
*/ */

View File

@ -23,6 +23,8 @@ commands:
/<command> stats world - Show render statistics for maps on world 'world'. /<command> stats world - Show render statistics for maps on world 'world'.
/<command> resetstats - Reset render statistics. /<command> resetstats - Reset render statistics.
/<command> resetstats world - Reset render statistics for maps on world 'world'. /<command> resetstats world - Reset render statistics for maps on world 'world'.
/<command> sendtoweb msg - Send message to web users
dmarker: dmarker:
description: Manipulate map markers description: Manipulate map markers
usage: | usage: |
@ -74,6 +76,7 @@ permissions:
dynmap.reload: true dynmap.reload: true
dynmap.stats: true dynmap.stats: true
dynmap.resetstats: true dynmap.resetstats: true
dynmap.sendtoweb: true
dynmap.marker.add: true dynmap.marker.add: true
dynmap.marker.update: true dynmap.marker.update: true
dynmap.marker.movehere: true dynmap.marker.movehere: true
@ -125,6 +128,9 @@ permissions:
dynmap.resetstats: dynmap.resetstats:
description: Allows /dynmap resetstats or /dynmap resetstats <world> description: Allows /dynmap resetstats or /dynmap resetstats <world>
default: op default: op
dynmap.sendtoweb:
description: Allows /dynmap sendtoweb
default: op
dynmap.marker.add: dynmap.marker.add:
description: Allows /dmarker add description: Allows /dmarker add
default: op default: op

View File

@ -97,10 +97,11 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
.appendTo(messageRow); .appendTo(messageRow);
} }
var playerNameContainer = $('<span/>') var playerNameContainer = '';
.addClass('messagetext') if(message.name) {
.text(' '+message.name+': '); playerNameContainer = $('<span/>').addClass('messagetext').text(' '+message.name+': ');
}
var playerMessageContainer = $('<span/>') var playerMessageContainer = $('<span/>')
.addClass('messagetext') .addClass('messagetext')
.text(message.text); .text(message.text);