mirror of
https://github.com/encounter/dynmap.git
synced 2026-03-30 11:08:39 -07:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b2f6ae5132 | |||
| 5c209c2a5e | |||
| fb1b5df3d0 | |||
| 38ee8657e8 | |||
| 89c8d564a4 | |||
| b31bb14452 | |||
| 553eb7952d | |||
| 421b91058a | |||
| 100a03274c | |||
| d2b7169884 | |||
| 3e398e9124 | |||
| 7c257af454 | |||
| a937d13086 | |||
| d651d58d63 | |||
| 9a655676ab | |||
| debf5bcc57 | |||
| 2a79aea7bb | |||
| 883eba6890 | |||
| 226cc5f86c | |||
| bf0edea7e2 | |||
| 711341ec47 | |||
| 14a3d32205 | |||
| 9f555bd4bb | |||
| 902cc87458 | |||
| 9951baf8b5 | |||
| 335109d8c7 | |||
| 3940b91d0e | |||
| 4f138a56da | |||
| c8cf39a440 | |||
| 138aed8c33 | |||
| fde56275fe | |||
| 13e829cda0 |
@@ -15,6 +15,9 @@ webserver-bindaddress: 0.0.0.0
|
||||
# The TCP-port the webserver will listen on.
|
||||
webserver-port: 8123
|
||||
|
||||
disabledcommands:
|
||||
- fullrender
|
||||
|
||||
# The maptypes Dynmap will use to render.
|
||||
maps:
|
||||
- class: org.dynmap.kzedmap.KzedMap
|
||||
@@ -31,6 +34,7 @@ web:
|
||||
showchatballoons: true
|
||||
showplayerfacesonmap: true
|
||||
showplayerfacesinmenu: true
|
||||
focuschatballoons: false
|
||||
|
||||
# The name of the map shown when opening Dynmap's page (must be in menu).
|
||||
defaultmap: defaultmap
|
||||
|
||||
@@ -2,115 +2,110 @@ package org.dynmap;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Cache<K, V>
|
||||
{
|
||||
private final int size;
|
||||
private int len;
|
||||
public class Cache<K, V> {
|
||||
private final int size;
|
||||
private int len;
|
||||
|
||||
private CacheNode head;
|
||||
private CacheNode tail;
|
||||
private CacheNode head;
|
||||
private CacheNode tail;
|
||||
|
||||
private class CacheNode
|
||||
{
|
||||
public CacheNode prev;
|
||||
public CacheNode next;
|
||||
public K key;
|
||||
public V value;
|
||||
private class CacheNode {
|
||||
public CacheNode prev;
|
||||
public CacheNode next;
|
||||
public K key;
|
||||
public V value;
|
||||
|
||||
public CacheNode(K key, V value)
|
||||
{
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
prev = null;
|
||||
next = null;
|
||||
}
|
||||
public CacheNode(K key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
prev = null;
|
||||
next = null;
|
||||
}
|
||||
|
||||
public void unlink()
|
||||
{
|
||||
if(prev == null) {
|
||||
head = next;
|
||||
} else {
|
||||
prev.next = next;
|
||||
}
|
||||
public void unlink() {
|
||||
if (prev == null) {
|
||||
head = next;
|
||||
} else {
|
||||
prev.next = next;
|
||||
}
|
||||
|
||||
if(next == null) {
|
||||
tail = prev;
|
||||
} else {
|
||||
next.prev = prev;
|
||||
}
|
||||
if (next == null) {
|
||||
tail = prev;
|
||||
} else {
|
||||
next.prev = prev;
|
||||
}
|
||||
|
||||
prev = null;
|
||||
next = null;
|
||||
prev = null;
|
||||
next = null;
|
||||
|
||||
len --;
|
||||
}
|
||||
len--;
|
||||
}
|
||||
|
||||
public void append()
|
||||
{
|
||||
if(tail == null) {
|
||||
head = this;
|
||||
tail = this;
|
||||
} else {
|
||||
tail.next = this;
|
||||
prev = tail;
|
||||
tail = this;
|
||||
}
|
||||
public void append() {
|
||||
if (tail == null) {
|
||||
head = this;
|
||||
tail = this;
|
||||
} else {
|
||||
tail.next = this;
|
||||
prev = tail;
|
||||
tail = this;
|
||||
}
|
||||
|
||||
len ++;
|
||||
}
|
||||
}
|
||||
len++;
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<K, CacheNode> map;
|
||||
private HashMap<K, CacheNode> map;
|
||||
|
||||
public Cache(int size)
|
||||
{
|
||||
this.size = size;
|
||||
len = 0;
|
||||
public Cache(int size) {
|
||||
this.size = size;
|
||||
len = 0;
|
||||
|
||||
head = null;
|
||||
tail = null;
|
||||
head = null;
|
||||
tail = null;
|
||||
|
||||
map = new HashMap<K, CacheNode>();
|
||||
}
|
||||
map = new HashMap<K, CacheNode>();
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
CacheNode n = map.get(key);
|
||||
if(n == null) {
|
||||
V ret = null;
|
||||
/*
|
||||
* 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;
|
||||
|
||||
if(len >= size) {
|
||||
CacheNode first = head;
|
||||
first.unlink();
|
||||
map.remove(first.key);
|
||||
ret = first.value;
|
||||
}
|
||||
if (len >= size) {
|
||||
CacheNode first = head;
|
||||
first.unlink();
|
||||
map.remove(first.key);
|
||||
ret = first.value;
|
||||
}
|
||||
|
||||
CacheNode add = new CacheNode(key, value);
|
||||
add.append();
|
||||
map.put(key, add);
|
||||
CacheNode add = new CacheNode(key, value);
|
||||
add.append();
|
||||
map.put(key, add);
|
||||
|
||||
return ret;
|
||||
} else {
|
||||
n.unlink();
|
||||
V old = n.value;
|
||||
n.value = value;
|
||||
n.append();
|
||||
return old;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
n.unlink();
|
||||
V old = n.value;
|
||||
n.value = value;
|
||||
n.append();
|
||||
return old;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
package org.dynmap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
|
||||
public class ChatQueue {
|
||||
|
||||
public class ChatMessage
|
||||
{
|
||||
public long time;
|
||||
public String playerName;
|
||||
public String message;
|
||||
|
||||
public ChatMessage(PlayerChatEvent event)
|
||||
{
|
||||
time = System.currentTimeMillis();
|
||||
playerName = event.getPlayer().getName();
|
||||
message = event.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/* a list of recent chat message */
|
||||
private LinkedList<ChatMessage> messageQueue;
|
||||
|
||||
/* remember up to this old chat messages (ms) */
|
||||
private static final int maxChatAge = 120000;
|
||||
|
||||
public ChatQueue() {
|
||||
messageQueue = new LinkedList<ChatMessage>();
|
||||
}
|
||||
|
||||
/* put a chat message in the queue */
|
||||
public void pushChatMessage(PlayerChatEvent event)
|
||||
{
|
||||
synchronized(MapManager.lock) {
|
||||
messageQueue.add(new ChatMessage(event));
|
||||
}
|
||||
}
|
||||
|
||||
public ChatMessage[] getChatMessages(long cutoff) {
|
||||
|
||||
ArrayList<ChatMessage> queue = new ArrayList<ChatMessage>();
|
||||
ArrayList<ChatMessage> updateList = new ArrayList<ChatMessage>();
|
||||
queue.addAll(messageQueue);
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long deadline = now - maxChatAge;
|
||||
|
||||
synchronized(MapManager.lock) {
|
||||
|
||||
for (ChatMessage message : queue)
|
||||
{
|
||||
if (message.time < deadline)
|
||||
{
|
||||
messageQueue.remove(message);
|
||||
}
|
||||
else if (message.time >= cutoff)
|
||||
{
|
||||
updateList.add(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
ChatMessage[] messages = new ChatMessage[updateList.size()];
|
||||
updateList.toArray(messages);
|
||||
return messages;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.dynmap;
|
||||
|
||||
public class Client {
|
||||
public static class Update {
|
||||
public long timestamp;
|
||||
public long servertime;
|
||||
public Player[] players;
|
||||
public Object[] updates;
|
||||
}
|
||||
|
||||
public static class Player {
|
||||
public String type = "player";
|
||||
public String name;
|
||||
public double x, y, z;
|
||||
|
||||
public Player(String name, double x, double y, double z) {
|
||||
this.name = name;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChatMessage {
|
||||
public String type = "chat";
|
||||
public String playerName;
|
||||
public String message;
|
||||
|
||||
public ChatMessage(String playerName, String message) {
|
||||
this.playerName = playerName;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Tile {
|
||||
public String type = "tile";
|
||||
public String name;
|
||||
|
||||
public Tile(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,22 +7,22 @@ import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class DynmapBlockListener extends BlockListener {
|
||||
private MapManager mgr;
|
||||
|
||||
public DynmapBlockListener(MapManager mgr) {
|
||||
this.mgr = mgr;
|
||||
}
|
||||
private MapManager mgr;
|
||||
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
Block blockPlaced = event.getBlockPlaced();
|
||||
mgr.touch(blockPlaced.getX(), blockPlaced.getY(), blockPlaced.getZ());
|
||||
}
|
||||
public DynmapBlockListener(MapManager mgr) {
|
||||
this.mgr = mgr;
|
||||
}
|
||||
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
if (event.getDamageLevel() == BlockDamageLevel.BROKEN) {
|
||||
Block blockBroken = event.getBlock();
|
||||
mgr.touch(blockBroken.getX(), blockBroken.getY(), blockBroken.getZ());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
Block blockPlaced = event.getBlockPlaced();
|
||||
mgr.touch(blockPlaced.getX(), blockPlaced.getY(), blockPlaced.getZ());
|
||||
}
|
||||
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
if (event.getDamageLevel() == BlockDamageLevel.BROKEN) {
|
||||
Block blockBroken = event.getBlock();
|
||||
mgr.touch(blockBroken.getX(), blockBroken.getY(), blockBroken.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.dynmap;
|
||||
|
||||
public class DynmapChunk {
|
||||
public int x, z;
|
||||
|
||||
public DynmapChunk(int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
@@ -3,49 +3,69 @@ package org.dynmap;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.util.config.ConfigurationNode;
|
||||
|
||||
public class DynmapPlayerListener extends PlayerListener {
|
||||
private MapManager mgr;
|
||||
private PlayerList playerList;
|
||||
|
||||
public DynmapPlayerListener(MapManager mgr, PlayerList playerList) {
|
||||
this.mgr = mgr;
|
||||
this.playerList = playerList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCommand(PlayerChatEvent event) {
|
||||
String[] split = event.getMessage().split(" ");
|
||||
private MapManager mgr;
|
||||
private PlayerList playerList;
|
||||
private ConfigurationNode configuration;
|
||||
|
||||
public DynmapPlayerListener(MapManager mgr, PlayerList playerList, ConfigurationNode configuration) {
|
||||
this.mgr = mgr;
|
||||
this.playerList = playerList;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCommand(PlayerChatEvent event) {
|
||||
String[] split = event.getMessage().split(" ");
|
||||
if (split[0].equalsIgnoreCase("/dynmap")) {
|
||||
if (split.length > 1) {
|
||||
if (split[1].equals("render")) {
|
||||
Player player = event.getPlayer();
|
||||
mgr.touch(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
|
||||
event.setCancelled(true);
|
||||
} else if (split[1].equals("hide")) {
|
||||
if (split.length == 2) {
|
||||
playerList.hide(event.getPlayer().getName());
|
||||
} 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++)
|
||||
playerList.show(split[i]);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (split.length > 1) {
|
||||
if (configuration.getProperty("disabledcommands") instanceof Iterable<?>) {
|
||||
for(String s : (Iterable<String>)configuration.getProperty("disabledcommands")) {
|
||||
if (split[1].equals(s)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (split[1].equals("render")) {
|
||||
Player player = event.getPlayer();
|
||||
mgr.touch(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
|
||||
event.setCancelled(true);
|
||||
} else if (split[1].equals("hide")) {
|
||||
if (split.length == 2) {
|
||||
playerList.hide(event.getPlayer().getName());
|
||||
} 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++) {
|
||||
playerList.show(split[i]);
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
} else if (split[1].equals("fullrender")) {
|
||||
Player player = event.getPlayer();
|
||||
mgr.renderFullWorld(player.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player sends a chat message
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*
|
||||
* @param event
|
||||
* Relevant event details
|
||||
*/
|
||||
public void onPlayerChat(PlayerChatEvent event)
|
||||
{
|
||||
mgr.addChatEvent(event);
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
mgr.updateQueue.pushUpdate(new Client.ChatMessage(event.getPlayer().getName(), event.getMessage()));
|
||||
}
|
||||
}
|
||||
@@ -1,101 +1,114 @@
|
||||
package org.dynmap;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.io.File;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.event.*;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.plugin.*;
|
||||
import org.bukkit.plugin.java.*;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
import org.dynmap.debug.BukkitPlayerDebugger;
|
||||
import org.dynmap.web.WebServer;
|
||||
import org.dynmap.web.HttpServer;
|
||||
import org.dynmap.web.handlers.ClientConfigurationHandler;
|
||||
import org.dynmap.web.handlers.ClientUpdateHandler;
|
||||
import org.dynmap.web.handlers.FilesystemHandler;
|
||||
|
||||
public class DynmapPlugin extends JavaPlugin {
|
||||
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private WebServer webServer = null;
|
||||
private MapManager mapManager = null;
|
||||
private PlayerList playerList;
|
||||
|
||||
private BukkitPlayerDebugger debugger = new BukkitPlayerDebugger(this);
|
||||
|
||||
public static File dataRoot;
|
||||
|
||||
public DynmapPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
|
||||
super(pluginLoader, instance, desc, folder, plugin, cLoader);
|
||||
dataRoot = folder;
|
||||
}
|
||||
private HttpServer webServer = null;
|
||||
private MapManager mapManager = null;
|
||||
private PlayerList playerList;
|
||||
private Configuration configuration;
|
||||
|
||||
public World getWorld() {
|
||||
return getServer().getWorlds()[0];
|
||||
}
|
||||
|
||||
public MapManager getMapManager() {
|
||||
return mapManager;
|
||||
}
|
||||
|
||||
public WebServer getWebServer() {
|
||||
return webServer;
|
||||
}
|
||||
private BukkitPlayerDebugger debugger = new BukkitPlayerDebugger(this);
|
||||
|
||||
public void onEnable() {
|
||||
Configuration configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt"));
|
||||
configuration.load();
|
||||
|
||||
debugger.enable();
|
||||
playerList = new PlayerList(getServer());
|
||||
playerList.load();
|
||||
|
||||
mapManager = new MapManager(getWorld(), debugger, configuration);
|
||||
mapManager.startManager();
|
||||
public static File dataRoot;
|
||||
|
||||
try {
|
||||
webServer = new WebServer(mapManager, getServer(), playerList, debugger, configuration);
|
||||
} catch(IOException e) {
|
||||
log.info("position failed to start WebServer (IOException)");
|
||||
}
|
||||
|
||||
registerEvents();
|
||||
}
|
||||
public DynmapPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
|
||||
super(pluginLoader, instance, desc, folder, plugin, cLoader);
|
||||
dataRoot = folder;
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
mapManager.stopManager();
|
||||
public World getWorld() {
|
||||
return getServer().getWorlds().get(0);
|
||||
}
|
||||
|
||||
if(webServer != null) {
|
||||
webServer.shutdown();
|
||||
webServer = null;
|
||||
}
|
||||
debugger.disable();
|
||||
}
|
||||
public MapManager getMapManager() {
|
||||
return mapManager;
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
BlockListener blockListener = new DynmapBlockListener(mapManager);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this);
|
||||
|
||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, new DynmapPlayerListener(mapManager, playerList), Priority.Normal, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, new DynmapPlayerListener(mapManager, playerList), Priority.Normal, this);
|
||||
//getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DESTROYED, listener, Priority.Normal, this);
|
||||
/* etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this, PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this, PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener(PluginLoader.Hook.LOGIN, listener, this, PluginListener.Priority.MEDIUM);
|
||||
public HttpServer getWebServer() {
|
||||
return webServer;
|
||||
}
|
||||
|
||||
etc.getInstance().addCommand("/map_wait", " [wait] - set wait between tile renders (ms)");
|
||||
etc.getInstance().addCommand("/map_stat", " - query number of tiles in render queue");
|
||||
etc.getInstance().addCommand("/map_regen", " - regenerate entire map");
|
||||
etc.getInstance().addCommand("/map_debug", " - send map debugging messages");
|
||||
etc.getInstance().addCommand("/map_nodebug", " - disable map debugging messages");
|
||||
etc.getInstance().addCommand("/addsign", " [name] - adds a named sign to the map");
|
||||
etc.getInstance().addCommand("/removesign", " [name] - removes a named sign to the map");
|
||||
etc.getInstance().addCommand("/listsigns", " - list all named signs");
|
||||
etc.getInstance().addCommand("/tpsign", " [name] - teleport to a named sign");
|
||||
*/
|
||||
|
||||
}
|
||||
public void onEnable() {
|
||||
configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt"));
|
||||
configuration.load();
|
||||
|
||||
debugger.enable();
|
||||
playerList = new PlayerList(getServer());
|
||||
playerList.load();
|
||||
|
||||
mapManager = new MapManager(getWorld(), debugger, configuration);
|
||||
mapManager.startManager();
|
||||
|
||||
InetAddress bindAddress;
|
||||
{
|
||||
String address = configuration.getString("webserver-bindaddress", "0.0.0.0");
|
||||
try {
|
||||
bindAddress = address.equals("0.0.0.0")
|
||||
? null
|
||||
: InetAddress.getByName(address);
|
||||
} catch (UnknownHostException e) {
|
||||
bindAddress = null;
|
||||
}
|
||||
}
|
||||
int port = configuration.getInt("webserver-port", 8123);
|
||||
|
||||
webServer = new HttpServer(bindAddress, port);
|
||||
webServer.handlers.put("/", new FilesystemHandler(mapManager.webDirectory));
|
||||
webServer.handlers.put("/tiles/", new FilesystemHandler(mapManager.tileDirectory));
|
||||
webServer.handlers.put("/up/", new ClientUpdateHandler(mapManager, playerList, getWorld()));
|
||||
webServer.handlers.put("/up/configuration", new ClientConfigurationHandler((Map<?, ?>) configuration.getProperty("web")));
|
||||
|
||||
try {
|
||||
webServer.startServer();
|
||||
} catch (IOException e) {
|
||||
log.severe("Failed to start WebServer on " + bindAddress + ":" + port + "!");
|
||||
}
|
||||
|
||||
registerEvents();
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
mapManager.stopManager();
|
||||
|
||||
if (webServer != null) {
|
||||
webServer.shutdown();
|
||||
webServer = null;
|
||||
}
|
||||
debugger.disable();
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
BlockListener blockListener = new DynmapBlockListener(mapManager);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this);
|
||||
|
||||
PlayerListener playerListener = new DynmapPlayerListener(mapManager, playerList, configuration);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.dynmap;
|
||||
|
||||
public class MapLocation {
|
||||
public float x;
|
||||
public float y;
|
||||
public float x;
|
||||
public float y;
|
||||
}
|
||||
|
||||
@@ -3,182 +3,236 @@ package org.dynmap;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.util.config.ConfigurationNode;
|
||||
import org.dynmap.debug.Debugger;
|
||||
|
||||
public class MapManager extends Thread {
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private World world;
|
||||
private Debugger debugger;
|
||||
private MapType[] maps;
|
||||
public StaleQueue staleQueue;
|
||||
public ChatQueue chatQueue;
|
||||
public PlayerList playerList;
|
||||
private World world;
|
||||
private Debugger debugger;
|
||||
private MapType[] maps;
|
||||
public StaleQueue staleQueue;
|
||||
public UpdateQueue updateQueue;
|
||||
public PlayerList playerList;
|
||||
|
||||
/* lock for our data structures */
|
||||
public static final Object lock = new Object();
|
||||
/* lock for our data structures */
|
||||
public static final Object lock = new Object();
|
||||
|
||||
/* whether the worker thread should be running now */
|
||||
private boolean running = false;
|
||||
/* whether the worker thread should be running now */
|
||||
private boolean running = false;
|
||||
|
||||
/* path to image tile directory */
|
||||
public File tileDirectory;
|
||||
|
||||
/* web files location */
|
||||
public File webDirectory;
|
||||
|
||||
/* bind web server to ip-address */
|
||||
public String bindaddress = "0.0.0.0";
|
||||
|
||||
/* port to run web server on */
|
||||
public int serverport = 8123;
|
||||
|
||||
/* time to pause between rendering tiles (ms) */
|
||||
public int renderWait = 500;
|
||||
|
||||
public void debug(String msg)
|
||||
{
|
||||
debugger.debug(msg);
|
||||
}
|
||||
|
||||
private static File combinePaths(File parent, String path) { return combinePaths(parent, new File(path)); }
|
||||
|
||||
private static File combinePaths(File parent, File path) {
|
||||
if (path.isAbsolute()) return path;
|
||||
return new File(parent, path.getPath());
|
||||
}
|
||||
|
||||
public MapManager(World world, Debugger debugger, ConfigurationNode configuration)
|
||||
{
|
||||
this.world = world;
|
||||
this.debugger = debugger;
|
||||
this.staleQueue = new StaleQueue();
|
||||
this.chatQueue = new ChatQueue();
|
||||
|
||||
tileDirectory = combinePaths(DynmapPlugin.dataRoot, configuration.getString("tilespath", "web/tiles"));
|
||||
webDirectory = combinePaths(DynmapPlugin.dataRoot, configuration.getString("webpath", "web"));
|
||||
renderWait = (int)(configuration.getDouble("renderinterval", 0.5) * 1000);
|
||||
|
||||
if (!tileDirectory.isDirectory())
|
||||
tileDirectory.mkdirs();
|
||||
|
||||
maps = loadMapTypes(configuration);
|
||||
}
|
||||
|
||||
private MapType[] loadMapTypes(ConfigurationNode configuration) {
|
||||
List<?> configuredMaps = (List<?>)configuration.getProperty("maps");
|
||||
ArrayList<MapType> mapTypes = new ArrayList<MapType>();
|
||||
for(Object configuredMapObj : configuredMaps) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> configuredMap = (Map<String, Object>)configuredMapObj;
|
||||
String typeName = (String)configuredMap.get("class");
|
||||
log.info("Loading map '" + typeName.toString() + "'...");
|
||||
Class<?> mapTypeClass = Class.forName(typeName);
|
||||
Constructor<?> constructor = mapTypeClass.getConstructor(MapManager.class, World.class, Debugger.class, Map.class);
|
||||
MapType mapType = (MapType)constructor.newInstance(this, world, debugger, configuredMap);
|
||||
mapTypes.add(mapType);
|
||||
} catch (Exception e) {
|
||||
debugger.error("Error loading map", e);
|
||||
}
|
||||
}
|
||||
MapType[] result = new MapType[mapTypes.size()];
|
||||
mapTypes.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* initialize and start map manager */
|
||||
public void startManager()
|
||||
{
|
||||
synchronized(lock) {
|
||||
running = true;
|
||||
this.start();
|
||||
try {
|
||||
this.setPriority(MIN_PRIORITY);
|
||||
log.info("Set minimum priority for worker thread");
|
||||
} catch(SecurityException e) {
|
||||
log.info("Failed to set minimum priority for worker thread!");
|
||||
}
|
||||
}
|
||||
}
|
||||
/* path to image tile directory */
|
||||
public File tileDirectory;
|
||||
|
||||
/* stop map manager */
|
||||
public void stopManager()
|
||||
{
|
||||
synchronized(lock) {
|
||||
if(!running)
|
||||
return;
|
||||
|
||||
log.info("Stopping map renderer...");
|
||||
running = false;
|
||||
|
||||
try {
|
||||
this.join();
|
||||
} catch(InterruptedException e) {
|
||||
log.info("Waiting for map renderer to stop is interrupted");
|
||||
}
|
||||
}
|
||||
}
|
||||
/* web files location */
|
||||
public File webDirectory;
|
||||
|
||||
/* the worker/renderer thread */
|
||||
public void run()
|
||||
{
|
||||
try {
|
||||
log.info("Map renderer has started.");
|
||||
|
||||
while(running) {
|
||||
boolean found = false;
|
||||
|
||||
MapTile t = staleQueue.popStaleTile();
|
||||
if(t != null) {
|
||||
debugger.debug("rendering tile " + t + "...");
|
||||
t.getMap().render(t);
|
||||
|
||||
staleQueue.onTileUpdated(t);
|
||||
|
||||
try {
|
||||
Thread.sleep(renderWait);
|
||||
} catch(InterruptedException e) {
|
||||
}
|
||||
|
||||
found = true;
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch(InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Map renderer has stopped.");
|
||||
} catch(Exception ex) {
|
||||
debugger.error("Exception on rendering-thread: " + ex.toString());
|
||||
}
|
||||
}
|
||||
/* bind web server to ip-address */
|
||||
public String bindaddress = "0.0.0.0";
|
||||
|
||||
public void touch(int x, int y, int z) {
|
||||
for (int i = 0; i < maps.length; i++) {
|
||||
maps[i].touch(new Location(world, x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
public void invalidateTile(MapTile tile) {
|
||||
debugger.debug("invalidating tile " + tile.getName());
|
||||
staleQueue.pushStaleTile(tile);
|
||||
}
|
||||
|
||||
public void addChatEvent(PlayerChatEvent event)
|
||||
{
|
||||
chatQueue.pushChatMessage(event);
|
||||
}
|
||||
/* port to run web server on */
|
||||
public int serverport = 8123;
|
||||
|
||||
/* time to pause between rendering tiles (ms) */
|
||||
public int renderWait = 500;
|
||||
|
||||
public boolean loadChunks = true;
|
||||
|
||||
public void debug(String msg) {
|
||||
debugger.debug(msg);
|
||||
}
|
||||
|
||||
private static File combinePaths(File parent, String path) {
|
||||
return combinePaths(parent, new File(path));
|
||||
}
|
||||
|
||||
private static File combinePaths(File parent, File path) {
|
||||
if (path.isAbsolute())
|
||||
return path;
|
||||
return new File(parent, path.getPath());
|
||||
}
|
||||
|
||||
public MapManager(World world, Debugger debugger, ConfigurationNode configuration) {
|
||||
this.world = world;
|
||||
this.debugger = debugger;
|
||||
this.staleQueue = new StaleQueue();
|
||||
this.updateQueue = new UpdateQueue();
|
||||
|
||||
tileDirectory = combinePaths(DynmapPlugin.dataRoot, configuration.getString("tilespath", "web/tiles"));
|
||||
webDirectory = combinePaths(DynmapPlugin.dataRoot, configuration.getString("webpath", "web"));
|
||||
renderWait = (int) (configuration.getDouble("renderinterval", 0.5) * 1000);
|
||||
loadChunks = configuration.getBoolean("loadchunks", true);
|
||||
|
||||
if (!tileDirectory.isDirectory())
|
||||
tileDirectory.mkdirs();
|
||||
|
||||
maps = loadMapTypes(configuration);
|
||||
}
|
||||
|
||||
void renderFullWorld(Location l) {
|
||||
debugger.debug("Full render starting...");
|
||||
for (MapType map : maps) {
|
||||
int requiredChunkCount = 200;
|
||||
HashSet<MapTile> found = new HashSet<MapTile>();
|
||||
HashSet<MapTile> rendered = new HashSet<MapTile>();
|
||||
LinkedList<MapTile> renderQueue = new LinkedList<MapTile>();
|
||||
LinkedList<DynmapChunk> loadedChunks = new LinkedList<DynmapChunk>();
|
||||
|
||||
for (MapTile tile : map.getTiles(l)) {
|
||||
if (!found.contains(tile)) {
|
||||
found.add(tile);
|
||||
renderQueue.add(tile);
|
||||
}
|
||||
}
|
||||
while (!renderQueue.isEmpty()) {
|
||||
MapTile tile = renderQueue.pollFirst();
|
||||
|
||||
DynmapChunk[] requiredChunks = tile.getMap().getRequiredChunks(tile);
|
||||
|
||||
if (requiredChunks.length > requiredChunkCount)
|
||||
requiredChunkCount = requiredChunks.length;
|
||||
// Unload old chunks.
|
||||
while (loadedChunks.size() >= requiredChunkCount - requiredChunks.length) {
|
||||
DynmapChunk c = loadedChunks.pollFirst();
|
||||
world.unloadChunk(c.x, c.z, false, true);
|
||||
}
|
||||
|
||||
// Load the required chunks.
|
||||
for (DynmapChunk chunk : requiredChunks) {
|
||||
boolean wasLoaded = world.isChunkLoaded(chunk.x, chunk.z);
|
||||
world.loadChunk(chunk.x, chunk.z, false);
|
||||
if (!wasLoaded)
|
||||
loadedChunks.add(chunk);
|
||||
}
|
||||
|
||||
if (map.render(tile)) {
|
||||
found.remove(tile);
|
||||
rendered.add(tile);
|
||||
updateQueue.pushUpdate(new Client.Tile(tile.getName()));
|
||||
for (MapTile adjTile : map.getAdjecentTiles(tile)) {
|
||||
if (!found.contains(adjTile) && !rendered.contains(adjTile)) {
|
||||
found.add(adjTile);
|
||||
renderQueue.add(adjTile);
|
||||
}
|
||||
}
|
||||
}
|
||||
found.remove(tile);
|
||||
System.gc();
|
||||
}
|
||||
|
||||
// Unload remaining chunks to clean-up.
|
||||
while (!loadedChunks.isEmpty()) {
|
||||
DynmapChunk c = loadedChunks.pollFirst();
|
||||
world.unloadChunk(c.x, c.z, false, true);
|
||||
}
|
||||
}
|
||||
debugger.debug("Full render finished.");
|
||||
}
|
||||
|
||||
private MapType[] loadMapTypes(ConfigurationNode configuration) {
|
||||
List<?> configuredMaps = (List<?>) configuration.getProperty("maps");
|
||||
ArrayList<MapType> mapTypes = new ArrayList<MapType>();
|
||||
for (Object configuredMapObj : configuredMaps) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> configuredMap = (Map<String, Object>) configuredMapObj;
|
||||
String typeName = (String) configuredMap.get("class");
|
||||
log.info("Loading map '" + typeName.toString() + "'...");
|
||||
Class<?> mapTypeClass = Class.forName(typeName);
|
||||
Constructor<?> constructor = mapTypeClass.getConstructor(MapManager.class, World.class, Debugger.class, Map.class);
|
||||
MapType mapType = (MapType) constructor.newInstance(this, world, debugger, configuredMap);
|
||||
mapTypes.add(mapType);
|
||||
} catch (Exception e) {
|
||||
debugger.error("Error loading map", e);
|
||||
}
|
||||
}
|
||||
MapType[] result = new MapType[mapTypes.size()];
|
||||
mapTypes.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* initialize and start map manager */
|
||||
public void startManager() {
|
||||
synchronized (lock) {
|
||||
running = true;
|
||||
this.start();
|
||||
try {
|
||||
this.setPriority(MIN_PRIORITY);
|
||||
log.info("Set minimum priority for worker thread");
|
||||
} catch (SecurityException e) {
|
||||
log.info("Failed to set minimum priority for worker thread!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* stop map manager */
|
||||
public void stopManager() {
|
||||
synchronized (lock) {
|
||||
if (!running)
|
||||
return;
|
||||
|
||||
log.info("Stopping map renderer...");
|
||||
running = false;
|
||||
|
||||
try {
|
||||
this.join();
|
||||
} catch (InterruptedException e) {
|
||||
log.info("Waiting for map renderer to stop is interrupted");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* the worker/renderer thread */
|
||||
public void run() {
|
||||
try {
|
||||
log.info("Map renderer has started.");
|
||||
|
||||
while (running) {
|
||||
MapTile t = staleQueue.popStaleTile();
|
||||
if (t != null) {
|
||||
debugger.debug("Rendering tile " + t + "...");
|
||||
boolean isNonEmptyTile = t.getMap().render(t);
|
||||
updateQueue.pushUpdate(new Client.Tile(t.getName()));
|
||||
|
||||
try {
|
||||
Thread.sleep(renderWait);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Map renderer has stopped.");
|
||||
} catch (Exception ex) {
|
||||
debugger.error("Exception on rendering-thread: " + ex.toString());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void touch(int x, int y, int z) {
|
||||
for (int i = 0; i < maps.length; i++) {
|
||||
MapTile[] tiles = maps[i].getTiles(new Location(world, x, y, z));
|
||||
for (int j = 0; j < tiles.length; j++) {
|
||||
invalidateTile(tiles[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void invalidateTile(MapTile tile) {
|
||||
debugger.debug("Invalidating tile " + tile.getName());
|
||||
staleQueue.pushStaleTile(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package org.dynmap;
|
||||
|
||||
public abstract class MapTile {
|
||||
private MapType map;
|
||||
public MapType getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public MapTile(MapType map) {
|
||||
this.map = map;
|
||||
}
|
||||
private MapType map;
|
||||
|
||||
public MapType getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public MapTile(MapType map) {
|
||||
this.map = map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,31 +5,37 @@ import org.bukkit.World;
|
||||
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;
|
||||
}
|
||||
|
||||
public MapType(MapManager manager, World world, Debugger debugger) {
|
||||
this.manager = manager;
|
||||
this.world = world;
|
||||
this.debugger = debugger;
|
||||
}
|
||||
|
||||
public void invalidateTile(MapTile tile) {
|
||||
manager.invalidateTile(tile);
|
||||
}
|
||||
|
||||
public abstract void touch(Location l);
|
||||
public abstract void render(MapTile tile);
|
||||
private MapManager manager;
|
||||
|
||||
public MapManager getMapManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
private World world;
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
private Debugger debugger;
|
||||
|
||||
public Debugger getDebugger() {
|
||||
return debugger;
|
||||
}
|
||||
|
||||
public MapType(MapManager manager, World world, Debugger debugger) {
|
||||
this.manager = manager;
|
||||
this.world = world;
|
||||
this.debugger = debugger;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -14,68 +14,71 @@ import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerList {
|
||||
private Server server;
|
||||
private HashSet<String> hiddenPlayerNames = new HashSet<String>();
|
||||
private File hiddenPlayersFile = new File(DynmapPlugin.dataRoot, "hiddenplayers.txt");
|
||||
|
||||
public PlayerList(Server server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
OutputStream stream;
|
||||
try {
|
||||
stream = new FileOutputStream(hiddenPlayersFile);
|
||||
OutputStreamWriter writer = new OutputStreamWriter(stream);
|
||||
for(String player : hiddenPlayerNames) {
|
||||
writer.write(player);
|
||||
writer.write("\n");
|
||||
}
|
||||
writer.close();
|
||||
stream.close();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
try {
|
||||
Scanner scanner = new Scanner(hiddenPlayersFile);
|
||||
while(scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
hiddenPlayerNames.add(line);
|
||||
}
|
||||
scanner.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void hide(String playerName) {
|
||||
hiddenPlayerNames.add(playerName);
|
||||
save();
|
||||
}
|
||||
|
||||
public void show(String playerName) {
|
||||
hiddenPlayerNames.remove(playerName);
|
||||
save();
|
||||
}
|
||||
|
||||
public void setVisible(String playerName, boolean visible) {
|
||||
if (visible) show(playerName); else hide(playerName);
|
||||
}
|
||||
|
||||
public Player[] getVisiblePlayers() {
|
||||
ArrayList<Player> visiblePlayers = new ArrayList<Player>();
|
||||
Player[] onlinePlayers = server.getOnlinePlayers();
|
||||
for(int i=0;i<onlinePlayers.length;i++){
|
||||
Player p = onlinePlayers[i];
|
||||
if (!hiddenPlayerNames.contains(p.getName())) {
|
||||
visiblePlayers.add(p);
|
||||
}
|
||||
}
|
||||
Player[] result = new Player[visiblePlayers.size()];
|
||||
visiblePlayers.toArray(result);
|
||||
return result;
|
||||
}
|
||||
private Server server;
|
||||
private HashSet<String> hiddenPlayerNames = new HashSet<String>();
|
||||
private File hiddenPlayersFile = new File(DynmapPlugin.dataRoot, "hiddenplayers.txt");
|
||||
|
||||
public PlayerList(Server server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
OutputStream stream;
|
||||
try {
|
||||
stream = new FileOutputStream(hiddenPlayersFile);
|
||||
OutputStreamWriter writer = new OutputStreamWriter(stream);
|
||||
for (String player : hiddenPlayerNames) {
|
||||
writer.write(player);
|
||||
writer.write("\n");
|
||||
}
|
||||
writer.close();
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
try {
|
||||
Scanner scanner = new Scanner(hiddenPlayersFile);
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
hiddenPlayerNames.add(line);
|
||||
}
|
||||
scanner.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void hide(String playerName) {
|
||||
hiddenPlayerNames.add(playerName);
|
||||
save();
|
||||
}
|
||||
|
||||
public void show(String playerName) {
|
||||
hiddenPlayerNames.remove(playerName);
|
||||
save();
|
||||
}
|
||||
|
||||
public void setVisible(String playerName, boolean visible) {
|
||||
if (visible)
|
||||
show(playerName);
|
||||
else
|
||||
hide(playerName);
|
||||
}
|
||||
|
||||
public Player[] getVisiblePlayers() {
|
||||
ArrayList<Player> visiblePlayers = new ArrayList<Player>();
|
||||
Player[] onlinePlayers = server.getOnlinePlayers();
|
||||
for (int i = 0; i < onlinePlayers.length; i++) {
|
||||
Player p = onlinePlayers[i];
|
||||
if (!hiddenPlayerNames.contains(p.getName())) {
|
||||
visiblePlayers.add(p);
|
||||
}
|
||||
}
|
||||
Player[] result = new Player[visiblePlayers.size()];
|
||||
visiblePlayers.toArray(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,96 +1,50 @@
|
||||
package org.dynmap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ListIterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
public class StaleQueue {
|
||||
/* a list of MapTiles to be updated */
|
||||
private LinkedList<MapTile> staleTilesQueue;
|
||||
private Set<MapTile> staleTiles;
|
||||
/* a list of MapTiles to be updated */
|
||||
private LinkedList<MapTile> staleTilesQueue;
|
||||
private Set<MapTile> staleTiles;
|
||||
|
||||
/* this list stores the tile updates */
|
||||
public LinkedList<TileUpdate> tileUpdates = null;
|
||||
|
||||
/* remember up to this old tile updates (ms) */
|
||||
private static final int maxTileAge = 60000;
|
||||
|
||||
public StaleQueue() {
|
||||
staleTilesQueue = new LinkedList<MapTile>();
|
||||
staleTiles = new HashSet<MapTile>();
|
||||
tileUpdates = new LinkedList<TileUpdate>();
|
||||
}
|
||||
|
||||
/* put a MapTile that needs to be regenerated on the list of stale tiles */
|
||||
public boolean pushStaleTile(MapTile m)
|
||||
{
|
||||
synchronized(MapManager.lock) {
|
||||
if(staleTiles.add(m)) {
|
||||
staleTilesQueue.addLast(m);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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();
|
||||
if(!staleTiles.remove(t)) {
|
||||
// This should never happen.
|
||||
}
|
||||
return t;
|
||||
} catch(NoSuchElementException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onTileUpdated(MapTile t) {
|
||||
long now = System.currentTimeMillis();
|
||||
long deadline = now - maxTileAge;
|
||||
synchronized(MapManager.lock) {
|
||||
ListIterator<TileUpdate> it = tileUpdates.listIterator(0);
|
||||
while(it.hasNext()) {
|
||||
TileUpdate tu = it.next();
|
||||
if(tu.at < deadline || tu.tile == t)
|
||||
it.remove();
|
||||
}
|
||||
tileUpdates.addLast(new TileUpdate(now, t));
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<TileUpdate> tmpupdates = new ArrayList<TileUpdate>();
|
||||
public TileUpdate[] getTileUpdates(long cutoff) {
|
||||
long now = System.currentTimeMillis();
|
||||
long deadline = now - maxTileAge;
|
||||
TileUpdate[] updates;
|
||||
synchronized(MapManager.lock) {
|
||||
tmpupdates.clear();
|
||||
Iterator<TileUpdate> it = tileUpdates.descendingIterator();
|
||||
while(it.hasNext()) {
|
||||
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).
|
||||
it.remove();
|
||||
break;
|
||||
} else { // Tile is old, but not old enough for removal.
|
||||
break;
|
||||
}
|
||||
}
|
||||
updates = new TileUpdate[tmpupdates.size()];
|
||||
tmpupdates.toArray(updates);
|
||||
}
|
||||
return updates;
|
||||
}
|
||||
public StaleQueue() {
|
||||
staleTilesQueue = new LinkedList<MapTile>();
|
||||
staleTiles = new HashSet<MapTile>();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return staleTilesQueue.size();
|
||||
}
|
||||
|
||||
/* put a MapTile that needs to be regenerated on the list of stale tiles */
|
||||
public boolean pushStaleTile(MapTile m) {
|
||||
synchronized (MapManager.lock) {
|
||||
if (staleTiles.add(m)) {
|
||||
staleTilesQueue.addLast(m);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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();
|
||||
if (!staleTiles.remove(t)) {
|
||||
// This should never happen.
|
||||
}
|
||||
return t;
|
||||
} catch (NoSuchElementException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.dynmap;
|
||||
|
||||
/* this class stores a tile update */
|
||||
|
||||
public class TileUpdate {
|
||||
public long at;
|
||||
public MapTile tile;
|
||||
|
||||
public TileUpdate(long at, MapTile tile)
|
||||
{
|
||||
this.at = at;
|
||||
this.tile = tile;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package org.dynmap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class UpdateQueue {
|
||||
public Object lock = new Object();
|
||||
private LinkedList<Update> updateQueue = new LinkedList<Update>();
|
||||
|
||||
private static final int maxUpdateAge = 120000;
|
||||
|
||||
public void pushUpdate(Object obj) {
|
||||
long now = System.currentTimeMillis();
|
||||
long deadline = now - maxUpdateAge;
|
||||
synchronized (lock) {
|
||||
ListIterator<Update> i = updateQueue.listIterator(0);
|
||||
while (i.hasNext()) {
|
||||
Update u = i.next();
|
||||
if (u.time < deadline || u.obj == obj)
|
||||
i.remove();
|
||||
}
|
||||
updateQueue.addLast(new Update(now, obj));
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<Object> tmpupdates = new ArrayList<Object>();
|
||||
|
||||
public Object[] getUpdatedObjects(long since) {
|
||||
long now = System.currentTimeMillis();
|
||||
long deadline = now - maxUpdateAge;
|
||||
Object[] updates;
|
||||
synchronized (lock) {
|
||||
tmpupdates.clear();
|
||||
Iterator<Update> it = updateQueue.descendingIterator();
|
||||
while (it.hasNext()) {
|
||||
Update u = it.next();
|
||||
if (u.time >= since) {
|
||||
// Tile is new.
|
||||
tmpupdates.add(u.obj);
|
||||
} else if (u.time < deadline) {
|
||||
// Tile is too old, removing this one (will eventually decrease).
|
||||
it.remove();
|
||||
break;
|
||||
} else {
|
||||
// Tile is old, but not old enough for removal.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Reverse output.
|
||||
updates = new Object[tmpupdates.size()];
|
||||
for (int i = 0; i < updates.length; i++) {
|
||||
updates[i] = tmpupdates.get(updates.length-1-i);
|
||||
}
|
||||
}
|
||||
return updates;
|
||||
}
|
||||
|
||||
public class Update {
|
||||
public long time;
|
||||
public Object obj;
|
||||
|
||||
public Update(long time, Object obj) {
|
||||
this.time = time;
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,85 +15,86 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class BukkitPlayerDebugger implements Debugger {
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private boolean isLogging = false;
|
||||
|
||||
private JavaPlugin plugin;
|
||||
private HashSet<Player> debugees = new HashSet<Player>();
|
||||
private String debugCommand;
|
||||
private String undebugCommand;
|
||||
private String prepend;
|
||||
|
||||
public BukkitPlayerDebugger(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
PluginDescriptionFile pdfFile = plugin.getDescription();
|
||||
debugCommand = "/debug_" + pdfFile.getName();
|
||||
undebugCommand = "/undebug_" + pdfFile.getName();
|
||||
prepend = pdfFile.getName() + ": ";
|
||||
}
|
||||
|
||||
public synchronized void enable() {
|
||||
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);
|
||||
}
|
||||
|
||||
public synchronized void disable() {
|
||||
clearDebugees();
|
||||
}
|
||||
|
||||
public synchronized void addDebugee(Player p) {
|
||||
debugees.add(p);
|
||||
}
|
||||
|
||||
public synchronized void removeDebugee(Player p) {
|
||||
debugees.remove(p);
|
||||
}
|
||||
|
||||
public synchronized void clearDebugees() {
|
||||
debugees.clear();
|
||||
}
|
||||
|
||||
public synchronized void sendToDebuggees(String message) {
|
||||
for (Player p : debugees) {
|
||||
p.sendMessage(prepend + message);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void debug(String message) {
|
||||
sendToDebuggees(message);
|
||||
if (isLogging) log.info(prepend + message);
|
||||
}
|
||||
|
||||
public synchronized void error(String message) {
|
||||
sendToDebuggees(prepend + ChatColor.RED + message);
|
||||
if (isLogging) log.log(Level.SEVERE, prepend + message);
|
||||
}
|
||||
|
||||
public synchronized void error(String message, Throwable thrown) {
|
||||
sendToDebuggees(prepend + ChatColor.RED + message);
|
||||
sendToDebuggees(thrown.toString());
|
||||
if (isLogging) log.log(Level.SEVERE, prepend + message);
|
||||
}
|
||||
|
||||
protected class CommandListener extends PlayerListener {
|
||||
@Override
|
||||
public void onPlayerCommand(PlayerChatEvent event) {
|
||||
String[] split = event.getMessage().split(" ");
|
||||
Player player = event.getPlayer();
|
||||
if (split[0].equalsIgnoreCase(debugCommand)) {
|
||||
addDebugee(player);
|
||||
event.setCancelled(true);
|
||||
} else if (split[0].equalsIgnoreCase(undebugCommand)) {
|
||||
removeDebugee(player);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerEvent event) {
|
||||
removeDebugee(event.getPlayer());
|
||||
}
|
||||
}
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private boolean isLogging = false;
|
||||
|
||||
private JavaPlugin plugin;
|
||||
private HashSet<Player> debugees = new HashSet<Player>();
|
||||
private String debugCommand;
|
||||
private String undebugCommand;
|
||||
private String prepend;
|
||||
|
||||
public BukkitPlayerDebugger(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
PluginDescriptionFile pdfFile = plugin.getDescription();
|
||||
debugCommand = "/debug_" + pdfFile.getName();
|
||||
undebugCommand = "/undebug_" + pdfFile.getName();
|
||||
prepend = pdfFile.getName() + ": ";
|
||||
}
|
||||
|
||||
public synchronized void enable() {
|
||||
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);
|
||||
}
|
||||
|
||||
public synchronized void disable() {
|
||||
clearDebugees();
|
||||
}
|
||||
|
||||
public synchronized void addDebugee(Player p) {
|
||||
debugees.add(p);
|
||||
}
|
||||
|
||||
public synchronized void removeDebugee(Player p) {
|
||||
debugees.remove(p);
|
||||
}
|
||||
|
||||
public synchronized void clearDebugees() {
|
||||
debugees.clear();
|
||||
}
|
||||
|
||||
public synchronized void sendToDebuggees(String message) {
|
||||
for (Player p : debugees) {
|
||||
p.sendMessage(prepend + message);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void debug(String message) {
|
||||
sendToDebuggees(message);
|
||||
if (isLogging)
|
||||
log.info(prepend + message);
|
||||
}
|
||||
|
||||
public synchronized void error(String message) {
|
||||
sendToDebuggees(prepend + ChatColor.RED + message);
|
||||
log.log(Level.SEVERE, prepend + message);
|
||||
}
|
||||
|
||||
public synchronized void error(String message, Throwable thrown) {
|
||||
sendToDebuggees(prepend + ChatColor.RED + message);
|
||||
sendToDebuggees(thrown.toString());
|
||||
log.log(Level.SEVERE, prepend + message);
|
||||
}
|
||||
|
||||
protected class CommandListener extends PlayerListener {
|
||||
@Override
|
||||
public void onPlayerCommand(PlayerChatEvent event) {
|
||||
String[] split = event.getMessage().split(" ");
|
||||
Player player = event.getPlayer();
|
||||
if (split[0].equalsIgnoreCase(debugCommand)) {
|
||||
addDebugee(player);
|
||||
event.setCancelled(true);
|
||||
} else if (split[0].equalsIgnoreCase(undebugCommand)) {
|
||||
removeDebugee(player);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerEvent event) {
|
||||
removeDebugee(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.dynmap.debug;
|
||||
|
||||
public interface Debugger {
|
||||
void debug(String message);
|
||||
void error(String message);
|
||||
void error(String message, Throwable thrown);
|
||||
void debug(String message);
|
||||
|
||||
void error(String message);
|
||||
|
||||
void error(String message, Throwable thrown);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package org.dynmap.debug;
|
||||
|
||||
public class NullDebugger implements Debugger {
|
||||
public void debug(String message) {
|
||||
}
|
||||
public static final NullDebugger instance = new NullDebugger();
|
||||
|
||||
public void error(String message) {
|
||||
}
|
||||
public void debug(String message) {
|
||||
}
|
||||
|
||||
public void error(String message, Throwable thrown) {
|
||||
}
|
||||
public void error(String message) {
|
||||
}
|
||||
|
||||
public void error(String message, Throwable thrown) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,94 +2,94 @@ package org.dynmap.kzedmap;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.dynmap.debug.Debugger;
|
||||
|
||||
public class CaveTileRenderer extends DefaultTileRenderer {
|
||||
|
||||
public CaveTileRenderer(Debugger debugger, Map<String, Object> configuration) {
|
||||
super(debugger, configuration);
|
||||
}
|
||||
public CaveTileRenderer(Debugger debugger, Map<String, Object> configuration) {
|
||||
super(debugger, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color scan(World world, int x, int y, int z, int seq)
|
||||
{
|
||||
boolean air = true;
|
||||
@Override
|
||||
protected Color scan(World world, int x, int y, int z, int seq) {
|
||||
boolean air = true;
|
||||
|
||||
for(;;) {
|
||||
if(y < 0)
|
||||
return Color.BLACK;
|
||||
for (;;) {
|
||||
if (y < 0)
|
||||
return translucent;
|
||||
|
||||
int id = world.getBlockTypeIdAt(x, y, z);
|
||||
int id = world.getBlockTypeIdAt(x, y, z);
|
||||
|
||||
switch(seq) {
|
||||
case 0:
|
||||
x--;
|
||||
break;
|
||||
case 1:
|
||||
y--;
|
||||
break;
|
||||
case 2:
|
||||
z++;
|
||||
break;
|
||||
case 3:
|
||||
y--;
|
||||
break;
|
||||
}
|
||||
switch (seq) {
|
||||
case 0:
|
||||
x--;
|
||||
break;
|
||||
case 1:
|
||||
y--;
|
||||
break;
|
||||
case 2:
|
||||
z++;
|
||||
break;
|
||||
case 3:
|
||||
y--;
|
||||
break;
|
||||
}
|
||||
|
||||
seq = (seq + 1) & 3;
|
||||
seq = (seq + 1) & 3;
|
||||
|
||||
switch(id) {
|
||||
case 20:
|
||||
case 18:
|
||||
case 17:
|
||||
case 78:
|
||||
case 79:
|
||||
id = 0;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
switch (id) {
|
||||
case 20:
|
||||
case 18:
|
||||
case 17:
|
||||
case 78:
|
||||
case 79:
|
||||
id = 0;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
if(id != 0) {
|
||||
air = false;
|
||||
continue;
|
||||
}
|
||||
if (id != 0) {
|
||||
air = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(id == 0 && !air) {
|
||||
int cr, cg, cb;
|
||||
int mult = 256;
|
||||
if (id == 0 && !air) {
|
||||
int cr, cg, cb;
|
||||
int mult = 256;
|
||||
|
||||
if(y < 64) {
|
||||
cr = 0;
|
||||
cg = 64 + y * 3;
|
||||
cb = 255 - y * 4;
|
||||
} else {
|
||||
cr = (y-64) * 4;
|
||||
cg = 255;
|
||||
cb = 0;
|
||||
}
|
||||
if (y < 64) {
|
||||
cr = 0;
|
||||
cg = 64 + y * 3;
|
||||
cb = 255 - y * 4;
|
||||
} else {
|
||||
cr = (y - 64) * 4;
|
||||
cg = 255;
|
||||
cb = 0;
|
||||
}
|
||||
|
||||
switch(seq) {
|
||||
case 0:
|
||||
mult = 224;
|
||||
break;
|
||||
case 1:
|
||||
mult = 256;
|
||||
break;
|
||||
case 2:
|
||||
mult = 192;
|
||||
break;
|
||||
case 3:
|
||||
mult = 160;
|
||||
break;
|
||||
}
|
||||
switch (seq) {
|
||||
case 0:
|
||||
mult = 224;
|
||||
break;
|
||||
case 1:
|
||||
mult = 256;
|
||||
break;
|
||||
case 2:
|
||||
mult = 192;
|
||||
break;
|
||||
case 3:
|
||||
mult = 160;
|
||||
break;
|
||||
}
|
||||
|
||||
cr = cr * mult / 256;
|
||||
cg = cg * mult / 256;
|
||||
cb = cb * mult / 256;
|
||||
cr = cr * mult / 256;
|
||||
cg = cg * mult / 256;
|
||||
cb = cb * mult / 256;
|
||||
|
||||
return new Color(cr, cg, cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Color(cr, cg, cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user