--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/web/StatusListener.java 2011/12/22 14:45:38 1670
+++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/web/StatusListener.java 2012/01/27 14:12:37 1685
@@ -13,19 +13,31 @@
import org.bukkit.configuration.Configuration;
-import org.kokakiwi.apicraft.events.ApiEvent;
-import org.kokakiwi.apicraft.events.ApiListener;
+/*import org.kokakiwi.apicraft.events.ApiEvent;
+import org.kokakiwi.apicraft.events.ApiListener;*/
+import de.codeinfection.quickwango.ApiBukkit.ApiBukkit;
+import de.codeinfection.quickwango.ApiBukkit.ApiRequestAction;
+import de.codeinfection.quickwango.ApiBukkit.ApiRequestException;
+import de.codeinfection.quickwango.ApiBukkit.Net.Parameters;
+import de.codeinfection.quickwango.ApiBukkit.ApiRequestController;
-public class StatusListener extends ApiListener {
+public class StatusListener extends ApiRequestController {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Server server;
Configuration loginConfig;
+ Configuration homeConfig;
+
+ long cachedTime = 0;
+ String cachedXml = "";
+
+ public StatusListener(Plugin plugin, Server server, Configuration loginConfig, Configuration homeConfig) {
+ super(plugin,true);
- public StatusListener(Server server, Configuration loginConfig) {
this.server = server;
this.loginConfig = loginConfig;
+ this.homeConfig = homeConfig;
}
String formatTime(String input) {
@@ -37,10 +49,33 @@
}
@Override
- public void onApiEvent(ApiEvent event) {
- if(!event.path[0].equalsIgnoreCase("webstatus")) {
+ public Object defaultAction(String action, Parameters params, Server server) throws ApiRequestException {
+/* if(!event.path[0].equalsIgnoreCase("webstatus")) {
return;
+ }*/
+
+ String xml;
+
+ synchronized(this) { //is this necessary ?
+ long now = System.currentTimeMillis();
+ if ( (now-cachedTime) > 5000) {
+ xml = buildXML();
+ cachedXml = xml;
+ cachedTime = now;
+ } else {
+ xml = cachedXml;
+ }
}
+
+
+/* event.setResponse(xml);
+ event.setActionTaken(true);*/
+
+ return xml;
+ }
+
+ private String buildXML() {
+
StringBuilder sb = new StringBuilder();
sb.append(" \n");
@@ -88,8 +123,18 @@
sb.append("" + loc.getBlockY() + "");
sb.append("" + loc.getBlockZ() + "");
sb.append("" + loc.getWorld().getName() + "");
- sb.append("");
-
+ sb.append("");
+ }
+
+ String homeWorld = homeConfig.getString( player.getName() + ".world");
+ if (homeWorld != null) {
+ sb.append("");
+ sb.append("" + homeWorld + "\n");
+ sb.append("" + (int)homeConfig.getDouble(player.getName() + ".x") + "\n");
+ sb.append("" + (int)homeConfig.getDouble(player.getName() + ".y") + "\n");
+ sb.append("" + (int)homeConfig.getDouble(player.getName() + ".z") + "\n");
+ sb.append("");
+
}
@@ -109,8 +154,8 @@
sb.append("\n");
sb.append("");
- event.setResponse(sb.toString());
- event.setActionTaken(true);
+
+ return sb.toString();
}