From 13e829cda04c6837182e61b85d5287e74b56d041 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Wed, 2 Feb 2011 11:40:49 +0100 Subject: [PATCH] Updated Server.getTime to World.getTime (to reflect Bukkit's changes) --- src/main/java/org/dynmap/DynmapPlugin.java | 2 +- src/main/java/org/dynmap/web/WebServer.java | 11 ++++--- .../java/org/dynmap/web/WebServerRequest.java | 30 ++++++++----------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 4ffaa5c0..91c38653 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -55,7 +55,7 @@ public class DynmapPlugin extends JavaPlugin { mapManager.startManager(); try { - webServer = new WebServer(mapManager, getServer(), playerList, debugger, configuration); + webServer = new WebServer(mapManager, getWorld(), playerList, debugger, configuration); } catch(IOException e) { log.info("position failed to start WebServer (IOException)"); } diff --git a/src/main/java/org/dynmap/web/WebServer.java b/src/main/java/org/dynmap/web/WebServer.java index 5c90c36e..680f94d1 100644 --- a/src/main/java/org/dynmap/web/WebServer.java +++ b/src/main/java/org/dynmap/web/WebServer.java @@ -6,8 +6,7 @@ import java.net.ServerSocket; import java.net.Socket; import java.util.logging.Logger; -import org.bukkit.Server; -import org.bukkit.util.config.Configuration; +import org.bukkit.World; import org.bukkit.util.config.ConfigurationNode; import org.dynmap.MapManager; import org.dynmap.PlayerList; @@ -24,14 +23,14 @@ public class WebServer extends Thread { private boolean running = false; private MapManager mgr; - private Server server; + private World world; private PlayerList playerList; private ConfigurationNode configuration; - public WebServer(MapManager mgr, Server server, PlayerList playerList, Debugger debugger, ConfigurationNode configuration) throws IOException + public WebServer(MapManager mgr, World world, PlayerList playerList, Debugger debugger, ConfigurationNode configuration) throws IOException { this.mgr = mgr; - this.server = server; + this.world = world; this.playerList = playerList; this.configuration = configuration; this.debugger = debugger; @@ -51,7 +50,7 @@ public class WebServer extends Thread { while (running) { try { Socket socket = sock.accept(); - WebServerRequest requestThread = new WebServerRequest(socket, mgr, server, playerList, configuration, debugger); + WebServerRequest requestThread = new WebServerRequest(socket, mgr, world, playerList, configuration, debugger); requestThread.start(); } catch (IOException e) { diff --git a/src/main/java/org/dynmap/web/WebServerRequest.java b/src/main/java/org/dynmap/web/WebServerRequest.java index c6a0f860..57bce14b 100644 --- a/src/main/java/org/dynmap/web/WebServerRequest.java +++ b/src/main/java/org/dynmap/web/WebServerRequest.java @@ -15,7 +15,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.logging.Logger; -import org.bukkit.Server; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.util.config.ConfigurationNode; import org.dynmap.ChatQueue; @@ -30,16 +30,16 @@ public class WebServerRequest extends Thread { private Debugger debugger; private Socket socket; private MapManager mgr; - private Server server; + private World world; private PlayerList playerList; private ConfigurationNode configuration; - public WebServerRequest(Socket socket, MapManager mgr, Server server, PlayerList playerList, ConfigurationNode configuration, Debugger debugger) + public WebServerRequest(Socket socket, MapManager mgr, World world, PlayerList playerList, ConfigurationNode configuration, Debugger debugger) { this.debugger = debugger; this.socket = socket; this.mgr = mgr; - this.server = server; + this.world = world; this.playerList = playerList; this.configuration = configuration; } @@ -66,11 +66,12 @@ public class WebServerRequest extends Thread { public void run() { - InputStream reader = null; + BufferedReader in = null; + BufferedOutputStream out = null; try { socket.setSoTimeout(30000); - BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); - BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream()); + in = new BufferedReader(new InputStreamReader(socket.getInputStream())); + out = new BufferedOutputStream(socket.getOutputStream()); String request = in.readLine(); if (request == null || !request.startsWith("GET ") || !(request.endsWith(" HTTP/1.0") || request.endsWith("HTTP/1.1"))) { @@ -95,16 +96,12 @@ public class WebServerRequest extends Thread { out.close(); } catch (IOException e) { - if (reader != null) { - try { - reader.close(); - } - catch (Exception anye) { - // Do nothing. - } - } + if (out != null) { try { out.close(); } catch (Exception anye) { } } + if (in != null) { try { in.close(); } catch (Exception anye) { } } } catch(Exception ex) { + if (out != null) { try { out.close(); } catch (Exception anye) { } } + if (in != null) { try { in.close(); } catch (Exception anye) { } } debugger.error("Exception on WebRequest-thread: " + ex.toString()); } } @@ -178,8 +175,7 @@ public class WebServerRequest extends Thread { } StringBuilder sb = new StringBuilder(); - - long relativeTime = server.getTime() % 24000; + long relativeTime = world.getTime() % 24000; sb.append(current + " " + relativeTime + "\n"); Player[] players = playerList.getVisiblePlayers();