More exception handling and messages.

This commit is contained in:
FrozenCow 2011-01-15 02:57:11 +01:00
parent b22a48d5cb
commit b501f1d8cb
5 changed files with 86 additions and 54 deletions

View file

@ -99,6 +99,7 @@ public class MapManager extends Thread {
/* initialize and start map manager */ /* initialize and start map manager */
public void startManager() public void startManager()
{ {
synchronized(lock) {
running = true; running = true;
this.start(); this.start();
try { try {
@ -108,10 +109,12 @@ public class MapManager extends Thread {
log.info("Failed to set minimum priority for worker thread!"); log.info("Failed to set minimum priority for worker thread!");
} }
} }
}
/* stop map manager */ /* stop map manager */
public void stopManager() public void stopManager()
{ {
synchronized(lock) {
if(!running) if(!running)
return; return;
@ -124,10 +127,12 @@ public class MapManager extends Thread {
log.info("Waiting for map renderer to stop is interrupted"); log.info("Waiting for map renderer to stop is interrupted");
} }
} }
}
/* the worker/renderer thread */ /* the worker/renderer thread */
public void run() public void run()
{ {
try {
log.info("Map renderer has started."); log.info("Map renderer has started.");
while(running) { while(running) {
@ -141,7 +146,7 @@ public class MapManager extends Thread {
staleQueue.onTileUpdated(t); staleQueue.onTileUpdated(t);
try { try {
this.sleep(renderWait); Thread.sleep(renderWait);
} catch(InterruptedException e) { } catch(InterruptedException e) {
} }
@ -150,13 +155,16 @@ public class MapManager extends Thread {
if(!found) { if(!found) {
try { try {
this.sleep(500); Thread.sleep(500);
} catch(InterruptedException e) { } catch(InterruptedException e) {
} }
} }
} }
log.info("Map renderer has stopped."); log.info("Map renderer has stopped.");
} catch(Exception ex) {
debugger.error("Exception on rendering-thread: " + ex.toString());
}
} }
public void touch(int x, int y, int z) { public void touch(int x, int y, int z) {

View file

@ -34,6 +34,7 @@ public class WebServer extends Thread {
public void run() public void run()
{ {
try {
while (running) { while (running) {
try { try {
Socket socket = sock.accept(); Socket socket = sock.accept();
@ -46,6 +47,9 @@ public class WebServer extends Thread {
} }
} }
log.info("map WebServer run() exiting"); log.info("map WebServer run() exiting");
} catch (Exception ex) {
debugger.error("Exception on WebServer-thread: " + ex.toString());
}
} }
public void shutdown() public void shutdown()

View file

@ -94,6 +94,9 @@ public class WebServerRequest extends Thread {
} }
} }
} }
catch(Exception ex) {
debugger.error("Exception on WebRequest-thread: " + ex.toString());
}
} }
public void handleUp(BufferedOutputStream out, String path) throws IOException { public void handleUp(BufferedOutputStream out, String path) throws IOException {

View file

@ -34,45 +34,45 @@ public class BukkitPlayerDebugger implements Debugger {
prepend = pdfFile.getName() + ": "; prepend = pdfFile.getName() + ": ";
} }
public void enable() { public synchronized void enable() {
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, new CommandListener(), Priority.Normal, plugin); plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, new CommandListener(), Priority.Normal, plugin);
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, new CommandListener(), Priority.Normal, plugin); plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, new CommandListener(), Priority.Normal, plugin);
log.info("Debugger enabled, use: " + debugCommand); log.info("Debugger enabled, use: " + debugCommand);
} }
public void disable() { public synchronized void disable() {
clearDebugees(); clearDebugees();
} }
public void addDebugee(Player p) { public synchronized void addDebugee(Player p) {
debugees.add(p); debugees.add(p);
} }
public void removeDebugee(Player p) { public synchronized void removeDebugee(Player p) {
debugees.remove(p); debugees.remove(p);
} }
public void clearDebugees() { public synchronized void clearDebugees() {
debugees.clear(); debugees.clear();
} }
public void sendToDebuggees(String message) { public synchronized void sendToDebuggees(String message) {
for (Player p : debugees) { for (Player p : debugees) {
p.sendMessage(prepend + message); p.sendMessage(prepend + message);
} }
} }
public void debug(String message) { public synchronized void debug(String message) {
sendToDebuggees(message); sendToDebuggees(message);
if (isLogging) log.info(prepend + message); if (isLogging) log.info(prepend + message);
} }
public void error(String message) { public synchronized void error(String message) {
sendToDebuggees(prepend + ChatColor.RED + message); sendToDebuggees(prepend + ChatColor.RED + message);
if (isLogging) log.log(Level.SEVERE, prepend + message); if (isLogging) log.log(Level.SEVERE, prepend + message);
} }
public void error(String message, Throwable thrown) { public synchronized void error(String message, Throwable thrown) {
sendToDebuggees(prepend + ChatColor.RED + message); sendToDebuggees(prepend + ChatColor.RED + message);
sendToDebuggees(thrown.toString()); sendToDebuggees(thrown.toString());
if (isLogging) log.log(Level.SEVERE, prepend + message); if (isLogging) log.log(Level.SEVERE, prepend + message);

View file

@ -13,6 +13,8 @@ import java.util.logging.Logger;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.bukkit.Block;
import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.dynmap.MapManager; import org.dynmap.MapManager;
import org.dynmap.MapTile; import org.dynmap.MapTile;
@ -40,6 +42,21 @@ public class DefaultTileRenderer implements MapTileRenderer {
int ix = tile.mx; int ix = tile.mx;
int iy = tile.my; int iy = tile.my;
int iz = tile.mz; int iz = tile.mz;
Block block = tile.getMap().getWorld().getBlockAt(ix, iy, iz);
if (block == null) {
debugger.debug("Could not get block for rendering.");
return;
}
Chunk chunk = block.getChunk();
if (chunk == null) {
debugger.debug("Could not get chunk for rendering.");
return;
}
if (!world.isChunkLoaded(chunk)) {
debugger.debug("Chunk was not loaded, but we'll still continue render.");
}
int jx, jz; int jx, jz;
int x, y; int x, y;