Applied Eclipse formatting.
This commit is contained in:
parent
e7aff6ee79
commit
a89ef6ac75
25 changed files with 1763 additions and 1708 deletions
|
|
@ -2,31 +2,27 @@ package org.dynmap;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Cache<K, V>
|
public class Cache<K, V> {
|
||||||
{
|
|
||||||
private final int size;
|
private final int size;
|
||||||
private int len;
|
private int len;
|
||||||
|
|
||||||
private CacheNode head;
|
private CacheNode head;
|
||||||
private CacheNode tail;
|
private CacheNode tail;
|
||||||
|
|
||||||
private class CacheNode
|
private class CacheNode {
|
||||||
{
|
|
||||||
public CacheNode prev;
|
public CacheNode prev;
|
||||||
public CacheNode next;
|
public CacheNode next;
|
||||||
public K key;
|
public K key;
|
||||||
public V value;
|
public V value;
|
||||||
|
|
||||||
public CacheNode(K key, V value)
|
public CacheNode(K key, V value) {
|
||||||
{
|
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
prev = null;
|
prev = null;
|
||||||
next = null;
|
next = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unlink()
|
public void unlink() {
|
||||||
{
|
|
||||||
if (prev == null) {
|
if (prev == null) {
|
||||||
head = next;
|
head = next;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -45,8 +41,7 @@ public class Cache<K, V>
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void append()
|
public void append() {
|
||||||
{
|
|
||||||
if (tail == null) {
|
if (tail == null) {
|
||||||
head = this;
|
head = this;
|
||||||
tail = this;
|
tail = this;
|
||||||
|
|
@ -62,8 +57,7 @@ public class Cache<K, V>
|
||||||
|
|
||||||
private HashMap<K, CacheNode> map;
|
private HashMap<K, CacheNode> map;
|
||||||
|
|
||||||
public Cache(int size)
|
public Cache(int size) {
|
||||||
{
|
|
||||||
this.size = size;
|
this.size = size;
|
||||||
len = 0;
|
len = 0;
|
||||||
|
|
||||||
|
|
@ -73,22 +67,23 @@ public class Cache<K, V>
|
||||||
map = new HashMap<K, CacheNode>();
|
map = new HashMap<K, CacheNode>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns value for key, if key exists in the cache
|
/*
|
||||||
* otherwise null */
|
* returns value for key, if key exists in the cache otherwise null
|
||||||
public V get(K key)
|
*/
|
||||||
{
|
public V get(K key) {
|
||||||
CacheNode n = map.get(key);
|
CacheNode n = map.get(key);
|
||||||
if (n == null)
|
if (n == null)
|
||||||
return null;
|
return null;
|
||||||
return n.value;
|
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
|
* puts a new key-value pair in the cache if the key existed already, the
|
||||||
* if the key didn't exist, it is added; the oldest value (now pushed out of the
|
* value is updated, and the old value is returned if the key didn't exist,
|
||||||
* cache) may be returned, or null if the cache isn't yet full */
|
* it is added; the oldest value (now pushed out of the cache) may be
|
||||||
public V put(K key, V value)
|
* returned, or null if the cache isn't yet full
|
||||||
{
|
*/
|
||||||
|
public V put(K key, V value) {
|
||||||
CacheNode n = map.get(key);
|
CacheNode n = map.get(key);
|
||||||
if (n == null) {
|
if (n == null) {
|
||||||
V ret = null;
|
V ret = null;
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,12 @@ import org.bukkit.event.player.PlayerChatEvent;
|
||||||
|
|
||||||
public class ChatQueue {
|
public class ChatQueue {
|
||||||
|
|
||||||
public class ChatMessage
|
public class ChatMessage {
|
||||||
{
|
|
||||||
public long time;
|
public long time;
|
||||||
public String playerName;
|
public String playerName;
|
||||||
public String message;
|
public String message;
|
||||||
|
|
||||||
public ChatMessage(PlayerChatEvent event)
|
public ChatMessage(PlayerChatEvent event) {
|
||||||
{
|
|
||||||
time = System.currentTimeMillis();
|
time = System.currentTimeMillis();
|
||||||
playerName = event.getPlayer().getName();
|
playerName = event.getPlayer().getName();
|
||||||
message = event.getMessage();
|
message = event.getMessage();
|
||||||
|
|
@ -32,8 +30,7 @@ public class ChatQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* put a chat message in the queue */
|
/* put a chat message in the queue */
|
||||||
public void pushChatMessage(PlayerChatEvent event)
|
public void pushChatMessage(PlayerChatEvent event) {
|
||||||
{
|
|
||||||
synchronized (MapManager.lock) {
|
synchronized (MapManager.lock) {
|
||||||
messageQueue.add(new ChatMessage(event));
|
messageQueue.add(new ChatMessage(event));
|
||||||
}
|
}
|
||||||
|
|
@ -50,14 +47,10 @@ public class ChatQueue {
|
||||||
|
|
||||||
synchronized (MapManager.lock) {
|
synchronized (MapManager.lock) {
|
||||||
|
|
||||||
for (ChatMessage message : queue)
|
for (ChatMessage message : queue) {
|
||||||
{
|
if (message.time < deadline) {
|
||||||
if (message.time < deadline)
|
|
||||||
{
|
|
||||||
messageQueue.remove(message);
|
messageQueue.remove(message);
|
||||||
}
|
} else if (message.time >= cutoff) {
|
||||||
else if (message.time >= cutoff)
|
|
||||||
{
|
|
||||||
updateList.add(message);
|
updateList.add(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package org.dynmap;
|
||||||
|
|
||||||
public class DynmapChunk {
|
public class DynmapChunk {
|
||||||
public int x, y;
|
public int x, y;
|
||||||
|
|
||||||
public DynmapChunk(int x, int y) {
|
public DynmapChunk(int x, int y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,20 @@ public class DynmapPlayerListener extends PlayerListener {
|
||||||
} else if (split[1].equals("hide")) {
|
} else if (split[1].equals("hide")) {
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
playerList.hide(event.getPlayer().getName());
|
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]);
|
playerList.hide(split[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (split[1].equals("show")) {
|
} else if (split[1].equals("show")) {
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
playerList.show(event.getPlayer().getName());
|
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]);
|
playerList.show(split[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (split[1].equals("fullrender")) {
|
} else if (split[1].equals("fullrender")) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
@ -48,10 +54,10 @@ public class DynmapPlayerListener extends PlayerListener {
|
||||||
/**
|
/**
|
||||||
* Called when a player sends a chat message
|
* 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);
|
mgr.addChatEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ package org.dynmap;
|
||||||
|
|
||||||
public abstract class MapTile {
|
public abstract class MapTile {
|
||||||
private MapType map;
|
private MapType map;
|
||||||
|
|
||||||
public MapType getMap() {
|
public MapType getMap() {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,19 @@ import org.dynmap.debug.Debugger;
|
||||||
|
|
||||||
public abstract class MapType {
|
public abstract class MapType {
|
||||||
private MapManager manager;
|
private MapManager manager;
|
||||||
|
|
||||||
public MapManager getMapManager() {
|
public MapManager getMapManager() {
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Debugger debugger;
|
private Debugger debugger;
|
||||||
|
|
||||||
public Debugger getDebugger() {
|
public Debugger getDebugger() {
|
||||||
return debugger;
|
return debugger;
|
||||||
}
|
}
|
||||||
|
|
@ -27,8 +30,12 @@ public abstract class MapType {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract MapTile[] getTiles(Location l);
|
public abstract MapTile[] getTiles(Location l);
|
||||||
|
|
||||||
public abstract MapTile[] getAdjecentTiles(MapTile tile);
|
public abstract MapTile[] getAdjecentTiles(MapTile tile);
|
||||||
|
|
||||||
public abstract DynmapChunk[] getRequiredChunks(MapTile tile);
|
public abstract DynmapChunk[] getRequiredChunks(MapTile tile);
|
||||||
|
|
||||||
public abstract boolean render(MapTile tile);
|
public abstract boolean render(MapTile tile);
|
||||||
|
|
||||||
public abstract boolean isRendered(MapTile tile);
|
public abstract boolean isRendered(MapTile tile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,10 @@ public class PlayerList {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisible(String playerName, boolean visible) {
|
public void setVisible(String playerName, boolean visible) {
|
||||||
if (visible) show(playerName); else hide(playerName);
|
if (visible)
|
||||||
|
show(playerName);
|
||||||
|
else
|
||||||
|
hide(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player[] getVisiblePlayers() {
|
public Player[] getVisiblePlayers() {
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,7 @@ public class StaleQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* put a MapTile that needs to be regenerated on the list of stale tiles */
|
/* 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) {
|
synchronized (MapManager.lock) {
|
||||||
if (staleTiles.add(m)) {
|
if (staleTiles.add(m)) {
|
||||||
staleTilesQueue.addLast(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! */
|
* get next MapTile that needs to be regenerated, or null the mapTile is
|
||||||
public MapTile popStaleTile()
|
* removed from the list of stale tiles!
|
||||||
{
|
*/
|
||||||
|
public MapTile popStaleTile() {
|
||||||
synchronized (MapManager.lock) {
|
synchronized (MapManager.lock) {
|
||||||
try {
|
try {
|
||||||
MapTile t = staleTilesQueue.removeFirst();
|
MapTile t = staleTilesQueue.removeFirst();
|
||||||
|
|
@ -73,6 +73,7 @@ public class StaleQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<TileUpdate> tmpupdates = new ArrayList<TileUpdate>();
|
private ArrayList<TileUpdate> tmpupdates = new ArrayList<TileUpdate>();
|
||||||
|
|
||||||
public TileUpdate[] getTileUpdates(long cutoff) {
|
public TileUpdate[] getTileUpdates(long cutoff) {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
long deadline = now - maxTileAge;
|
long deadline = now - maxTileAge;
|
||||||
|
|
@ -84,7 +85,9 @@ public class StaleQueue {
|
||||||
TileUpdate tu = it.next();
|
TileUpdate tu = it.next();
|
||||||
if (tu.at >= cutoff) { // Tile is new.
|
if (tu.at >= cutoff) { // Tile is new.
|
||||||
tmpupdates.add(tu);
|
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();
|
it.remove();
|
||||||
break;
|
break;
|
||||||
} else { // Tile is old, but not old enough for removal.
|
} else { // Tile is old, but not old enough for removal.
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ public class TileUpdate {
|
||||||
public long at;
|
public long at;
|
||||||
public MapTile tile;
|
public MapTile tile;
|
||||||
|
|
||||||
public TileUpdate(long at, MapTile tile)
|
public TileUpdate(long at, MapTile tile) {
|
||||||
{
|
|
||||||
this.at = at;
|
this.at = at;
|
||||||
this.tile = tile;
|
this.tile = tile;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,8 @@ public class BukkitPlayerDebugger implements Debugger {
|
||||||
|
|
||||||
public synchronized 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 synchronized void error(String message) {
|
public synchronized void error(String message) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package org.dynmap.debug;
|
||||||
|
|
||||||
public interface Debugger {
|
public interface Debugger {
|
||||||
void debug(String message);
|
void debug(String message);
|
||||||
|
|
||||||
void error(String message);
|
void error(String message);
|
||||||
|
|
||||||
void error(String message, Throwable thrown);
|
void error(String message, Throwable thrown);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package org.dynmap.debug;
|
||||||
|
|
||||||
public class NullDebugger implements Debugger {
|
public class NullDebugger implements Debugger {
|
||||||
public static final NullDebugger instance = new NullDebugger();
|
public static final NullDebugger instance = new NullDebugger();
|
||||||
|
|
||||||
public void debug(String message) {
|
public void debug(String message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@ public class CaveTileRenderer extends DefaultTileRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
boolean air = true;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,14 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
||||||
Color c1 = scan(world, jx, iy, jz, 0);
|
Color c1 = scan(world, jx, iy, jz, 0);
|
||||||
Color c2 = scan(world, jx, iy, jz, 2);
|
Color c2 = scan(world, jx, iy, jz, 2);
|
||||||
isempty = isempty && c1 == translucent && c2 == translucent;
|
isempty = isempty && c1 == translucent && c2 == translucent;
|
||||||
r.setPixel(x, y, new int[] { c1.getRed(), c1.getGreen(), c1.getBlue() });
|
r.setPixel(x, y, new int[] {
|
||||||
r.setPixel(x - 1, y, new int[] { c2.getRed(), c2.getGreen(), c2.getBlue() });
|
c1.getRed(),
|
||||||
|
c1.getGreen(),
|
||||||
|
c1.getBlue() });
|
||||||
|
r.setPixel(x - 1, y, new int[] {
|
||||||
|
c2.getRed(),
|
||||||
|
c2.getGreen(),
|
||||||
|
c2.getBlue() });
|
||||||
|
|
||||||
jx++;
|
jx++;
|
||||||
jz++;
|
jz++;
|
||||||
|
|
@ -69,8 +75,14 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
||||||
jz++;
|
jz++;
|
||||||
Color c2 = scan(world, jx, iy, jz, 0);
|
Color c2 = scan(world, jx, iy, jz, 0);
|
||||||
isempty = isempty && c1 == translucent && c2 == translucent;
|
isempty = isempty && c1 == translucent && c2 == translucent;
|
||||||
r.setPixel(x, y, new int[] { c1.getRed(), c1.getGreen(), c1.getBlue() });
|
r.setPixel(x, y, new int[] {
|
||||||
r.setPixel(x - 1, y, new int[] { c2.getRed(), c2.getGreen(), c2.getBlue() });
|
c1.getRed(),
|
||||||
|
c1.getGreen(),
|
||||||
|
c1.getBlue() });
|
||||||
|
r.setPixel(x - 1, y, new int[] {
|
||||||
|
c2.getRed(),
|
||||||
|
c2.getGreen(),
|
||||||
|
c2.getBlue() });
|
||||||
}
|
}
|
||||||
|
|
||||||
y++;
|
y++;
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,10 @@ public class KzedMap extends MapType {
|
||||||
public static final int tileWidth = 128;
|
public static final int tileWidth = 128;
|
||||||
public static final int tileHeight = 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 zTileWidth = 256;
|
||||||
public static final int zTileHeight = 256;
|
public static final int zTileHeight = 256;
|
||||||
|
|
||||||
|
|
@ -96,15 +98,23 @@ public class KzedMap extends MapType {
|
||||||
boolean redge = tilex(px + 4) != tx;
|
boolean redge = tilex(px + 4) != tx;
|
||||||
boolean bedge = tiley(py + 4) != ty;
|
boolean bedge = tiley(py + 4) != ty;
|
||||||
|
|
||||||
if (ledge) addTile(tiles, tx - tileWidth, ty);
|
if (ledge)
|
||||||
if (redge) addTile(tiles, tx + tileWidth, ty);
|
addTile(tiles, tx - tileWidth, ty);
|
||||||
if (tedge) addTile(tiles, tx, ty - tileHeight);
|
if (redge)
|
||||||
if (bedge) addTile(tiles, tx, ty + tileHeight);
|
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 && tedge)
|
||||||
if (ledge && bedge) addTile(tiles, tx - tileWidth, ty + tileHeight);
|
addTile(tiles, tx - tileWidth, ty - tileHeight);
|
||||||
if (redge && tedge) addTile(tiles, tx + tileWidth, ty - tileHeight);
|
if (ledge && bedge)
|
||||||
if (redge && bedge) addTile(tiles, tx + tileWidth, ty + tileHeight);
|
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()];
|
MapTile[] result = new MapTile[tiles.size()];
|
||||||
tiles.toArray(result);
|
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 + 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)
|
new KzedMapTile(this, renderer, t.px, t.py + tileHeight) };
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return new MapTile[0];
|
return new MapTile[0];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package org.dynmap.kzedmap;
|
package org.dynmap.kzedmap;
|
||||||
|
|
||||||
|
|
||||||
public interface MapTileRenderer {
|
public interface MapTileRenderer {
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
boolean render(KzedMapTile tile, String path);
|
boolean render(KzedMapTile tile, String path);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,10 @@ public class ZoomedTileRenderer {
|
||||||
int ox = 0;
|
int ox = 0;
|
||||||
int oy = 0;
|
int oy = 0;
|
||||||
|
|
||||||
if(zpx != px) ox = scw;
|
if (zpx != px)
|
||||||
if(zpy != py) oy = sch;
|
ox = scw;
|
||||||
|
if (zpy != py)
|
||||||
|
oy = sch;
|
||||||
|
|
||||||
/* blit scaled rendered tile onto zoom-out tile */
|
/* blit scaled rendered tile onto zoom-out tile */
|
||||||
// WritableRaster zr = zIm.getRaster();
|
// WritableRaster zr = zIm.getRaster();
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,7 @@ public class WebServer extends Thread {
|
||||||
private PlayerList playerList;
|
private PlayerList playerList;
|
||||||
private ConfigurationNode configuration;
|
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.mgr = mgr;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.playerList = playerList;
|
this.playerList = playerList;
|
||||||
|
|
@ -38,22 +37,22 @@ public class WebServer extends Thread {
|
||||||
String bindAddress = configuration.getString("webserver-bindaddress", "0.0.0.0");
|
String bindAddress = configuration.getString("webserver-bindaddress", "0.0.0.0");
|
||||||
int port = configuration.getInt("webserver-port", 8123);
|
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;
|
running = true;
|
||||||
start();
|
start();
|
||||||
log.info("Dynmap WebServer started on " + bindAddress + ":" + port);
|
log.info("Dynmap WebServer started on " + bindAddress + ":" + port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
while (running) {
|
while (running) {
|
||||||
try {
|
try {
|
||||||
Socket socket = sock.accept();
|
Socket socket = sock.accept();
|
||||||
WebServerRequest requestThread = new WebServerRequest(socket, mgr, world, playerList, configuration, debugger);
|
WebServerRequest requestThread = new WebServerRequest(socket, mgr, world, playerList, configuration, debugger);
|
||||||
requestThread.start();
|
requestThread.start();
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
log.info("map WebServer.run() stops with IOException");
|
log.info("map WebServer.run() stops with IOException");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -64,8 +63,7 @@ public class WebServer extends Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown()
|
public void shutdown() {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
if (sock != null) {
|
if (sock != null) {
|
||||||
sock.close();
|
sock.close();
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,7 @@ public class WebServerRequest extends Thread {
|
||||||
private PlayerList playerList;
|
private PlayerList playerList;
|
||||||
private ConfigurationNode configuration;
|
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.debugger = debugger;
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
this.mgr = mgr;
|
this.mgr = mgr;
|
||||||
|
|
@ -64,8 +63,7 @@ public class WebServerRequest extends Thread {
|
||||||
out.write(10);
|
out.write(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
BufferedOutputStream out = null;
|
BufferedOutputStream out = null;
|
||||||
try {
|
try {
|
||||||
|
|
@ -94,14 +92,32 @@ public class WebServerRequest extends Thread {
|
||||||
}
|
}
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
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());
|
debugger.error("Exception on WebRequest-thread: " + ex.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -122,8 +138,10 @@ public class WebServerRequest extends Thread {
|
||||||
sb.append("{");
|
sb.append("{");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (String key : m.keySet()) {
|
for (String key : m.keySet()) {
|
||||||
if (first) first = false;
|
if (first)
|
||||||
else sb.append(",");
|
first = false;
|
||||||
|
else
|
||||||
|
sb.append(",");
|
||||||
|
|
||||||
sb.append(stringifyJson(key));
|
sb.append(stringifyJson(key));
|
||||||
sb.append(": ");
|
sb.append(": ");
|
||||||
|
|
@ -213,7 +231,8 @@ public class WebServerRequest extends Thread {
|
||||||
public void writeFile(BufferedOutputStream out, String path, InputStream fileInput) throws IOException {
|
public void writeFile(BufferedOutputStream out, String path, InputStream fileInput) throws IOException {
|
||||||
int dotindex = path.lastIndexOf('.');
|
int dotindex = path.lastIndexOf('.');
|
||||||
String extension = null;
|
String extension = null;
|
||||||
if (dotindex > 0) extension = path.substring(dotindex);
|
if (dotindex > 0)
|
||||||
|
extension = path.substring(dotindex);
|
||||||
|
|
||||||
writeHttpHeader(out, 200, "OK");
|
writeHttpHeader(out, 200, "OK");
|
||||||
writeHeaderField(out, "Content-Type", getMimeTypeFromExtension(extension));
|
writeHeaderField(out, "Content-Type", getMimeTypeFromExtension(extension));
|
||||||
|
|
@ -233,12 +252,14 @@ public class WebServerRequest extends Thread {
|
||||||
|
|
||||||
public String getFilePath(String path) {
|
public String getFilePath(String path) {
|
||||||
int qmark = path.indexOf('?');
|
int qmark = path.indexOf('?');
|
||||||
if (qmark >= 0) path = path.substring(0, qmark);
|
if (qmark >= 0)
|
||||||
|
path = path.substring(0, qmark);
|
||||||
path = path.substring(1);
|
path = path.substring(1);
|
||||||
|
|
||||||
if (path.startsWith("/") || path.startsWith("."))
|
if (path.startsWith("/") || path.startsWith("."))
|
||||||
return null;
|
return null;
|
||||||
if (path.length() == 0) path = "index.html";
|
if (path.length() == 0)
|
||||||
|
path = "index.html";
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -279,9 +300,11 @@ public class WebServerRequest extends Thread {
|
||||||
mimes.put(".css", "text/css");
|
mimes.put(".css", "text/css");
|
||||||
mimes.put(".txt", "text/plain");
|
mimes.put(".txt", "text/plain");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMimeTypeFromExtension(String extension) {
|
public static String getMimeTypeFromExtension(String extension) {
|
||||||
String m = mimes.get(extension);
|
String m = mimes.get(extension);
|
||||||
if (m != null) return m;
|
if (m != null)
|
||||||
|
return m;
|
||||||
return "application/octet-steam";
|
return "application/octet-steam";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue