1 |
package dk.thoerup.bukkit.hoeruputils.web; |
2 |
|
3 |
import java.io.File; |
4 |
import java.text.SimpleDateFormat; |
5 |
import java.util.Date; |
6 |
import java.util.Set; |
7 |
import java.util.Map; |
8 |
import org.bukkit.Location; |
9 |
import org.bukkit.Server; |
10 |
import org.bukkit.OfflinePlayer; |
11 |
import org.bukkit.entity.Player; |
12 |
import org.bukkit.plugin.Plugin; |
13 |
|
14 |
import org.bukkit.configuration.Configuration; |
15 |
|
16 |
/*import org.kokakiwi.apicraft.events.ApiEvent; |
17 |
import org.kokakiwi.apicraft.events.ApiListener;*/ |
18 |
import de.codeinfection.quickwango.ApiBukkit.ApiBukkit; |
19 |
import de.codeinfection.quickwango.ApiBukkit.ApiServer.*; |
20 |
|
21 |
|
22 |
@Controller( name = "bans", authenticate = false, serializer = "raw" ) |
23 |
public class BanListener extends ApiController { |
24 |
|
25 |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
26 |
|
27 |
Server server; |
28 |
|
29 |
long cachedTime = 0; |
30 |
String cachedText = ""; |
31 |
|
32 |
public BanListener(Plugin plugin, Server server) { |
33 |
super( new de.codeinfection.quickwango.Abstraction.Implementations.Bukkit.BukkitPlugin(plugin) ); |
34 |
//super( new de.codeinfection.quickwango.ApiBukkit.Abstraction.Implementations.Bukkit.BukkitPlugin(plugin) ); |
35 |
|
36 |
this.server = server; |
37 |
} |
38 |
|
39 |
String formatTime(String input) { |
40 |
return formatTime( Long.parseLong(input) ); |
41 |
} |
42 |
String formatTime(long input) { |
43 |
Date d = new Date( input ); |
44 |
return format.format(d ); |
45 |
} |
46 |
|
47 |
@Override |
48 |
public void defaultAction(ApiRequest request, ApiResponse response) { |
49 |
/* if(!event.path[0].equalsIgnoreCase("webstatus")) { |
50 |
return; |
51 |
}*/ |
52 |
|
53 |
String text; |
54 |
|
55 |
synchronized(this) { //is this necessary ? |
56 |
long now = System.currentTimeMillis(); |
57 |
if ( (now-cachedTime) > 5000) { |
58 |
text = buildText(); |
59 |
cachedText = text; |
60 |
cachedTime = now; |
61 |
} else { |
62 |
text = cachedText; |
63 |
} |
64 |
} |
65 |
|
66 |
|
67 |
/* event.setResponse(xml); |
68 |
event.setActionTaken(true);*/ |
69 |
|
70 |
response.setContent( text ); |
71 |
} |
72 |
|
73 |
private String buildText() { |
74 |
StringBuilder sb = new StringBuilder(); |
75 |
|
76 |
sb.append("<h2>Banned Players</h2>"); |
77 |
sb.append("<ul>\n"); |
78 |
for(OfflinePlayer player : server.getBannedPlayers() ) { |
79 |
sb.append("<li>").append( player.getName() ).append("</li>\n"); |
80 |
} |
81 |
sb.append("</ul>\n"); |
82 |
|
83 |
|
84 |
sb.append("<h2>Banned IPs</h2>"); |
85 |
sb.append("<ul>\n"); |
86 |
for(String ip : server.getIPBans() ) { |
87 |
sb.append("<li>").append( ip ).append("</li>\n"); |
88 |
} |
89 |
sb.append("</ul>\n"); |
90 |
|
91 |
|
92 |
return sb.toString(); |
93 |
|
94 |
} |
95 |
|
96 |
} |