Merge branch 'master' of git://github.com/FrozenCow/dynmap

This commit is contained in:
Jason Booth 2011-03-09 16:42:49 -06:00
commit d4bc0863b8
9 changed files with 179 additions and 123 deletions

9
configuration.txt Executable file → Normal file
View File

@ -67,13 +67,16 @@ web:
# Interval the browser should poll for updates. # Interval the browser should poll for updates.
updaterate: 2000 updaterate: 2000
# showchat: modal/balloons showchatballoons: false
showchat: modal focuschatballoons: false
showchatwindow: true
allowwebchat: true
messagettl: 15000 messagettl: 15000
showplayerfacesonmap: true showplayerfacesonmap: true
showplayerfacesinmenu: true showplayerfacesinmenu: true
focuschatballoons: false
joinmessage: "%playername% joined" joinmessage: "%playername% joined"
quitmessage: "%playername% quit" quitmessage: "%playername% quit"

View File

@ -4,10 +4,10 @@ import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerListener;
public class DynmapPlayerListener extends PlayerListener { public class DynmapPlayerChatListener extends PlayerListener {
DynmapPlugin plugin; DynmapPlugin plugin;
public DynmapPlayerListener(DynmapPlugin plugin) { public DynmapPlayerChatListener(DynmapPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }

View File

@ -16,14 +16,12 @@ import java.util.logging.Logger;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.BlockDamageLevel;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerEvent;
@ -131,6 +129,7 @@ public class DynmapPlugin extends JavaPlugin {
webServer.handlers.put("/up/", new ClientUpdateHandler(mapManager, playerList, getServer())); webServer.handlers.put("/up/", new ClientUpdateHandler(mapManager, playerList, getServer()));
webServer.handlers.put("/up/configuration", new ClientConfigurationHandler((Map<?, ?>) configuration.getProperty("web"))); webServer.handlers.put("/up/configuration", new ClientConfigurationHandler((Map<?, ?>) configuration.getProperty("web")));
if (configuration.getNode("web").getBoolean("allowwebchat", false)) {
SendMessageHandler messageHandler = new SendMessageHandler(); SendMessageHandler messageHandler = new SendMessageHandler();
messageHandler.onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() { messageHandler.onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() {
@Override @Override
@ -141,6 +140,7 @@ public class DynmapPlugin extends JavaPlugin {
} }
}); });
webServer.handlers.put("/up/sendmessage", messageHandler); webServer.handlers.put("/up/sendmessage", messageHandler);
}
try { try {
webServer.startServer(); webServer.startServer();
@ -185,8 +185,10 @@ public class DynmapPlugin extends JavaPlugin {
mm.touch(event.getBlock().getLocation()); mm.touch(event.getBlock().getLocation());
} }
}; };
if (isTrigger("blockplaced")) pm.registerEvent(Event.Type.BLOCK_PLACED, renderTrigger, Priority.Monitor, this); if (isTrigger("blockplaced"))
if (isTrigger("blockbreak")) pm.registerEvent(Event.Type.BLOCK_BREAK, renderTrigger, Priority.Monitor, this); pm.registerEvent(Event.Type.BLOCK_PLACED, renderTrigger, Priority.Monitor, this);
if (isTrigger("blockbreak"))
pm.registerEvent(Event.Type.BLOCK_BREAK, renderTrigger, Priority.Monitor, this);
} }
{ {
PlayerListener renderTrigger = new PlayerListener() { PlayerListener renderTrigger = new PlayerListener() {
@ -194,13 +196,16 @@ public class DynmapPlugin extends JavaPlugin {
public void onPlayerJoin(PlayerEvent event) { public void onPlayerJoin(PlayerEvent event) {
mm.touch(event.getPlayer().getLocation()); mm.touch(event.getPlayer().getLocation());
} }
@Override @Override
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
mm.touch(event.getPlayer().getLocation()); mm.touch(event.getPlayer().getLocation());
} }
}; };
if (isTrigger("playerjoin")) pm.registerEvent(Event.Type.PLAYER_JOIN, renderTrigger, Priority.Monitor, this); if (isTrigger("playerjoin"))
if (isTrigger("playermove")) pm.registerEvent(Event.Type.PLAYER_MOVE, renderTrigger, Priority.Monitor, this); pm.registerEvent(Event.Type.PLAYER_JOIN, renderTrigger, Priority.Monitor, this);
if (isTrigger("playermove"))
pm.registerEvent(Event.Type.PLAYER_MOVE, renderTrigger, Priority.Monitor, this);
} }
{ {
WorldListener renderTrigger = new WorldListener() { WorldListener renderTrigger = new WorldListener() {
@ -211,17 +216,29 @@ public class DynmapPlugin extends JavaPlugin {
mm.touch(new Location(event.getWorld(), x, 127, z)); mm.touch(new Location(event.getWorld(), x, 127, z));
} }
/*@Override /*
public void onChunkGenerated(ChunkLoadEvent event) { * @Override public void onChunkGenerated(ChunkLoadEvent event)
int x = event.getChunk().getX() * 16 + 8; * { int x = event.getChunk().getX() * 16 + 8; int z =
int z = event.getChunk().getZ() * 16 + 8; * event.getChunk().getZ() * 16 + 8; mm.touch(new
mm.touch(new Location(event.getWorld(), x, 127, z)); * Location(event.getWorld(), x, 127, z)); }
}*/ */
}; };
if (isTrigger("chunkloaded")) pm.registerEvent(Event.Type.CHUNK_LOADED, renderTrigger, Priority.Monitor, this); if (isTrigger("chunkloaded"))
pm.registerEvent(Event.Type.CHUNK_LOADED, renderTrigger, Priority.Monitor, this);
//if (isTrigger("chunkgenerated")) pm.registerEvent(Event.Type.CHUNK_GENERATED, renderTrigger, Priority.Monitor, this); //if (isTrigger("chunkgenerated")) pm.registerEvent(Event.Type.CHUNK_GENERATED, renderTrigger, Priority.Monitor, this);
} }
// To announce when players have joined/quit/chatted.
if (configuration.getNode("web").getBoolean("showchatballoons", false) || configuration.getNode("web").getBoolean("showchatwindow", false)) {
// To handle webchat.
PlayerListener playerListener = new DynmapPlayerChatListener(this);
//getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Monitor, this);
}
// To link configuration to real loaded worlds. // To link configuration to real loaded worlds.
WorldListener worldListener = new WorldListener() { WorldListener worldListener = new WorldListener() {
@Override @Override
@ -230,15 +247,6 @@ public class DynmapPlugin extends JavaPlugin {
} }
}; };
pm.registerEvent(Event.Type.WORLD_LOADED, worldListener, Priority.Monitor, this); pm.registerEvent(Event.Type.WORLD_LOADED, worldListener, Priority.Monitor, this);
// To handle webchat.
PlayerListener playerListener = new DynmapPlayerListener(this);
//getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Monitor, this);
} }
private static File combinePaths(File parent, String path) { private static File combinePaths(File parent, String path) {
@ -315,7 +323,7 @@ public class DynmapPlugin extends JavaPlugin {
} }
} else if (args[0].equals("fullrender")) { } else if (args[0].equals("fullrender")) {
if (player == null || player.isOp()) { if (player == null || player.isOp()) {
if (args.length > 2) { if (args.length > 1) {
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
World w = getServer().getWorld(args[i]); World w = getServer().getWorld(args[i]);
mapManager.renderFullWorld(new Location(w, 0, 0, 0)); mapManager.renderFullWorld(new Location(w, 0, 0, 0));

View File

@ -1,6 +1,7 @@
package org.dynmap.flat; package org.dynmap.flat;
import java.awt.Color; import java.awt.Color;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster; import java.awt.image.WritableRaster;
import java.io.File; import java.io.File;
@ -69,7 +70,10 @@ public class FlatMap extends MapType {
boolean rendered = false; boolean rendered = false;
BufferedImage im = new BufferedImage(t.size, t.size, BufferedImage.TYPE_INT_RGB); BufferedImage im = new BufferedImage(t.size, t.size, BufferedImage.TYPE_INT_RGB);
WritableRaster r = im.getRaster(); WritableRaster raster = im.getRaster();
float[] hsb = new float[4];
int[] pixel = new int[4];
for (int x = 0; x < t.size; x++) for (int x = 0; x < t.size; x++)
for (int y = 0; y < t.size; y++) { for (int y = 0; y < t.size; y++) {
@ -83,10 +87,26 @@ public class FlatMap extends MapType {
Color c = colors[0]; Color c = colors[0];
if (c == null) if (c == null)
continue; continue;
r.setPixel(x, y, new int[] {
c.getRed(),
c.getGreen(), Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), hsb);
c.getBlue() });
float normalheight = 64;
float below = Math.min(my, normalheight) / normalheight;
float above = 1.0f - Math.max(0, my - normalheight) / (128 - normalheight);
// Saturation will be changed when going higher.
hsb[1] *= above;
// Brightness will change when going lower
hsb[2] *= below;
int rgb = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);
pixel[0] = (rgb&0xff0000) >> 16;
pixel[1] = (rgb&0x00ff00) >> 8;
pixel[2] = (rgb&0x0000ff)/* >> 0*/;
raster.setPixel(x, y, pixel);
rendered = true; rendered = true;
} }

View File

@ -2,23 +2,6 @@
* Page setup * Page setup
*/ */
html {
height: 100%
}
body {
height: 100%;
font-family: sans-serif;
font-size: 11px;
color: #fff;
background: #000;
margin: 0px;
padding: 0px ;
}
.dynmap .map .tile img, img { .dynmap .map .tile img, img {
image-rendering: -moz-crisp-edges; image-rendering: -moz-crisp-edges;
-ms-interpolation-mode: nearest-neighbor; -ms-interpolation-mode: nearest-neighbor;
@ -45,8 +28,8 @@ body {
*/ */
#mcmap { #mcmap {
width: 100%; /*width: 100%;
height: 100% height: 100%*/
} }
.dynmap { .dynmap {
@ -540,7 +523,3 @@ body {
top: -3px; top: -3px;
left: 0px; left: 0px;
} }
/* Chat Balloons */
#content { color: #000; }

15
web/embedded_example.css Normal file
View File

@ -0,0 +1,15 @@
/* Embedded into website */
#mcmap {
width: 100%;
height: 500px;
}
.dynmap .sidebar {
width: 140px; /* original width 200px */
margin-right: -143px; /* original margin 203px, sidebar width +2xborder 1px +1px to hide */
}
.dynmap .hitbar {
right: 140px; /* width of sidebar */
}

View File

@ -10,6 +10,8 @@
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<link rel="icon" href="images/dynmap.ico" type="image/ico" /> <link rel="icon" href="images/dynmap.ico" type="image/ico" />
<!--<link rel="stylesheet" type="text/css" href="/map/embedded.css" media="screen" />-->
<link rel="stylesheet" type="text/css" href="standalone.css" media="screen" />
<link rel="stylesheet" type="text/css" href="dynmap_style.css" media="screen" /> <link rel="stylesheet" type="text/css" href="dynmap_style.css" media="screen" />
<!-- <link rel="stylesheet" type="text/css" href="override.css" media="screen" /> --> <!-- <link rel="stylesheet" type="text/css" href="override.css" media="screen" /> -->

View File

@ -195,13 +195,14 @@ DynMap.prototype = {
.appendTo(container); .appendTo(container);
// The chat // The chat
if (me.options.showchat === 'modal') { if (me.options.showchatwindow) {
var chat = me.chat = $('<div/>') var chat = me.chat = $('<div/>')
.addClass('chat') .addClass('chat')
.appendTo(container); .appendTo(container);
var messagelist = me.messagelist = $('<div/>') var messagelist = me.messagelist = $('<div/>')
.addClass('messagelist') .addClass('messagelist')
.appendTo(chat); .appendTo(chat);
if (me.options.allowwebchat) {
var chatinput = me.chatinput = $('<input/>') var chatinput = me.chatinput = $('<input/>')
.addClass('chatinput') .addClass('chatinput')
.attr({ .attr({
@ -218,6 +219,7 @@ DynMap.prototype = {
}) })
.appendTo(chat); .appendTo(chat);
} }
}
// TODO: Enable hash-links. // TODO: Enable hash-links.
/* /*
@ -306,30 +308,22 @@ DynMap.prototype = {
} }
$.each(update.updates, function(index, update) { $.each(update.updates, function(index, update) {
// Only handle updates that are actually new.
if(!me.options.jsonfile || me.lasttimestamp <= update.timestamp) {
swtch(update.type, { swtch(update.type, {
tile: function() { tile: function() {
if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile)
me.onTileUpdated(update.name); me.onTileUpdated(update.name);
}, },
chat: function() { chat: function() {
if (!me.options.showchat) {
return;
}
if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile)
me.onPlayerChat(update.playerName, update.message); me.onPlayerChat(update.playerName, update.message);
}, },
webchat: function() { webchat: function() {
if (!me.options.showchat) {
return;
}
if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile)
me.onPlayerChat('[WEB]' + update.playerName, update.message); me.onPlayerChat('[WEB]' + update.playerName, update.message);
} }
}, function(type) { }, function(type) {
console.log('Unknown type ', type, '!'); console.log('Unknown type ', type, '!');
}); });
}
/* remove older messages from chat*/ /* remove older messages from chat*/
//var timestamp = event.timeStamp; //var timestamp = event.timeStamp;
//var divs = $('div[rel]'); //var divs = $('div[rel]');
@ -369,11 +363,9 @@ DynMap.prototype = {
var d = new Date(); var d = new Date();
var now = d.getTime(); var now = d.getTime();
var popupIndex; var popupIndex;
for (popupIndex in this.chatPopups) for (popupIndex in this.chatPopups) {
{
var popup = this.chatPopups[popupIndex]; var popup = this.chatPopups[popupIndex];
if (now - popup.popupTime > POPUP_LIFE) if (now - popup.popupTime > POPUP_LIFE) {
{
popup.infoWindow.close(); popup.infoWindow.close();
popup.infoWindow = null; popup.infoWindow = null;
delete this.chatPopups[popupIndex]; delete this.chatPopups[popupIndex];
@ -386,9 +378,8 @@ DynMap.prototype = {
var map = me.map; var map = me.map;
var player = me.players[playerName]; var player = me.players[playerName];
var playerMarker = player && player.marker; var playerMarker = player && player.marker;
if (me.options.showchat === 'balloons') { if (me.options.showchatballoons) {
if (playerMarker) if (playerMarker) {
{
var popup = chatPopups[playerName]; var popup = chatPopups[playerName];
if (!popup) { if (!popup) {
popup = { lines: [ message ] }; popup = { lines: [ message ] };
@ -397,14 +388,12 @@ DynMap.prototype = {
} }
var MAX_LINES = 5; var MAX_LINES = 5;
if (popup.lines.length > MAX_LINES) if (popup.lines.length > MAX_LINES) {
{
popup.lines = popup.lines.slice(1); popup.lines = popup.lines.slice(1);
} }
var htmlMessage = '<div id="content"><b>' + playerName + "</b><br/><br/>"; var htmlMessage = '<div id="content"><b>' + playerName + "</b><br/><br/>";
var line; var line;
for (line in popup.lines) for (line in popup.lines) {
{
htmlMessage = htmlMessage + popup.lines[line] + "<br/>"; htmlMessage = htmlMessage + popup.lines[line] + "<br/>";
} }
htmlMessage = htmlMessage + "</div>"; htmlMessage = htmlMessage + "</div>";
@ -421,7 +410,8 @@ DynMap.prototype = {
popup.infoWindow.open(map, playerMarker); popup.infoWindow.open(map, playerMarker);
this.chatPopups[playerName] = popup; this.chatPopups[playerName] = popup;
} }
} else if (me.options.showchat === 'modal') { }
if (me.options.showchatwindow) {
var messagelist = me.messagelist; var messagelist = me.messagelist;
var messageRow = $('<div/>') var messageRow = $('<div/>')
@ -527,7 +517,9 @@ DynMap.prototype = {
.text(player.name) .text(player.name)
) )
.click(function(e) { .click(function(e) {
if (me.followingPlayer !== player) {
me.followPlayer(null); me.followPlayer(null);
}
me.panTo(player.location); me.panTo(player.location);
}) })
.appendTo(me.playerlist); .appendTo(me.playerlist);

37
web/standalone.css Normal file
View File

@ -0,0 +1,37 @@
/* Standalone Document */
html {
width: 100%;
height: 100%
}
body {
height: 100%;
font-family: sans-serif;
font-size: 11px;
color: #fff;
background: #000;
margin: 0px;
padding: 0px ;
}
/* Chat Balloons */
#content { color: #000; }
#mcmap {
width: 100%;
height: 100%;
}
.dynmap .sidebar {
width: 200px; /* original width 200px */
margin-right: -203px; /* original margin 203px, sidebar width +2xborder 1px +1px to hide */
}
.dynmap .hitbar {
right: 200px; /* width of sidebar */
}