diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 0ab14f08..f790dedd 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -1,8 +1,8 @@ package org.dynmap; import java.io.File; -import java.io.FileOutputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Constructor; import java.net.InetAddress; @@ -10,12 +10,12 @@ import java.net.UnknownHostException; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.logging.Logger; import java.util.Timer; +import java.util.logging.Level; +import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.block.Block; import org.bukkit.block.BlockDamageLevel; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -39,12 +39,12 @@ import org.dynmap.Event.Listener; import org.dynmap.debug.Debug; import org.dynmap.debug.Debugger; import org.dynmap.web.HttpServer; +import org.dynmap.web.Json; import org.dynmap.web.handlers.ClientConfigurationHandler; import org.dynmap.web.handlers.ClientUpdateHandler; import org.dynmap.web.handlers.FilesystemHandler; import org.dynmap.web.handlers.SendMessageHandler; import org.dynmap.web.handlers.SendMessageHandler.Message; -import org.dynmap.web.Json; public class DynmapPlugin extends JavaPlugin { @@ -79,7 +79,9 @@ public class DynmapPlugin extends JavaPlugin { loadDebuggers(); tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles")); - tilesDirectory.mkdirs(); + if (!tilesDirectory.isDirectory() && !tilesDirectory.mkdirs()) { + log.warning("Could not create directory for tiles ('" + tilesDirectory + "')."); + } playerList = new PlayerList(getServer(), getFile("hiddenplayers.txt")); playerList.load(); @@ -351,9 +353,9 @@ public class DynmapPlugin extends JavaPlugin { fos.write(Json.stringifyJson(clientConfig).getBytes()); fos.close(); } catch (FileNotFoundException ex) { - System.out.println("FileNotFoundException : " + ex); + log.log(Level.SEVERE, "Exception while writing JSON-configuration-file.", ex); } catch (IOException ioe) { - System.out.println("IOException : " + ioe); + log.log(Level.SEVERE, "Exception while writing JSON-configuration-file.", ioe); } } } diff --git a/src/main/java/org/dynmap/JsonTimerTask.java b/src/main/java/org/dynmap/JsonTimerTask.java index b9aba3c0..d7f95e76 100644 --- a/src/main/java/org/dynmap/JsonTimerTask.java +++ b/src/main/java/org/dynmap/JsonTimerTask.java @@ -5,6 +5,8 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.TimerTask; +import java.util.logging.Level; +import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.Server; @@ -14,6 +16,8 @@ import org.bukkit.util.config.Configuration; import org.dynmap.web.Json; class JsonTimerTask extends TimerTask { + protected static final Logger log = Logger.getLogger("Minecraft"); + private final DynmapPlugin plugin; private Server server; private MapManager mapManager; @@ -57,9 +61,9 @@ class JsonTimerTask extends TimerTask { fos.write(Json.stringifyJson(update).getBytes()); fos.close(); } catch (FileNotFoundException ex) { - System.out.println("FileNotFoundException : " + ex); + log.log(Level.SEVERE, "Exception while writing JSON-file.", ex); } catch (IOException ioe) { - System.out.println("IOException : " + ioe); + log.log(Level.SEVERE, "Exception while writing JSON-file.", ioe); } } } diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index ea5dfb7a..936546e4 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -107,7 +107,6 @@ public class MapManager { } } found.remove(tile); - System.gc(); } // Unload remaining chunks to clean-up. @@ -202,7 +201,9 @@ public class MapManager { worldTileDirectory = new File(DynmapPlugin.tilesDirectory, tile.getWorld().getName()); worldTileDirectories.put(world, worldTileDirectory); } - worldTileDirectory.mkdirs(); + if (!worldTileDirectory.isDirectory() && !worldTileDirectory.mkdirs()) { + log.warning("Could not create directory for tiles ('" + worldTileDirectory + "')."); + } return new File(worldTileDirectory, tile.getFilename()); } diff --git a/src/main/java/org/dynmap/UpdateQueue.java b/src/main/java/org/dynmap/UpdateQueue.java index 24a35eb5..368c987d 100644 --- a/src/main/java/org/dynmap/UpdateQueue.java +++ b/src/main/java/org/dynmap/UpdateQueue.java @@ -58,7 +58,7 @@ public class UpdateQueue { return updates; } - public class Update { + public static class Update { public long time; public Object obj; diff --git a/src/main/java/org/dynmap/flat/FlatMap.java b/src/main/java/org/dynmap/flat/FlatMap.java index 9e7f2726..40ae11dd 100644 --- a/src/main/java/org/dynmap/flat/FlatMap.java +++ b/src/main/java/org/dynmap/flat/FlatMap.java @@ -97,7 +97,7 @@ public class FlatMap extends MapType { return rendered; } - public class FlatMapTile extends MapTile { + public static class FlatMapTile extends MapTile { public int x; public int y; diff --git a/src/main/java/org/dynmap/kzedmap/KzedMap.java b/src/main/java/org/dynmap/kzedmap/KzedMap.java index 860a1e07..05a00430 100644 --- a/src/main/java/org/dynmap/kzedmap/KzedMap.java +++ b/src/main/java/org/dynmap/kzedmap/KzedMap.java @@ -3,6 +3,7 @@ package org.dynmap.kzedmap; import java.awt.Color; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.InputStream; import java.lang.reflect.Constructor; import java.util.ArrayList; @@ -10,6 +11,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; +import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Location; @@ -267,9 +269,11 @@ public class KzedMap extends MapType { nc += 1; } scanner.close(); - } catch (Exception e) { - Debug.error("Could not load colors", e); + } catch (RuntimeException e) { + log.log(Level.SEVERE, "Could not load colors", e); return null; + } catch (FileNotFoundException e) { + log.log(Level.SEVERE, "Could not load colors: file not found", e); } return colors; } diff --git a/src/main/java/org/dynmap/web/HttpServerConnection.java b/src/main/java/org/dynmap/web/HttpServerConnection.java index 4cc630f3..c1c96d12 100644 --- a/src/main/java/org/dynmap/web/HttpServerConnection.java +++ b/src/main/java/org/dynmap/web/HttpServerConnection.java @@ -115,6 +115,8 @@ public class HttpServerConnection extends Thread { public void run() { try { + if (socket == null) + return; socket.setSoTimeout(5000); InputStream in = socket.getInputStream(); BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream(), 40960); @@ -178,8 +180,10 @@ public class HttpServerConnection extends Thread { return; } - if (bound > 0) { - boundBody.skip(bound); + if (bound > 0 && boundBody.skip(bound) < bound) { + Debug.debug("Incoming stream was only read partially by handler '" + handler + "'."); + //socket.close(); + //return; } String connection = response.fields.get("Connection"); diff --git a/src/main/java/org/dynmap/web/Json.java b/src/main/java/org/dynmap/web/Json.java index f254e566..b1b95f38 100644 --- a/src/main/java/org/dynmap/web/Json.java +++ b/src/main/java/org/dynmap/web/Json.java @@ -3,8 +3,10 @@ package org.dynmap.web; import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.security.KeyStore.Entry; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; public class Json { public static String stringifyJson(Object o) { @@ -26,15 +28,15 @@ public class Json { LinkedHashMap m = (LinkedHashMap) o; s.append("{"); boolean first = true; - for (Object key : m.keySet()) { + for (Map.Entry entry : m.entrySet()) { if (first) first = false; else s.append(","); - appendJson(key, s); + appendJson(entry.getKey(), s); s.append(": "); - appendJson(m.get(key), s); + appendJson(entry.getValue(), s); } s.append("}"); } else if (o instanceof List) { diff --git a/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java b/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java index 8cacc932..24d41d5a 100644 --- a/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java +++ b/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java @@ -30,7 +30,7 @@ public class ClientUpdateHandler implements HttpHandler { this.server = server; } - Pattern updatePathPattern = Pattern.compile("world/([a-zA-Z0-9_-\\.]+)/([0-9]*)"); + Pattern updatePathPattern = Pattern.compile("world/([a-zA-Z0-9_\\-\\.]+)/([0-9]*)"); private static final HttpStatus WorldNotFound = new HttpStatus(HttpStatus.NotFound.getCode(), "World Not Found"); @Override public void handle(String path, HttpRequest request, HttpResponse response) throws Exception { diff --git a/src/main/java/org/dynmap/web/handlers/SendMessageHandler.java b/src/main/java/org/dynmap/web/handlers/SendMessageHandler.java index d33cd20f..27e77562 100644 --- a/src/main/java/org/dynmap/web/handlers/SendMessageHandler.java +++ b/src/main/java/org/dynmap/web/handlers/SendMessageHandler.java @@ -39,7 +39,7 @@ public class SendMessageHandler implements HttpHandler { response.status = HttpStatus.OK; response.getBody(); } - public class Message { + public static class Message { public String name; public String message; }