Merge remote-tracking branch 'kilandor/master' into nowebserver

Conflicts:
	configuration.txt
	src/main/java/org/dynmap/DynmapPlayerListener.java
	src/main/java/org/dynmap/DynmapPlugin.java
	web/map.js
This commit is contained in:
FrozenCow 2011-02-22 17:58:39 +01:00
commit 1cc43637ee
5 changed files with 144 additions and 13 deletions

13
configuration.txt Normal file → Executable file
View File

@ -15,6 +15,15 @@ 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: 1000
# The maptypes Dynmap will use to render.
worlds:
- name: world
@ -36,12 +45,16 @@ worlds:
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

View File

@ -23,7 +23,11 @@ public class Client {
}
}
public static class ChatMessage {
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;
@ -34,7 +38,7 @@ public class Client {
}
}
public static class WebChatMessage {
public static class WebChatMessage extends Stamped {
public String type = "webchat";
public String playerName;
public String message;
@ -45,7 +49,7 @@ public class Client {
}
}
public static class Tile {
public static class Tile extends Stamped {
public String type = "tile";
public String name;

View File

@ -1,6 +1,8 @@
package org.dynmap;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.InetAddress;
@ -8,6 +10,7 @@ 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;
@ -31,6 +34,7 @@ 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 {
@ -41,6 +45,8 @@ public class DynmapPlugin extends JavaPlugin {
public PlayerList playerList;
public Configuration configuration;
public Timer timer;
public static File tilesDirectory;
public World getWorld() {
@ -70,6 +76,19 @@ public class DynmapPlugin extends JavaPlugin {
mapManager = new MapManager(this, configuration);
mapManager.startRendering();
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");
@ -105,8 +124,6 @@ public class DynmapPlugin extends JavaPlugin {
} catch (IOException e) {
log.severe("Failed to start WebServer on " + bindAddress + ":" + port + "!");
}
registerEvents();
}
public void onDisable() {
@ -116,6 +133,11 @@ public class DynmapPlugin extends JavaPlugin {
webServer.shutdown();
webServer = null;
}
if (timer != null) {
timer.cancel();
}
Debug.clearDebuggers();
}
@ -232,4 +254,24 @@ public class DynmapPlugin extends JavaPlugin {
}
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);
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -103,7 +103,7 @@ DynMap.prototype = {
};
google.maps.event.addListener(map, 'dragstart', function(mEvent) {
me.followPlayer('');
me.followPlayer(null);
});
// TODO: Enable hash-links.
/*google.maps.event.addListener(map, 'zoom_changed', function() {
@ -277,7 +277,9 @@ DynMap.prototype = {
$.getJSON(me.options.updateUrl + "world/" + me.world.name + "/" + me.lasttimestamp, function(update) {
me.alertbox.hide();
if (!me.options.jsonfile)
me.lasttimestamp = update.timestamp;
me.clock.setTime(update.servertime);
me.clockdigital.setTime(update.servertime);
@ -303,18 +305,23 @@ DynMap.prototype = {
$.each(update.updates, function(index, update) {
swtch(update.type, {
tile: function() {
if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile)
me.onTileUpdated(update.name);
},
chat: function() {
if (!me.options.showchat) {
return;
}
if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile)
me.onPlayerChat(update.playerName, update.message);
},
webchat: function() {
if (!me.options.showchat) {
return;
}
if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile)
me.onPlayerChat('[WEB]' + update.playerName, update.message);
}
}, function(type) {
@ -325,7 +332,6 @@ DynMap.prototype = {
//var divs = $('div[rel]');
//divs.filter(function(i){return parseInt(divs[i].attr('rel')) > timestamp+me.options.messagettl;}).remove();
});
setTimeout(function() { me.update(); }, me.options.updaterate);
}, function(request, statusText, ex) {
me.alertbox