mirror of
https://github.com/encounter/dynmap.git
synced 2026-03-30 11:08:39 -07:00
Compare commits
138 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 39db895b9d | |||
| e6d2c4932a | |||
| 00f55758c1 | |||
| ea64a55c04 | |||
| fcbd76c591 | |||
| 9a32485ca9 | |||
| 20e954b905 | |||
| da4c456254 | |||
| 95bf263f11 | |||
| 774e013558 | |||
| b6ec0a2955 | |||
| cdd30d95c5 | |||
| cc0bb3b509 | |||
| 1d2cce6caa | |||
| b7f6a5a39d | |||
| 1cc43637ee | |||
| da7da17235 | |||
| b99f487567 | |||
| ccf6f2ac49 | |||
| ca76b29fb9 | |||
| 40c7c9fa66 | |||
| fae5014b4e | |||
| 0fbd0c0a44 | |||
| 8d0f509bfe | |||
| 65f3ea4fe3 | |||
| b097fb8321 | |||
| feb6d65d82 | |||
| cd4027495c | |||
| 298c0f3391 | |||
| e15514291b | |||
| f80385e1af | |||
| 618d1b05c9 | |||
| aaa06bfc38 | |||
| ad07d68d7e | |||
| 02fb226350 | |||
| d7fe6072a5 | |||
| 6ab82174a5 | |||
| 83f334445b | |||
| d5bd6ff038 | |||
| 22cc46f4b8 | |||
| 77539522f0 | |||
| 2bd0052aa9 | |||
| c53e6058be | |||
| 9b604d4e75 | |||
| 9d490cbcc8 | |||
| 791341f210 | |||
| 42d07d6ca2 | |||
| 61c6f4a086 | |||
| 723e7da8d3 | |||
| d3cf795ebb | |||
| 67baf5100c | |||
| 56f126d5f2 | |||
| 10f93c02c1 | |||
| 5ddaf940ed | |||
| 7c917b729e | |||
| 00485ddcc2 | |||
| 55aeb3c583 | |||
| 1388fa11e5 | |||
| b860c7dd0e | |||
| c67b2e5cc2 | |||
| 44748d7f07 | |||
| 13099587e0 | |||
| 3916c363ae | |||
| 77d9a88868 | |||
| e1f2ca26d6 | |||
| 3c1bde1092 | |||
| f7dbc89ab4 | |||
| 909207ac26 | |||
| 99605ba433 | |||
| ada9637d72 | |||
| 2d693b1ebf | |||
| e900aca2e0 | |||
| 060d1092f9 | |||
| 38df91bafe | |||
| 18ad2e1d79 | |||
| 5fb098259a | |||
| 24c9dfed41 | |||
| a1c86bfabb | |||
| 49d45c653d | |||
| 42391cc4d5 | |||
| 3980ebefa1 | |||
| 058ab0eea7 | |||
| 6e8160e576 | |||
| 51e7420bdb | |||
| 60ea503053 | |||
| f894c4945b | |||
| 7241b2be81 | |||
| b729f28df4 | |||
| 1fc2cdb636 | |||
| b63369675d | |||
| a81665d38d | |||
| db9ced3394 | |||
| d5d737d385 | |||
| f3a1d53277 | |||
| 9a2b9ccac0 | |||
| 835e566151 | |||
| 2380325975 | |||
| 100f3e0590 | |||
| 5b0171c459 | |||
| 2fd91ef94b | |||
| 403a2acc53 | |||
| 959040e5f4 | |||
| 2f6930bc17 | |||
| fb01f6ecf7 | |||
| 29517e9a24 | |||
| d566fccb1e | |||
| 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 |
@@ -0,0 +1,34 @@
|
||||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||
<id>build</id>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<formats>
|
||||
<format>tar.bz2</format>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<includes>
|
||||
<include>README*</include>
|
||||
<include>LICENSE*</include>
|
||||
<include>NOTICE*</include>
|
||||
<include>LICENSE*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}/web</directory>
|
||||
<outputDirectory>/dynmap/web</outputDirectory>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}</directory>
|
||||
<outputDirectory>/dynmap/</outputDirectory>
|
||||
<includes>
|
||||
<include>configuration.txt</include></includes></fileSet>
|
||||
</fileSets>
|
||||
<files>
|
||||
<file>
|
||||
<source>${project.build.directory}/${artifactId}-${version}.jar</source>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<destName>dynmap.jar</destName></file></files>
|
||||
</assembly>
|
||||
+101
-45
@@ -1,45 +1,101 @@
|
||||
# All paths in this configuration file are relative to Dynmap's data-folder: minecraft_server/plugins/dynmap/
|
||||
|
||||
# How often a tile gets rendered (in seconds).
|
||||
renderinterval: 1
|
||||
|
||||
# The path where the tile-files are placed.
|
||||
tilepath: web/tiles
|
||||
|
||||
# The path where the web-files are located.
|
||||
webpath: web
|
||||
|
||||
# The network-interface the webserver will bind to (0.0.0.0 for all interfaces, 127.0.0.1 for only local access).
|
||||
webserver-bindaddress: 0.0.0.0
|
||||
|
||||
# The TCP-port the webserver will listen on.
|
||||
webserver-port: 8123
|
||||
|
||||
# The maptypes Dynmap will use to render.
|
||||
maps:
|
||||
- class: org.dynmap.kzedmap.KzedMap
|
||||
renderers:
|
||||
- class: org.dynmap.kzedmap.DefaultTileRenderer
|
||||
prefix: t
|
||||
- class: org.dynmap.kzedmap.CaveTileRenderer
|
||||
prefix: ct
|
||||
|
||||
web:
|
||||
# Interval the browser should poll for updates.
|
||||
updaterate: 2000
|
||||
|
||||
showchatballoons: true
|
||||
showplayerfacesonmap: true
|
||||
showplayerfacesinmenu: true
|
||||
|
||||
# The name of the map shown when opening Dynmap's page (must be in menu).
|
||||
defaultmap: defaultmap
|
||||
|
||||
# The maps shown in the menu.
|
||||
shownmaps:
|
||||
- type: KzedMapType
|
||||
name: defaultmap
|
||||
prefix: t
|
||||
- type: KzedMapType
|
||||
name: cavemap
|
||||
prefix: ct
|
||||
# All paths in this configuration file are relative to Dynmap's data-folder: minecraft_server/plugins/dynmap/
|
||||
|
||||
# How often a tile gets rendered (in seconds).
|
||||
renderinterval: 1
|
||||
|
||||
# The path where the tile-files are placed.
|
||||
tilespath: web/tiles
|
||||
|
||||
# The path where the web-files are located.
|
||||
webpath: web
|
||||
|
||||
# The network-interface the webserver will bind to (0.0.0.0 for all interfaces, 127.0.0.1 for only local access).
|
||||
webserver-bindaddress: 0.0.0.0
|
||||
|
||||
# The TCP-port the webserver will listen on.
|
||||
webserver-port: 8123
|
||||
|
||||
# Disables Webserver portion of Dynmap (Advanced users only)
|
||||
disable-webserver: false
|
||||
|
||||
# Writes JSON to file in the webpath
|
||||
jsonfile: false
|
||||
|
||||
# How often the json file gets written to(in seconds)
|
||||
jsonfile-interval: 1
|
||||
|
||||
# The maptypes Dynmap will use to render.
|
||||
worlds:
|
||||
- name: world
|
||||
maps:
|
||||
- class: org.dynmap.kzedmap.KzedMap
|
||||
renderers:
|
||||
- class: org.dynmap.kzedmap.DefaultTileRenderer
|
||||
prefix: t
|
||||
maximumheight: 127
|
||||
- class: org.dynmap.kzedmap.CaveTileRenderer
|
||||
prefix: ct
|
||||
maximumheight: 127
|
||||
- name: nether
|
||||
maps:
|
||||
- class: org.dynmap.kzedmap.KzedMap
|
||||
renderers:
|
||||
- class: org.dynmap.kzedmap.DefaultTileRenderer
|
||||
prefix: nt
|
||||
maximumheight: 64
|
||||
|
||||
web:
|
||||
# Handles the clientside updates differently only enable if using jsonfile
|
||||
jsonfile: false
|
||||
|
||||
# Interval the browser should poll for updates.
|
||||
updaterate: 2000
|
||||
|
||||
# showchat: modal/balloons
|
||||
showchat: modal
|
||||
messagettl: 15000
|
||||
|
||||
showplayerfacesonmap: true
|
||||
showplayerfacesinmenu: true
|
||||
focuschatballoons: false
|
||||
joinmessage: "%playername% joined"
|
||||
quitmessage: "%playername% quit"
|
||||
|
||||
defaultworld: world
|
||||
worlds:
|
||||
- title: World
|
||||
name: world
|
||||
maps:
|
||||
- type: KzedMapType
|
||||
title: Surface
|
||||
name: surface
|
||||
prefix: t
|
||||
- type: KzedMapType
|
||||
title: Cave
|
||||
name: cave
|
||||
prefix: ct
|
||||
- title: Nether
|
||||
name: nether
|
||||
maps:
|
||||
- type: KzedMapType
|
||||
title: Surface
|
||||
name: nether
|
||||
prefix: nt
|
||||
# Example:
|
||||
#- title: Other World # With what name the world is displayed.
|
||||
# name: world_other # The actual name of the world (equal to your directory-name).
|
||||
# maps:
|
||||
# - type: KzedMapType # The type (or perspective) of the map. At the moment, there are no others than KzedMapType.
|
||||
# title: Surface # The name of the map that will be displayed.
|
||||
# name: surface # The actual name of the map (should be unique for this world).
|
||||
# prefix: t # The prefix of the tile-files that are generated.
|
||||
# icon: block_other.png # Sets a custom icon for the map. (optional)
|
||||
# - type: KzedMapType
|
||||
# title: Cave
|
||||
# name: cave
|
||||
# prefix: ct
|
||||
|
||||
# Enables debugging.
|
||||
#debuggers:
|
||||
# - class: org.dynmap.debug.LogDebugger
|
||||
# - class: org.dynmap.debug.BukkitPlayerDebugger
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>dynamic-map</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<artifactId>dynmap</artifactId>
|
||||
<version>0.13</version>
|
||||
<name>DynamicMap</name>
|
||||
<url>http://www.bukkit.org</url>
|
||||
<build>
|
||||
@@ -16,7 +16,24 @@
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>assembly.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>build</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package org.dynmap;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class AsynchronousQueue<T> {
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private Object lock = new Object();
|
||||
private Thread thread;
|
||||
private LinkedList<T> queue = new LinkedList<T>();
|
||||
private Set<T> set = new HashSet<T>();
|
||||
private Handler<T> handler;
|
||||
private int dequeueTime;
|
||||
|
||||
public AsynchronousQueue(Handler<T> handler, int dequeueTime) {
|
||||
this.handler = handler;
|
||||
this.dequeueTime = dequeueTime;
|
||||
}
|
||||
|
||||
public boolean push(T t) {
|
||||
synchronized (lock) {
|
||||
if (set.add(t)) {
|
||||
queue.addLast(t);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private T pop() {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
T t = queue.removeFirst();
|
||||
if (!set.remove(t)) {
|
||||
// This should never happen.
|
||||
}
|
||||
return t;
|
||||
} catch (NoSuchElementException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return set.size();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
synchronized (lock) {
|
||||
thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
running();
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
try {
|
||||
thread.setPriority(Thread.MIN_PRIORITY);
|
||||
} catch (SecurityException e) {
|
||||
log.info("Failed to set minimum priority for worker thread!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
synchronized (lock) {
|
||||
if (thread == null)
|
||||
return;
|
||||
Thread oldThread = thread;
|
||||
thread = null;
|
||||
|
||||
log.info("Stopping map renderer...");
|
||||
|
||||
try {
|
||||
oldThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
log.info("Waiting for map renderer to stop is interrupted");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void running() {
|
||||
try {
|
||||
while (Thread.currentThread() == thread) {
|
||||
T t = pop();
|
||||
if (t != null) {
|
||||
handler.handle(t);
|
||||
}
|
||||
sleep(dequeueTime);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
log.log(Level.SEVERE, "Exception on rendering-thread", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void sleep(int time) {
|
||||
try {
|
||||
Thread.sleep(time);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,60 @@
|
||||
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 String world;
|
||||
public double x, y, z;
|
||||
|
||||
public Player(String name, String world, double x, double y, double z) {
|
||||
this.name = name;
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Stamped {
|
||||
public long timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static class ChatMessage extends Stamped {
|
||||
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 WebChatMessage extends Stamped {
|
||||
public String type = "webchat";
|
||||
public String playerName;
|
||||
public String message;
|
||||
|
||||
public WebChatMessage(String playerName, String message) {
|
||||
this.playerName = playerName;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Tile extends Stamped {
|
||||
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.getLocation());
|
||||
}
|
||||
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
if (event.getDamageLevel() == BlockDamageLevel.BROKEN) {
|
||||
Block blockBroken = event.getBlock();
|
||||
mgr.touch(blockBroken.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,33 @@
|
||||
package org.dynmap;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
|
||||
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(" ");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player sends a chat message
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPlayerChat(PlayerChatEvent event)
|
||||
{
|
||||
mgr.addChatEvent(event);
|
||||
DynmapPlugin plugin;
|
||||
|
||||
public DynmapPlayerListener(DynmapPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
plugin.mapManager.pushUpdate(new Client.ChatMessage(event.getPlayer().getName(), event.getMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerEvent event) {
|
||||
String joinMessage = plugin.configuration.getString("joinmessage", "%playername% joined");
|
||||
joinMessage = joinMessage.replaceAll("%playername%", event.getPlayer().getName());
|
||||
plugin.mapManager.pushUpdate(new Client.ChatMessage("Server", joinMessage));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerEvent event) {
|
||||
String quitMessage = plugin.configuration.getString("quitmessage", "%playername% quit");
|
||||
quitMessage = quitMessage.replaceAll("%playername%", event.getPlayer().getName());
|
||||
plugin.mapManager.pushUpdate(new Client.ChatMessage("Server", quitMessage));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,101 +1,279 @@
|
||||
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.FileOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Timer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
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.event.world.WorldEvent;
|
||||
import org.bukkit.event.world.WorldListener;
|
||||
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.Event.Listener;
|
||||
import org.dynmap.debug.Debug;
|
||||
import org.dynmap.debug.Debugger;
|
||||
import org.dynmap.web.HttpServer;
|
||||
import org.dynmap.web.handlers.ClientConfigurationHandler;
|
||||
import org.dynmap.web.handlers.ClientUpdateHandler;
|
||||
import org.dynmap.web.handlers.FilesystemHandler;
|
||||
import org.dynmap.web.handlers.SendMessageHandler;
|
||||
import org.dynmap.web.handlers.SendMessageHandler.Message;
|
||||
import org.dynmap.web.Json;
|
||||
|
||||
public class DynmapPlugin extends JavaPlugin {
|
||||
|
||||
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;
|
||||
}
|
||||
public HttpServer webServer = null;
|
||||
public MapManager mapManager = null;
|
||||
public PlayerList playerList;
|
||||
public Configuration configuration;
|
||||
|
||||
public World getWorld() {
|
||||
return getServer().getWorlds()[0];
|
||||
}
|
||||
|
||||
public MapManager getMapManager() {
|
||||
return mapManager;
|
||||
}
|
||||
|
||||
public WebServer getWebServer() {
|
||||
return webServer;
|
||||
}
|
||||
public Timer timer;
|
||||
|
||||
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 tilesDirectory;
|
||||
|
||||
try {
|
||||
webServer = new WebServer(mapManager, getServer(), playerList, debugger, configuration);
|
||||
} catch(IOException e) {
|
||||
log.info("position failed to start WebServer (IOException)");
|
||||
}
|
||||
|
||||
registerEvents();
|
||||
}
|
||||
public World getWorld() {
|
||||
return getServer().getWorlds().get(0);
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
mapManager.stopManager();
|
||||
public MapManager getMapManager() {
|
||||
return mapManager;
|
||||
}
|
||||
|
||||
if(webServer != null) {
|
||||
webServer.shutdown();
|
||||
webServer = null;
|
||||
}
|
||||
debugger.disable();
|
||||
}
|
||||
public HttpServer getWebServer() {
|
||||
return webServer;
|
||||
}
|
||||
|
||||
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 void onEnable() {
|
||||
configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt"));
|
||||
configuration.load();
|
||||
|
||||
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");
|
||||
*/
|
||||
|
||||
}
|
||||
loadDebuggers();
|
||||
|
||||
tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles"));
|
||||
tilesDirectory.mkdirs();
|
||||
|
||||
playerList = new PlayerList(getServer(), getFile("hiddenplayers.txt"));
|
||||
playerList.load();
|
||||
|
||||
mapManager = new MapManager(this, configuration);
|
||||
mapManager.startRendering();
|
||||
|
||||
if (!configuration.getBoolean("disable-webserver", false)) {
|
||||
loadWebserver();
|
||||
}
|
||||
|
||||
if (configuration.getBoolean("jsonfile", false)) {
|
||||
jsonConfig();
|
||||
int jsonInterval = configuration.getInt("jsonfile-interval", 1) * 1000;
|
||||
timer = new Timer();
|
||||
timer.scheduleAtFixedRate(new JsonTimerTask(this, configuration), jsonInterval, jsonInterval);
|
||||
}
|
||||
|
||||
registerEvents();
|
||||
}
|
||||
|
||||
public void loadWebserver() {
|
||||
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(getFile(configuration.getString("webpath", "web"))));
|
||||
webServer.handlers.put("/tiles/", new FilesystemHandler(tilesDirectory));
|
||||
webServer.handlers.put("/up/", new ClientUpdateHandler(mapManager, playerList, getServer()));
|
||||
webServer.handlers.put("/up/configuration", new ClientConfigurationHandler((Map<?, ?>) configuration.getProperty("web")));
|
||||
|
||||
SendMessageHandler messageHandler = new SendMessageHandler();
|
||||
messageHandler.onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() {
|
||||
@Override
|
||||
public void triggered(Message t) {
|
||||
mapManager.pushUpdate(new Client.WebChatMessage(t.name, t.message));
|
||||
log.info("[WEB]" + t.name + ": " + t.message);
|
||||
getServer().broadcastMessage("[WEB]" + t.name + ": " + t.message);
|
||||
}
|
||||
});
|
||||
webServer.handlers.put("/up/sendmessage", messageHandler);
|
||||
|
||||
try {
|
||||
webServer.startServer();
|
||||
} catch (IOException e) {
|
||||
log.severe("Failed to start WebServer on " + bindAddress + ":" + port + "!");
|
||||
}
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
mapManager.stopRendering();
|
||||
|
||||
if (webServer != null) {
|
||||
webServer.shutdown();
|
||||
webServer = null;
|
||||
}
|
||||
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
Debug.clearDebuggers();
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
BlockListener blockListener = new DynmapBlockListener(mapManager);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Monitor, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Monitor, this);
|
||||
|
||||
WorldListener worldListener = new WorldListener() {
|
||||
@Override
|
||||
public void onWorldLoaded(WorldEvent event) {
|
||||
mapManager.activateWorld(event.getWorld());
|
||||
}
|
||||
};
|
||||
getServer().getPluginManager().registerEvent(Event.Type.WORLD_LOADED, worldListener, Priority.Monitor, this);
|
||||
|
||||
PlayerListener playerListener = new DynmapPlayerListener(this);
|
||||
//getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
||||
}
|
||||
|
||||
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 File getFile(String path) {
|
||||
return combinePaths(getDataFolder(), path);
|
||||
}
|
||||
|
||||
protected void loadDebuggers() {
|
||||
Object debuggersConfiguration = configuration.getProperty("debuggers");
|
||||
Debug.clearDebuggers();
|
||||
if (debuggersConfiguration != null) {
|
||||
for (Object debuggerConfiguration : (List<?>) debuggersConfiguration) {
|
||||
Map<?, ?> debuggerConfigurationMap = (Map<?, ?>) debuggerConfiguration;
|
||||
try {
|
||||
Class<?> debuggerClass = Class.forName((String) debuggerConfigurationMap.get("class"));
|
||||
Constructor<?> constructor = debuggerClass.getConstructor(JavaPlugin.class, Map.class);
|
||||
Debugger debugger = (Debugger) constructor.newInstance(this, debuggerConfigurationMap);
|
||||
Debug.addDebugger(debugger);
|
||||
} catch (Exception e) {
|
||||
log.severe("Error loading debugger: " + e);
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (!cmd.getName().equalsIgnoreCase("dynmap"))
|
||||
return false;
|
||||
Player player = null;
|
||||
if (sender instanceof Player)
|
||||
player = (Player) sender;
|
||||
if (args.length > 0) {
|
||||
if (args[0].equals("render")) {
|
||||
if (sender instanceof Player) {
|
||||
mapManager.touch(((Player) sender).getLocation());
|
||||
return true;
|
||||
}
|
||||
} else if (args[0].equals("hide")) {
|
||||
if (args.length == 1 && player != null) {
|
||||
playerList.hide(player.getName());
|
||||
sender.sendMessage("You are now hidden on Dynmap.");
|
||||
return true;
|
||||
} else {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
playerList.hide(args[i]);
|
||||
sender.sendMessage(args[i] + " is now hidden on Dynmap.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else if (args[0].equals("show")) {
|
||||
if (args.length == 1 && player != null) {
|
||||
playerList.show(player.getName());
|
||||
sender.sendMessage("You are now visible on Dynmap.");
|
||||
return true;
|
||||
} else {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
playerList.show(args[i]);
|
||||
sender.sendMessage(args[i] + " is now visible on Dynmap.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else if (args[0].equals("fullrender")) {
|
||||
if (player == null || player.isOp()) {
|
||||
if (args.length > 2) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
World w = getServer().getWorld(args[i]);
|
||||
mapManager.renderFullWorld(new Location(w, 0, 0, 0));
|
||||
}
|
||||
return true;
|
||||
} else if (player != null) {
|
||||
mapManager.renderFullWorld(player.getLocation());
|
||||
return true;
|
||||
}
|
||||
} else if (player != null) {
|
||||
player.sendMessage("Only OPs are allowed to use this command!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void jsonConfig() {
|
||||
File outputFile;
|
||||
Map<?, ?> clientConfig = (Map<?, ?>) configuration.getProperty("web");
|
||||
File webpath = new File(configuration.getString("webpath", "web"), "dynmap_config.json");
|
||||
if (webpath.isAbsolute())
|
||||
outputFile = webpath;
|
||||
else
|
||||
outputFile = new File(getDataFolder(), webpath.toString());
|
||||
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(outputFile);
|
||||
fos.write(Json.stringifyJson(clientConfig).getBytes());
|
||||
fos.close();
|
||||
} catch (FileNotFoundException ex) {
|
||||
System.out.println("FileNotFoundException : " + ex);
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("IOException : " + ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.dynmap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
public class DynmapWorld {
|
||||
public World world;
|
||||
public List<MapType> maps = new ArrayList<MapType>();
|
||||
public UpdateQueue updates = new UpdateQueue();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.dynmap;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Event<T> {
|
||||
private List<Listener<T>> listeners = new LinkedList<Listener<T>>();
|
||||
|
||||
public synchronized void addListener(Listener<T> l) {
|
||||
listeners.add(l);
|
||||
}
|
||||
|
||||
public synchronized void removeListener(Listener<T> l) {
|
||||
listeners.remove(l);
|
||||
}
|
||||
|
||||
public synchronized void trigger(T t) {
|
||||
for (Listener<T> l : listeners) {
|
||||
l.triggered(t);
|
||||
}
|
||||
}
|
||||
|
||||
public interface Listener<T> {
|
||||
void triggered(T t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.dynmap;
|
||||
|
||||
public interface Handler<T> {
|
||||
void handle(T t);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.dynmap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
import org.dynmap.web.Json;
|
||||
|
||||
class JsonTimerTask extends TimerTask {
|
||||
private final DynmapPlugin plugin;
|
||||
private Server server;
|
||||
private MapManager mapManager;
|
||||
private Configuration configuration;
|
||||
|
||||
public JsonTimerTask(DynmapPlugin instance, Configuration config) {
|
||||
this.plugin = instance;
|
||||
this.server = this.plugin.getServer();
|
||||
this.mapManager = this.plugin.getMapManager();
|
||||
this.configuration = config;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
for (World world : this.server.getWorlds()) {
|
||||
long current = System.currentTimeMillis();
|
||||
|
||||
Client.Update update = new Client.Update();
|
||||
|
||||
update.timestamp = current;
|
||||
update.servertime = world.getTime() % 24000;
|
||||
|
||||
Player[] players = mapManager.playerList.getVisiblePlayers();
|
||||
update.players = new Client.Player[players.length];
|
||||
for (int i = 0; i < players.length; i++) {
|
||||
Player p = players[i];
|
||||
Location pl = p.getLocation();
|
||||
update.players[i] = new Client.Player(p.getName(), pl.getWorld().getName(), pl.getX(), pl.getY(), pl.getZ());
|
||||
}
|
||||
|
||||
update.updates = mapManager.getWorldUpdates(world.getName(), current - (configuration.getInt("jsonfile-interval", 1) + 10000));
|
||||
|
||||
File webpath = new File(this.configuration.getString("webpath", "web"), "dynmap_" + world.getName() + ".json");
|
||||
File outputFile;
|
||||
if (webpath.isAbsolute())
|
||||
outputFile = webpath;
|
||||
else {
|
||||
outputFile = new File(plugin.getDataFolder(), webpath.toString());
|
||||
}
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(outputFile);
|
||||
fos.write(Json.stringifyJson(update).getBytes());
|
||||
fos.close();
|
||||
} catch (FileNotFoundException ex) {
|
||||
System.out.println("FileNotFoundException : " + ex);
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("IOException : " + ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package org.dynmap;
|
||||
|
||||
public class MapLocation {
|
||||
public float x;
|
||||
public float y;
|
||||
}
|
||||
@@ -3,182 +3,230 @@ package org.dynmap;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
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;
|
||||
import org.dynmap.debug.Debug;
|
||||
|
||||
public class MapManager extends Thread {
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
public class MapManager {
|
||||
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;
|
||||
public AsynchronousQueue<MapTile> tileQueue;
|
||||
|
||||
public Map<String, DynmapWorld> worlds = new HashMap<String, DynmapWorld>();
|
||||
public Map<String, DynmapWorld> inactiveworlds = new HashMap<String, DynmapWorld>();
|
||||
|
||||
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;
|
||||
public MapManager(DynmapPlugin plugin, ConfigurationNode configuration) {
|
||||
this.tileQueue = new AsynchronousQueue<MapTile>(new Handler<MapTile>() {
|
||||
@Override
|
||||
public void handle(MapTile t) {
|
||||
render(t);
|
||||
}
|
||||
}, (int) (configuration.getDouble("renderinterval", 0.5) * 1000));
|
||||
|
||||
for(Object worldConfigurationObj : (List<?>)configuration.getProperty("worlds")) {
|
||||
Map<?, ?> worldConfiguration = (Map<?, ?>)worldConfigurationObj;
|
||||
String worldName = (String)worldConfiguration.get("name");
|
||||
DynmapWorld world = new DynmapWorld();
|
||||
if (worldConfiguration.get("maps") != null) {
|
||||
for(MapType map : loadMapTypes((List<?>)worldConfiguration.get("maps"))) {
|
||||
world.maps.add(map);
|
||||
}
|
||||
}
|
||||
inactiveworlds.put(worldName, world);
|
||||
|
||||
World bukkitWorld = plugin.getServer().getWorld(worldName);
|
||||
if (bukkitWorld != null)
|
||||
activateWorld(bukkitWorld);
|
||||
}
|
||||
|
||||
tileQueue.start();
|
||||
}
|
||||
|
||||
/* 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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
void renderFullWorld(Location l) {
|
||||
DynmapWorld world = worlds.get(l.getWorld().getName());
|
||||
if (world == null) {
|
||||
log.severe("Could not render: world '" + l.getWorld().getName() + "' not defined in configuration.");
|
||||
return;
|
||||
}
|
||||
World w = world.world;
|
||||
log.info("Full render starting on world '" + w.getName() + "'...");
|
||||
for (MapType map : world.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>();
|
||||
|
||||
/* 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
for (MapTile tile : map.getTiles(l)) {
|
||||
if (!found.contains(tile)) {
|
||||
found.add(tile);
|
||||
renderQueue.add(tile);
|
||||
}
|
||||
}
|
||||
while (!renderQueue.isEmpty()) {
|
||||
MapTile tile = renderQueue.pollFirst();
|
||||
|
||||
/* 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());
|
||||
}
|
||||
}
|
||||
DynmapChunk[] requiredChunks = tile.getMap().getRequiredChunks(tile);
|
||||
|
||||
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);
|
||||
}
|
||||
if (requiredChunks.length > requiredChunkCount)
|
||||
requiredChunkCount = requiredChunks.length;
|
||||
// Unload old chunks.
|
||||
while (loadedChunks.size() >= requiredChunkCount - requiredChunks.length) {
|
||||
DynmapChunk c = loadedChunks.pollFirst();
|
||||
w.unloadChunk(c.x, c.z, false, true);
|
||||
}
|
||||
|
||||
// Load the required chunks.
|
||||
for (DynmapChunk chunk : requiredChunks) {
|
||||
boolean wasLoaded = w.isChunkLoaded(chunk.x, chunk.z);
|
||||
w.loadChunk(chunk.x, chunk.z, false);
|
||||
if (!wasLoaded)
|
||||
loadedChunks.add(chunk);
|
||||
}
|
||||
|
||||
if (render(tile)) {
|
||||
found.remove(tile);
|
||||
rendered.add(tile);
|
||||
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();
|
||||
w.unloadChunk(c.x, c.z, false, true);
|
||||
}
|
||||
}
|
||||
log.info("Full render finished.");
|
||||
}
|
||||
|
||||
public void activateWorld(World w) {
|
||||
DynmapWorld world = inactiveworlds.get(w.getName());
|
||||
if (world == null) {
|
||||
world = worlds.get(w.getName());
|
||||
} else {
|
||||
inactiveworlds.remove(w.getName());
|
||||
}
|
||||
if (world != null) {
|
||||
world.world = w;
|
||||
worlds.put(w.getName(), world);
|
||||
log.info("Activated world '" + w.getName() + "' in Dynmap.");
|
||||
}
|
||||
}
|
||||
|
||||
private MapType[] loadMapTypes(List<?> mapConfigurations) {
|
||||
Event.Listener<MapTile> invalitateListener = new Event.Listener<MapTile>() {
|
||||
@Override
|
||||
public void triggered(MapTile t) {
|
||||
invalidateTile(t);
|
||||
}
|
||||
};
|
||||
ArrayList<MapType> mapTypes = new ArrayList<MapType>();
|
||||
for (Object configuredMapObj : mapConfigurations) {
|
||||
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(Map.class);
|
||||
MapType mapType = (MapType) constructor.newInstance(configuredMap);
|
||||
mapType.onTileInvalidated.addListener(invalitateListener);
|
||||
mapTypes.add(mapType);
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "Error loading maptype", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
MapType[] result = new MapType[mapTypes.size()];
|
||||
mapTypes.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void touch(Location l) {
|
||||
DynmapWorld world = worlds.get(l.getWorld().getName());
|
||||
if (world == null)
|
||||
return;
|
||||
for (int i = 0; i < world.maps.size(); i++) {
|
||||
MapTile[] tiles = world.maps.get(i).getTiles(l);
|
||||
for (int j = 0; j < tiles.length; j++) {
|
||||
invalidateTile(tiles[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void invalidateTile(MapTile tile) {
|
||||
Debug.debug("Invalidating tile " + tile.getFilename());
|
||||
tileQueue.push(tile);
|
||||
}
|
||||
|
||||
public void startRendering() {
|
||||
tileQueue.start();
|
||||
}
|
||||
|
||||
public void stopRendering() {
|
||||
tileQueue.stop();
|
||||
}
|
||||
|
||||
public boolean render(MapTile tile) {
|
||||
boolean result = tile.getMap().render(tile, getTileFile(tile));
|
||||
pushUpdate(tile.getWorld(), new Client.Tile(tile.getFilename()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private HashMap<World, File> worldTileDirectories = new HashMap<World, File>();
|
||||
private File getTileFile(MapTile tile) {
|
||||
World world = tile.getWorld();
|
||||
File worldTileDirectory = worldTileDirectories.get(world);
|
||||
if (worldTileDirectory == null) {
|
||||
worldTileDirectory = new File(DynmapPlugin.tilesDirectory, tile.getWorld().getName());
|
||||
worldTileDirectories.put(world, worldTileDirectory);
|
||||
}
|
||||
worldTileDirectory.mkdirs();
|
||||
return new File(worldTileDirectory, tile.getFilename());
|
||||
}
|
||||
|
||||
public void pushUpdate(Object update) {
|
||||
for(DynmapWorld world : worlds.values()) {
|
||||
world.updates.pushUpdate(update);
|
||||
}
|
||||
}
|
||||
|
||||
public void pushUpdate(World world, Object update) {
|
||||
pushUpdate(world.getName(), update);
|
||||
}
|
||||
|
||||
public void pushUpdate(String worldName, Object update) {
|
||||
DynmapWorld world = worlds.get(worldName);
|
||||
world.updates.pushUpdate(update);
|
||||
}
|
||||
|
||||
public Object[] getWorldUpdates(String worldName, long since) {
|
||||
DynmapWorld world = worlds.get(worldName);
|
||||
if (world == null)
|
||||
return new Object[0];
|
||||
return world.updates.getUpdatedObjects(since);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
package org.dynmap;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
public abstract class MapTile {
|
||||
private MapType map;
|
||||
public MapType getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public MapTile(MapType map) {
|
||||
this.map = map;
|
||||
}
|
||||
private World world;
|
||||
private MapType map;
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public MapType getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public abstract String getFilename();
|
||||
|
||||
public MapTile(World world, MapType map) {
|
||||
this.world = world;
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getFilename().hashCode() ^ getWorld().hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,17 @@
|
||||
package org.dynmap;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.Location;
|
||||
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);
|
||||
public Event<MapTile> onTileInvalidated = new Event<MapTile>();
|
||||
|
||||
public abstract MapTile[] getTiles(Location l);
|
||||
|
||||
public abstract MapTile[] getAdjecentTiles(MapTile tile);
|
||||
|
||||
public abstract DynmapChunk[] getRequiredChunks(MapTile tile);
|
||||
|
||||
public abstract boolean render(MapTile tile, File outputFile);
|
||||
}
|
||||
|
||||
@@ -14,68 +14,87 @@ 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;
|
||||
|
||||
public PlayerList(Server server, File hiddenPlayersFile) {
|
||||
this.server = server;
|
||||
this.hiddenPlayersFile = hiddenPlayersFile;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// TODO: Clean this up... one day
|
||||
public Player[] getVisiblePlayers(String worldName) {
|
||||
ArrayList<Player> visiblePlayers = new ArrayList<Player>();
|
||||
Player[] onlinePlayers = server.getOnlinePlayers();
|
||||
for (int i = 0; i < onlinePlayers.length; i++) {
|
||||
Player p = onlinePlayers[i];
|
||||
if (p.getWorld().getName().equals(worldName) && !hiddenPlayerNames.contains(p.getName())) {
|
||||
visiblePlayers.add(p);
|
||||
}
|
||||
}
|
||||
Player[] result = new Player[visiblePlayers.size()];
|
||||
visiblePlayers.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user