package dk.thoerup.bukkit.hoeruputils.web; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.plugin.Plugin; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; public class BanListener implements HttpHandler { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Server server; long cachedTime = 0; String cachedText = ""; public BanListener(Plugin plugin, Server server) { this.server = server; } String formatTime(String input) { return formatTime( Long.parseLong(input) ); } String formatTime(long input) { Date d = new Date( input ); return format.format(d ); } @Override public void handle(HttpExchange http) throws IOException { /* if(!event.path[0].equalsIgnoreCase("webstatus")) { return; }*/ String text; synchronized(this) { //is this necessary ? long now = System.currentTimeMillis(); if ( (now-cachedTime) > 5000) { text = buildText(); cachedText = text; cachedTime = now; } else { text = cachedText; } } http.getResponseBody().write( text.getBytes() ); } private String buildText() { StringBuilder sb = new StringBuilder(); sb.append("

Banned Players

"); sb.append("\n"); sb.append("

Banned IPs

"); sb.append("\n"); return sb.toString(); } }