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, serializer = "plain" ) |
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 |
|
|
27 |
Server server; |
Server server; |
28 |
Configuration loginConfig; |
Configuration loginConfig; |
29 |
|
Configuration homeConfig; |
30 |
|
|
31 |
|
long cachedTime = 0; |
32 |
|
String cachedXml = ""; |
33 |
|
|
34 |
|
public StatusListener(Plugin plugin, Server server, Configuration loginConfig, Configuration homeConfig) { |
35 |
|
|
36 |
|
super( new de.codeinfection.quickwango.Abstraction.Implementations.Bukkit.BukkitPlugin(plugin) ); |
37 |
|
|
|
public StatusListener(Server server, Configuration loginConfig) { |
|
38 |
this.server = server; |
this.server = server; |
39 |
this.loginConfig = loginConfig; |
this.loginConfig = loginConfig; |
40 |
|
this.homeConfig = homeConfig; |
41 |
} |
} |
42 |
|
|
43 |
String formatTime(String input) { |
String formatTime(String input) { |
49 |
} |
} |
50 |
|
|
51 |
@Override |
@Override |
52 |
public void onApiEvent(ApiEvent event) { |
public void defaultAction(String action, ApiRequest request, ApiResponse response) { |
53 |
if(!event.path[0].equalsIgnoreCase("webstatus")) { |
/* if(!event.path[0].equalsIgnoreCase("webstatus")) { |
54 |
return; |
return; |
55 |
|
}*/ |
56 |
|
|
57 |
|
String xml; |
58 |
|
|
59 |
|
synchronized(this) { //is this necessary ? |
60 |
|
long now = System.currentTimeMillis(); |
61 |
|
if ( (now-cachedTime) > 5000) { |
62 |
|
xml = buildXML(); |
63 |
|
cachedXml = xml; |
64 |
|
cachedTime = now; |
65 |
|
} else { |
66 |
|
xml = cachedXml; |
67 |
|
} |
68 |
} |
} |
69 |
|
|
70 |
|
|
71 |
|
/* event.setResponse(xml); |
72 |
|
event.setActionTaken(true);*/ |
73 |
|
|
74 |
|
response.setContent( xml); |
75 |
|
} |
76 |
|
|
77 |
|
private String buildXML() { |
78 |
|
|
79 |
StringBuilder sb = new StringBuilder(); |
StringBuilder sb = new StringBuilder(); |
80 |
|
|
81 |
sb.append("<?xml version=\"1.0\"?> \n"); |
sb.append("<?xml version=\"1.0\"?> \n"); |
123 |
sb.append("<y>" + loc.getBlockY() + "</y>"); |
sb.append("<y>" + loc.getBlockY() + "</y>"); |
124 |
sb.append("<z>" + loc.getBlockZ() + "</z>"); |
sb.append("<z>" + loc.getBlockZ() + "</z>"); |
125 |
sb.append("<world>" + loc.getWorld().getName() + "</world>"); |
sb.append("<world>" + loc.getWorld().getName() + "</world>"); |
126 |
sb.append("</location>"); |
sb.append("</location>"); |
127 |
|
} |
128 |
|
|
129 |
|
String homeWorld = homeConfig.getString( player.getName() + ".world"); |
130 |
|
if (homeWorld != null) { |
131 |
|
sb.append("<home>"); |
132 |
|
sb.append("<world>" + homeWorld + "</world>\n"); |
133 |
|
sb.append("<x>" + (int)homeConfig.getDouble(player.getName() + ".x") + "</x>\n"); |
134 |
|
sb.append("<y>" + (int)homeConfig.getDouble(player.getName() + ".y") + "</y>\n"); |
135 |
|
sb.append("<z>" + (int)homeConfig.getDouble(player.getName() + ".z") + "</z>\n"); |
136 |
|
sb.append("</home>"); |
137 |
|
|
138 |
} |
} |
139 |
|
|
140 |
|
|
154 |
sb.append("</plugins>\n"); |
sb.append("</plugins>\n"); |
155 |
|
|
156 |
sb.append("</serverinfo>"); |
sb.append("</serverinfo>"); |
157 |
event.setResponse(sb.toString()); |
|
158 |
event.setActionTaken(true); |
return sb.toString(); |
159 |
|
|
160 |
} |
} |
161 |
|
|