Updated Server.getTime to World.getTime (to reflect Bukkit's changes)

This commit is contained in:
FrozenCow 2011-02-02 11:40:49 +01:00
parent 455b5d3b3e
commit 13e829cda0
3 changed files with 19 additions and 24 deletions

View File

@ -55,7 +55,7 @@ public class DynmapPlugin extends JavaPlugin {
mapManager.startManager(); mapManager.startManager();
try { try {
webServer = new WebServer(mapManager, getServer(), playerList, debugger, configuration); webServer = new WebServer(mapManager, getWorld(), playerList, debugger, configuration);
} catch(IOException e) { } catch(IOException e) {
log.info("position failed to start WebServer (IOException)"); log.info("position failed to start WebServer (IOException)");
} }

View File

@ -6,8 +6,7 @@ import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Server; import org.bukkit.World;
import org.bukkit.util.config.Configuration;
import org.bukkit.util.config.ConfigurationNode; import org.bukkit.util.config.ConfigurationNode;
import org.dynmap.MapManager; import org.dynmap.MapManager;
import org.dynmap.PlayerList; import org.dynmap.PlayerList;
@ -24,14 +23,14 @@ public class WebServer extends Thread {
private boolean running = false; private boolean running = false;
private MapManager mgr; private MapManager mgr;
private Server server; private World world;
private PlayerList playerList; private PlayerList playerList;
private ConfigurationNode configuration; 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.mgr = mgr;
this.server = server; this.world = world;
this.playerList = playerList; this.playerList = playerList;
this.configuration = configuration; this.configuration = configuration;
this.debugger = debugger; this.debugger = debugger;
@ -51,7 +50,7 @@ public class WebServer extends Thread {
while (running) { while (running) {
try { try {
Socket socket = sock.accept(); 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(); requestThread.start();
} }
catch (IOException e) { catch (IOException e) {

View File

@ -15,7 +15,7 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Server; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.config.ConfigurationNode; import org.bukkit.util.config.ConfigurationNode;
import org.dynmap.ChatQueue; import org.dynmap.ChatQueue;
@ -30,16 +30,16 @@ public class WebServerRequest extends Thread {
private Debugger debugger; private Debugger debugger;
private Socket socket; private Socket socket;
private MapManager mgr; private MapManager mgr;
private Server server; private World world;
private PlayerList playerList; private PlayerList playerList;
private ConfigurationNode configuration; 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.debugger = debugger;
this.socket = socket; this.socket = socket;
this.mgr = mgr; this.mgr = mgr;
this.server = server; this.world = world;
this.playerList = playerList; this.playerList = playerList;
this.configuration = configuration; this.configuration = configuration;
} }
@ -66,11 +66,12 @@ public class WebServerRequest extends Thread {
public void run() public void run()
{ {
InputStream reader = null; BufferedReader in = null;
BufferedOutputStream out = null;
try { try {
socket.setSoTimeout(30000); socket.setSoTimeout(30000);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream()); out = new BufferedOutputStream(socket.getOutputStream());
String request = in.readLine(); String request = in.readLine();
if (request == null || !request.startsWith("GET ") || !(request.endsWith(" HTTP/1.0") || request.endsWith("HTTP/1.1"))) { 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(); out.close();
} }
catch (IOException e) { catch (IOException e) {
if (reader != null) { if (out != null) { try { out.close(); } catch (Exception anye) { } }
try { if (in != null) { try { in.close(); } catch (Exception anye) { } }
reader.close();
}
catch (Exception anye) {
// Do nothing.
}
}
} }
catch(Exception ex) { 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()); debugger.error("Exception on WebRequest-thread: " + ex.toString());
} }
} }
@ -178,8 +175,7 @@ public class WebServerRequest extends Thread {
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
long relativeTime = world.getTime() % 24000;
long relativeTime = server.getTime() % 24000;
sb.append(current + " " + relativeTime + "\n"); sb.append(current + " " + relativeTime + "\n");
Player[] players = playerList.getVisiblePlayers(); Player[] players = playerList.getVisiblePlayers();