13 |
|
|
14 |
import org.bukkit.configuration.Configuration; |
import org.bukkit.configuration.Configuration; |
15 |
|
|
16 |
import org.kokakiwi.apicraft.events.ApiEvent; |
/*import org.kokakiwi.apicraft.events.ApiEvent; |
17 |
import org.kokakiwi.apicraft.events.ApiListener; |
import org.kokakiwi.apicraft.events.ApiListener;*/ |
18 |
|
import de.codeinfection.quickwango.ApiBukkit.ApiBukkit; |
19 |
|
import de.codeinfection.quickwango.ApiBukkit.ApiServer.*; |
20 |
|
|
21 |
public class StatusListener extends ApiListener { |
|
22 |
|
@Controller( name = "webstatus", authenticate = false ) |
23 |
|
public class StatusListener extends ApiController { |
24 |
|
|
25 |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
26 |
|
|
28 |
Configuration loginConfig; |
Configuration loginConfig; |
29 |
Configuration homeConfig; |
Configuration homeConfig; |
30 |
|
|
31 |
public StatusListener(Server server, Configuration loginConfig, Configuration homeConfig) { |
long cachedTime = 0; |
32 |
|
String cachedXml = ""; |
33 |
|
|
34 |
|
public StatusListener(Plugin plugin, Server server, Configuration loginConfig, Configuration homeConfig) { |
35 |
|
super(plugin); |
36 |
|
|
37 |
this.server = server; |
this.server = server; |
38 |
this.loginConfig = loginConfig; |
this.loginConfig = loginConfig; |
39 |
this.homeConfig = homeConfig; |
this.homeConfig = homeConfig; |
48 |
} |
} |
49 |
|
|
50 |
@Override |
@Override |
51 |
public void onApiEvent(ApiEvent event) { |
public void defaultAction(String action, ApiRequest request, ApiResponse response) { |
52 |
if(!event.path[0].equalsIgnoreCase("webstatus")) { |
/* if(!event.path[0].equalsIgnoreCase("webstatus")) { |
53 |
return; |
return; |
54 |
|
}*/ |
55 |
|
|
56 |
|
String xml; |
57 |
|
|
58 |
|
synchronized(this) { //is this necessary ? |
59 |
|
long now = System.currentTimeMillis(); |
60 |
|
if ( (now-cachedTime) > 5000) { |
61 |
|
xml = buildXML(); |
62 |
|
cachedXml = xml; |
63 |
|
cachedTime = now; |
64 |
|
} else { |
65 |
|
xml = cachedXml; |
66 |
|
} |
67 |
} |
} |
68 |
|
|
69 |
|
|
70 |
|
/* event.setResponse(xml); |
71 |
|
event.setActionTaken(true);*/ |
72 |
|
|
73 |
|
response.setContent( xml); |
74 |
|
} |
75 |
|
|
76 |
|
private String buildXML() { |
77 |
|
|
78 |
StringBuilder sb = new StringBuilder(); |
StringBuilder sb = new StringBuilder(); |
79 |
|
|
80 |
sb.append("<?xml version=\"1.0\"?> \n"); |
sb.append("<?xml version=\"1.0\"?> \n"); |
153 |
sb.append("</plugins>\n"); |
sb.append("</plugins>\n"); |
154 |
|
|
155 |
sb.append("</serverinfo>"); |
sb.append("</serverinfo>"); |
156 |
event.setResponse(sb.toString()); |
|
157 |
event.setActionTaken(true); |
return sb.toString(); |
158 |
|
|
159 |
} |
} |
160 |
|
|