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.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 ("[<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
*/