Some changes after running Findbugs.

This commit is contained in:
FrozenCow 2011-03-05 16:09:26 +01:00
parent b0c84234cc
commit 8d70839d3b
10 changed files with 39 additions and 22 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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());
}

View File

@ -58,7 +58,7 @@ public class UpdateQueue {
return updates;
}
public class Update {
public static class Update {
public long time;
public Object obj;

View File

@ -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;

View File

@ -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;
}

View File

@ -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");

View File

@ -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<?>) {

View File

@ -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 {

View File

@ -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;
}