Applied Eclipse formatting.

This commit is contained in:
FrozenCow 2011-02-05 02:25:18 +01:00
parent e7aff6ee79
commit a89ef6ac75
25 changed files with 1763 additions and 1708 deletions

View file

@ -2,31 +2,27 @@ package org.dynmap;
import java.util.HashMap;
public class Cache<K, V>
{
public class Cache<K, V> {
private final int size;
private int len;
private CacheNode head;
private CacheNode tail;
private class CacheNode
{
private class CacheNode {
public CacheNode prev;
public CacheNode next;
public K key;
public V value;
public CacheNode(K key, V value)
{
public CacheNode(K key, V value) {
this.key = key;
this.value = value;
prev = null;
next = null;
}
public void unlink()
{
public void unlink() {
if (prev == null) {
head = next;
} else {
@ -45,8 +41,7 @@ public class Cache<K, V>
len--;
}
public void append()
{
public void append() {
if (tail == null) {
head = this;
tail = this;
@ -62,8 +57,7 @@ public class Cache<K, V>
private HashMap<K, CacheNode> map;
public Cache(int size)
{
public Cache(int size) {
this.size = size;
len = 0;
@ -73,22 +67,23 @@ public class Cache<K, V>
map = new HashMap<K, CacheNode>();
}
/* returns value for key, if key exists in the cache
* otherwise null */
public V get(K key)
{
/*
* returns value for key, if key exists in the cache otherwise null
*/
public V get(K key) {
CacheNode n = map.get(key);
if (n == null)
return null;
return n.value;
}
/* puts a new key-value pair in the cache
* if the key existed already, the value is updated, and the old value is returned
* if the key didn't exist, it is added; the oldest value (now pushed out of the
* cache) may be returned, or null if the cache isn't yet full */
public V put(K key, V value)
{
/*
* puts a new key-value pair in the cache if the key existed already, the
* value is updated, and the old value is returned if the key didn't exist,
* it is added; the oldest value (now pushed out of the cache) may be
* returned, or null if the cache isn't yet full
*/
public V put(K key, V value) {
CacheNode n = map.get(key);
if (n == null) {
V ret = null;

View file

@ -7,14 +7,12 @@ import org.bukkit.event.player.PlayerChatEvent;
public class ChatQueue {
public class ChatMessage
{
public class ChatMessage {
public long time;
public String playerName;
public String message;
public ChatMessage(PlayerChatEvent event)
{
public ChatMessage(PlayerChatEvent event) {
time = System.currentTimeMillis();
playerName = event.getPlayer().getName();
message = event.getMessage();
@ -32,8 +30,7 @@ public class ChatQueue {
}
/* put a chat message in the queue */
public void pushChatMessage(PlayerChatEvent event)
{
public void pushChatMessage(PlayerChatEvent event) {
synchronized (MapManager.lock) {
messageQueue.add(new ChatMessage(event));
}
@ -50,14 +47,10 @@ public class ChatQueue {
synchronized (MapManager.lock) {
for (ChatMessage message : queue)
{
if (message.time < deadline)
{
for (ChatMessage message : queue) {
if (message.time < deadline) {
messageQueue.remove(message);
}
else if (message.time >= cutoff)
{
} else if (message.time >= cutoff) {
updateList.add(message);
}
}

View file

@ -2,6 +2,7 @@ package org.dynmap;
public class DynmapChunk {
public int x, y;
public DynmapChunk(int x, int y) {
this.x = x;
this.y = y;

View file

@ -25,14 +25,20 @@ public class DynmapPlayerListener extends PlayerListener {
} else if (split[1].equals("hide")) {
if (split.length == 2) {
playerList.hide(event.getPlayer().getName());
} else for (int i=2;i<split.length;i++)
} else {
for (int i = 2; i < split.length; i++) {
playerList.hide(split[i]);
}
}
event.setCancelled(true);
} else if (split[1].equals("show")) {
if (split.length == 2) {
playerList.show(event.getPlayer().getName());
} else for (int i=2;i<split.length;i++)
} else {
for (int i = 2; i < split.length; i++) {
playerList.show(split[i]);
}
}
event.setCancelled(true);
} else if (split[1].equals("fullrender")) {
Player player = event.getPlayer();
@ -48,10 +54,10 @@ public class DynmapPlayerListener extends PlayerListener {
/**
* Called when a player sends a chat message
*
* @param event Relevant event details
* @param event
* Relevant event details
*/
public void onPlayerChat(PlayerChatEvent event)
{
public void onPlayerChat(PlayerChatEvent event) {
mgr.addChatEvent(event);
}
}

View file

@ -2,6 +2,7 @@ package org.dynmap;
public abstract class MapTile {
private MapType map;
public MapType getMap() {
return map;
}

View file

@ -6,16 +6,19 @@ import org.dynmap.debug.Debugger;
public abstract class MapType {
private MapManager manager;
public MapManager getMapManager() {
return manager;
}
private World world;
public World getWorld() {
return world;
}
private Debugger debugger;
public Debugger getDebugger() {
return debugger;
}
@ -27,8 +30,12 @@ public abstract class MapType {
}
public abstract MapTile[] getTiles(Location l);
public abstract MapTile[] getAdjecentTiles(MapTile tile);
public abstract DynmapChunk[] getRequiredChunks(MapTile tile);
public abstract boolean render(MapTile tile);
public abstract boolean isRendered(MapTile tile);
}

View file

@ -62,7 +62,10 @@ public class PlayerList {
}
public void setVisible(String playerName, boolean visible) {
if (visible) show(playerName); else hide(playerName);
if (visible)
show(playerName);
else
hide(playerName);
}
public Player[] getVisiblePlayers() {

View file

@ -30,8 +30,7 @@ public class StaleQueue {
}
/* put a MapTile that needs to be regenerated on the list of stale tiles */
public boolean pushStaleTile(MapTile m)
{
public boolean pushStaleTile(MapTile m) {
synchronized (MapManager.lock) {
if (staleTiles.add(m)) {
staleTilesQueue.addLast(m);
@ -41,10 +40,11 @@ public class StaleQueue {
}
}
/* get next MapTile that needs to be regenerated, or null
* the mapTile is removed from the list of stale tiles! */
public MapTile popStaleTile()
{
/*
* get next MapTile that needs to be regenerated, or null the mapTile is
* removed from the list of stale tiles!
*/
public MapTile popStaleTile() {
synchronized (MapManager.lock) {
try {
MapTile t = staleTilesQueue.removeFirst();
@ -73,6 +73,7 @@ public class StaleQueue {
}
private ArrayList<TileUpdate> tmpupdates = new ArrayList<TileUpdate>();
public TileUpdate[] getTileUpdates(long cutoff) {
long now = System.currentTimeMillis();
long deadline = now - maxTileAge;
@ -84,7 +85,9 @@ public class StaleQueue {
TileUpdate tu = it.next();
if (tu.at >= cutoff) { // Tile is new.
tmpupdates.add(tu);
} else if(tu.at < deadline) { // Tile is too old, removing this one (will eventually decrease).
} else if (tu.at < deadline) { // Tile is too old, removing this
// one (will eventually
// decrease).
it.remove();
break;
} else { // Tile is old, but not old enough for removal.

View file

@ -6,8 +6,7 @@ public class TileUpdate {
public long at;
public MapTile tile;
public TileUpdate(long at, MapTile tile)
{
public TileUpdate(long at, MapTile tile) {
this.at = at;
this.tile = tile;
}

View file

@ -63,7 +63,8 @@ public class BukkitPlayerDebugger implements Debugger {
public synchronized void debug(String message) {
sendToDebuggees(message);
if (isLogging) log.info(prepend + message);
if (isLogging)
log.info(prepend + message);
}
public synchronized void error(String message) {

View file

@ -2,6 +2,8 @@ package org.dynmap.debug;
public interface Debugger {
void debug(String message);
void error(String message);
void error(String message, Throwable thrown);
}

View file

@ -2,6 +2,7 @@ package org.dynmap.debug;
public class NullDebugger implements Debugger {
public static final NullDebugger instance = new NullDebugger();
public void debug(String message) {
}

View file

@ -12,8 +12,7 @@ public class CaveTileRenderer extends DefaultTileRenderer {
}
@Override
protected Color scan(World world, int x, int y, int z, int seq)
{
protected Color scan(World world, int x, int y, int z, int seq) {
boolean air = true;
for (;;) {

View file

@ -50,8 +50,14 @@ public class DefaultTileRenderer implements MapTileRenderer {
Color c1 = scan(world, jx, iy, jz, 0);
Color c2 = scan(world, jx, iy, jz, 2);
isempty = isempty && c1 == translucent && c2 == translucent;
r.setPixel(x, y, new int[] { c1.getRed(), c1.getGreen(), c1.getBlue() });
r.setPixel(x - 1, y, new int[] { c2.getRed(), c2.getGreen(), c2.getBlue() });
r.setPixel(x, y, new int[] {
c1.getRed(),
c1.getGreen(),
c1.getBlue() });
r.setPixel(x - 1, y, new int[] {
c2.getRed(),
c2.getGreen(),
c2.getBlue() });
jx++;
jz++;
@ -69,8 +75,14 @@ public class DefaultTileRenderer implements MapTileRenderer {
jz++;
Color c2 = scan(world, jx, iy, jz, 0);
isempty = isempty && c1 == translucent && c2 == translucent;
r.setPixel(x, y, new int[] { c1.getRed(), c1.getGreen(), c1.getBlue() });
r.setPixel(x - 1, y, new int[] { c2.getRed(), c2.getGreen(), c2.getBlue() });
r.setPixel(x, y, new int[] {
c1.getRed(),
c1.getGreen(),
c1.getBlue() });
r.setPixel(x - 1, y, new int[] {
c2.getRed(),
c2.getGreen(),
c2.getBlue() });
}
y++;

View file

@ -26,8 +26,10 @@ public class KzedMap extends MapType {
public static final int tileWidth = 128;
public static final int tileHeight = 128;
/* (logical!) dimensions of a zoomed out map tile
* must be twice the size of the normal tile */
/*
* (logical!) dimensions of a zoomed out map tile must be twice the size of
* the normal tile
*/
public static final int zTileWidth = 256;
public static final int zTileHeight = 256;
@ -96,15 +98,23 @@ public class KzedMap extends MapType {
boolean redge = tilex(px + 4) != tx;
boolean bedge = tiley(py + 4) != ty;
if (ledge) addTile(tiles, tx - tileWidth, ty);
if (redge) addTile(tiles, tx + tileWidth, ty);
if (tedge) addTile(tiles, tx, ty - tileHeight);
if (bedge) addTile(tiles, tx, ty + tileHeight);
if (ledge)
addTile(tiles, tx - tileWidth, ty);
if (redge)
addTile(tiles, tx + tileWidth, ty);
if (tedge)
addTile(tiles, tx, ty - tileHeight);
if (bedge)
addTile(tiles, tx, ty + tileHeight);
if (ledge && tedge) addTile(tiles, tx - tileWidth, ty - tileHeight);
if (ledge && bedge) addTile(tiles, tx - tileWidth, ty + tileHeight);
if (redge && tedge) addTile(tiles, tx + tileWidth, ty - tileHeight);
if (redge && bedge) addTile(tiles, tx + tileWidth, ty + tileHeight);
if (ledge && tedge)
addTile(tiles, tx - tileWidth, ty - tileHeight);
if (ledge && bedge)
addTile(tiles, tx - tileWidth, ty + tileHeight);
if (redge && tedge)
addTile(tiles, tx + tileWidth, ty - tileHeight);
if (redge && bedge)
addTile(tiles, tx + tileWidth, ty + tileHeight);
MapTile[] result = new MapTile[tiles.size()];
tiles.toArray(result);
@ -120,8 +130,7 @@ public class KzedMap extends MapType {
new KzedMapTile(this, renderer, t.px - tileWidth, t.py),
new KzedMapTile(this, renderer, t.px + tileWidth, t.py),
new KzedMapTile(this, renderer, t.px, t.py - tileHeight),
new KzedMapTile(this, renderer, t.px, t.py + tileHeight)
};
new KzedMapTile(this, renderer, t.px, t.py + tileHeight) };
}
return new MapTile[0];
}

View file

@ -1,7 +1,7 @@
package org.dynmap.kzedmap;
public interface MapTileRenderer {
String getName();
boolean render(KzedMapTile tile, String path);
}

View file

@ -49,8 +49,10 @@ public class ZoomedTileRenderer {
int ox = 0;
int oy = 0;
if(zpx != px) ox = scw;
if(zpy != py) oy = sch;
if (zpx != px)
ox = scw;
if (zpy != py)
oy = sch;
/* blit scaled rendered tile onto zoom-out tile */
// WritableRaster zr = zIm.getRaster();

View file

@ -27,8 +27,7 @@ public class WebServer extends Thread {
private PlayerList playerList;
private ConfigurationNode configuration;
public WebServer(MapManager mgr, World world, 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.world = world;
this.playerList = playerList;
@ -38,22 +37,22 @@ public class WebServer extends Thread {
String bindAddress = configuration.getString("webserver-bindaddress", "0.0.0.0");
int port = configuration.getInt("webserver-port", 8123);
sock = new ServerSocket(port, 5, bindAddress.equals("0.0.0.0") ? null : InetAddress.getByName(bindAddress));
sock = new ServerSocket(port, 5, bindAddress.equals("0.0.0.0")
? null
: InetAddress.getByName(bindAddress));
running = true;
start();
log.info("Dynmap WebServer started on " + bindAddress + ":" + port);
}
public void run()
{
public void run() {
try {
while (running) {
try {
Socket socket = sock.accept();
WebServerRequest requestThread = new WebServerRequest(socket, mgr, world, playerList, configuration, debugger);
requestThread.start();
}
catch (IOException e) {
} catch (IOException e) {
log.info("map WebServer.run() stops with IOException");
break;
}
@ -64,8 +63,7 @@ public class WebServer extends Thread {
}
}
public void shutdown()
{
public void shutdown() {
try {
if (sock != null) {
sock.close();

View file

@ -34,8 +34,7 @@ public class WebServerRequest extends Thread {
private PlayerList playerList;
private ConfigurationNode configuration;
public WebServerRequest(Socket socket, MapManager mgr, World world, 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;
@ -64,8 +63,7 @@ public class WebServerRequest extends Thread {
out.write(10);
}
public void run()
{
public void run() {
BufferedReader in = null;
BufferedOutputStream out = null;
try {
@ -94,14 +92,32 @@ public class WebServerRequest extends Thread {
}
out.flush();
out.close();
} catch (IOException e) {
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) {
}
catch (IOException e) {
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());
}
}
@ -122,8 +138,10 @@ public class WebServerRequest extends Thread {
sb.append("{");
boolean first = true;
for (String key : m.keySet()) {
if (first) first = false;
else sb.append(",");
if (first)
first = false;
else
sb.append(",");
sb.append(stringifyJson(key));
sb.append(": ");
@ -213,7 +231,8 @@ public class WebServerRequest extends Thread {
public void writeFile(BufferedOutputStream out, String path, InputStream fileInput) throws IOException {
int dotindex = path.lastIndexOf('.');
String extension = null;
if (dotindex > 0) extension = path.substring(dotindex);
if (dotindex > 0)
extension = path.substring(dotindex);
writeHttpHeader(out, 200, "OK");
writeHeaderField(out, "Content-Type", getMimeTypeFromExtension(extension));
@ -233,12 +252,14 @@ public class WebServerRequest extends Thread {
public String getFilePath(String path) {
int qmark = path.indexOf('?');
if (qmark >= 0) path = path.substring(0, qmark);
if (qmark >= 0)
path = path.substring(0, qmark);
path = path.substring(1);
if (path.startsWith("/") || path.startsWith("."))
return null;
if (path.length() == 0) path = "index.html";
if (path.length() == 0)
path = "index.html";
return path;
}
@ -279,9 +300,11 @@ public class WebServerRequest extends Thread {
mimes.put(".css", "text/css");
mimes.put(".txt", "text/plain");
}
public static String getMimeTypeFromExtension(String extension) {
String m = mimes.get(extension);
if (m != null) return m;
if (m != null)
return m;
return "application/octet-steam";
}
}