diff --git a/configuration.txt b/configuration.txt old mode 100755 new mode 100644 index 10d54410..8b7fbc11 --- a/configuration.txt +++ b/configuration.txt @@ -67,13 +67,16 @@ web: # Interval the browser should poll for updates. updaterate: 2000 - # showchat: modal/balloons - showchat: modal + showchatballoons: false + focuschatballoons: false + + showchatwindow: true + allowwebchat: true messagettl: 15000 showplayerfacesonmap: true showplayerfacesinmenu: true - focuschatballoons: false + joinmessage: "%playername% joined" quitmessage: "%playername% quit" diff --git a/src/main/java/org/dynmap/DynmapPlayerListener.java b/src/main/java/org/dynmap/DynmapPlayerChatListener.java similarity index 90% rename from src/main/java/org/dynmap/DynmapPlayerListener.java rename to src/main/java/org/dynmap/DynmapPlayerChatListener.java index 0dab13da..08fee3fd 100644 --- a/src/main/java/org/dynmap/DynmapPlayerListener.java +++ b/src/main/java/org/dynmap/DynmapPlayerChatListener.java @@ -4,10 +4,10 @@ import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerListener; -public class DynmapPlayerListener extends PlayerListener { +public class DynmapPlayerChatListener extends PlayerListener { DynmapPlugin plugin; - public DynmapPlayerListener(DynmapPlugin plugin) { + public DynmapPlayerChatListener(DynmapPlugin plugin) { this.plugin = plugin; } diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 8ac9f555..c18c8f6c 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -16,14 +16,12 @@ import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.block.BlockDamageLevel; 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.BlockBreakEvent; -import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerEvent; @@ -75,12 +73,12 @@ public class DynmapPlugin extends JavaPlugin { public void onEnable() { dataDirectory = this.getDataFolder(); - + configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt")); configuration.load(); loadDebuggers(); - + tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles")); if (!tilesDirectory.isDirectory() && !tilesDirectory.mkdirs()) { log.warning("Could not create directory for tiles ('" + tilesDirectory + "')."); @@ -131,16 +129,18 @@ public class DynmapPlugin extends JavaPlugin { 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() { - @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); + if (configuration.getNode("web").getBoolean("allowwebchat", false)) { + SendMessageHandler messageHandler = new SendMessageHandler(); + messageHandler.onMessageReceived.addListener(new Listener() { + @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(); @@ -167,11 +167,11 @@ public class DynmapPlugin extends JavaPlugin { public boolean isTrigger(String s) { return enabledTriggers.contains(s); } - + public void registerEvents() { final PluginManager pm = getServer().getPluginManager(); final MapManager mm = mapManager; - + // To trigger rendering. { BlockListener renderTrigger = new BlockListener() { @@ -185,8 +185,10 @@ public class DynmapPlugin extends JavaPlugin { mm.touch(event.getBlock().getLocation()); } }; - if (isTrigger("blockplaced")) pm.registerEvent(Event.Type.BLOCK_PLACED, renderTrigger, Priority.Monitor, this); - if (isTrigger("blockbreak")) pm.registerEvent(Event.Type.BLOCK_BREAK, renderTrigger, Priority.Monitor, this); + if (isTrigger("blockplaced")) + 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() { @@ -194,13 +196,16 @@ public class DynmapPlugin extends JavaPlugin { public void onPlayerJoin(PlayerEvent event) { mm.touch(event.getPlayer().getLocation()); } + @Override public void onPlayerMove(PlayerMoveEvent event) { mm.touch(event.getPlayer().getLocation()); } }; - if (isTrigger("playerjoin")) pm.registerEvent(Event.Type.PLAYER_JOIN, renderTrigger, Priority.Monitor, this); - if (isTrigger("playermove")) pm.registerEvent(Event.Type.PLAYER_MOVE, renderTrigger, Priority.Monitor, this); + if (isTrigger("playerjoin")) + 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() { @@ -210,18 +215,30 @@ public class DynmapPlugin extends JavaPlugin { int z = event.getChunk().getZ() * 16 + 8; mm.touch(new Location(event.getWorld(), x, 127, z)); } - - /*@Override - public void onChunkGenerated(ChunkLoadEvent event) { - int x = event.getChunk().getX() * 16 + 8; - int z = event.getChunk().getZ() * 16 + 8; - mm.touch(new Location(event.getWorld(), x, 127, z)); - }*/ + + /* + * @Override public void onChunkGenerated(ChunkLoadEvent event) + * { int x = event.getChunk().getX() * 16 + 8; int z = + * event.getChunk().getZ() * 16 + 8; mm.touch(new + * 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); } - + + // 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. WorldListener worldListener = new WorldListener() { @Override @@ -230,15 +247,6 @@ public class DynmapPlugin extends JavaPlugin { } }; 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) { @@ -315,7 +323,7 @@ public class DynmapPlugin extends JavaPlugin { } } else if (args[0].equals("fullrender")) { if (player == null || player.isOp()) { - if (args.length > 2) { + if (args.length > 1) { for (int i = 1; i < args.length; i++) { World w = getServer().getWorld(args[i]); mapManager.renderFullWorld(new Location(w, 0, 0, 0)); diff --git a/src/main/java/org/dynmap/flat/FlatMap.java b/src/main/java/org/dynmap/flat/FlatMap.java index a0adc02a..5cd52d54 100644 --- a/src/main/java/org/dynmap/flat/FlatMap.java +++ b/src/main/java/org/dynmap/flat/FlatMap.java @@ -1,6 +1,7 @@ package org.dynmap.flat; import java.awt.Color; +import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; import java.awt.image.WritableRaster; import java.io.File; @@ -69,7 +70,10 @@ public class FlatMap extends MapType { boolean rendered = false; 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 y = 0; y < t.size; y++) { @@ -83,10 +87,26 @@ public class FlatMap extends MapType { Color c = colors[0]; if (c == null) continue; - r.setPixel(x, y, new int[] { - c.getRed(), - c.getGreen(), - c.getBlue() }); + + + Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), hsb); + + 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; } diff --git a/web/dynmap_style.css b/web/dynmap_style.css index 0f9c88ff..a91166c5 100644 --- a/web/dynmap_style.css +++ b/web/dynmap_style.css @@ -2,23 +2,6 @@ * 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 { image-rendering: -moz-crisp-edges; -ms-interpolation-mode: nearest-neighbor; @@ -45,8 +28,8 @@ body { */ #mcmap { - width: 100%; - height: 100% + /*width: 100%; + height: 100%*/ } .dynmap { @@ -539,8 +522,4 @@ body { position: relative; top: -3px; left: 0px; -} - -/* Chat Balloons */ - -#content { color: #000; } \ No newline at end of file +} \ No newline at end of file diff --git a/web/embedded_example.css b/web/embedded_example.css new file mode 100644 index 00000000..84ff3806 --- /dev/null +++ b/web/embedded_example.css @@ -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 */ +} \ No newline at end of file diff --git a/web/index.html b/web/index.html index 6f57c402..6fa6557f 100644 --- a/web/index.html +++ b/web/index.html @@ -10,6 +10,8 @@ + + diff --git a/web/map.js b/web/map.js index 326bf977..5d6c33d8 100644 --- a/web/map.js +++ b/web/map.js @@ -195,28 +195,30 @@ DynMap.prototype = { .appendTo(container); // The chat - if (me.options.showchat === 'modal') { + if (me.options.showchatwindow) { var chat = me.chat = $('
') .addClass('chat') .appendTo(container); var messagelist = me.messagelist = $('
') .addClass('messagelist') .appendTo(chat); - var chatinput = me.chatinput = $('') - .addClass('chatinput') - .attr({ - id: 'chatinput', - type: 'text', - value: '' - }) - .keydown(function(event) { - if (event.keyCode == '13') { - event.preventDefault(); - sendChat(chatinput.val()); - chatinput.val(''); - } - }) - .appendTo(chat); + if (me.options.allowwebchat) { + var chatinput = me.chatinput = $('') + .addClass('chatinput') + .attr({ + id: 'chatinput', + type: 'text', + value: '' + }) + .keydown(function(event) { + if (event.keyCode == '13') { + event.preventDefault(); + sendChat(chatinput.val()); + chatinput.val(''); + } + }) + .appendTo(chat); + } } // TODO: Enable hash-links. @@ -306,30 +308,22 @@ DynMap.prototype = { } $.each(update.updates, function(index, update) { - swtch(update.type, { - tile: function() { - - if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile) + // Only handle updates that are actually new. + if(!me.options.jsonfile || me.lasttimestamp <= update.timestamp) { + swtch(update.type, { + tile: function() { me.onTileUpdated(update.name); - }, - chat: function() { - if (!me.options.showchat) { - return; - } - if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile) + }, + chat: function() { me.onPlayerChat(update.playerName, update.message); - }, - webchat: function() { - if (!me.options.showchat) { - return; - } - - if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile) + }, + webchat: function() { me.onPlayerChat('[WEB]' + update.playerName, update.message); - } - }, function(type) { - console.log('Unknown type ', type, '!'); - }); + } + }, function(type) { + console.log('Unknown type ', type, '!'); + }); + } /* remove older messages from chat*/ //var timestamp = event.timeStamp; //var divs = $('div[rel]'); @@ -369,11 +363,9 @@ DynMap.prototype = { var d = new Date(); var now = d.getTime(); var popupIndex; - for (popupIndex in this.chatPopups) - { + for (popupIndex in this.chatPopups) { var popup = this.chatPopups[popupIndex]; - if (now - popup.popupTime > POPUP_LIFE) - { + if (now - popup.popupTime > POPUP_LIFE) { popup.infoWindow.close(); popup.infoWindow = null; delete this.chatPopups[popupIndex]; @@ -386,9 +378,8 @@ DynMap.prototype = { var map = me.map; var player = me.players[playerName]; var playerMarker = player && player.marker; - if (me.options.showchat === 'balloons') { - if (playerMarker) - { + if (me.options.showchatballoons) { + if (playerMarker) { var popup = chatPopups[playerName]; if (!popup) { popup = { lines: [ message ] }; @@ -397,14 +388,12 @@ DynMap.prototype = { } var MAX_LINES = 5; - if (popup.lines.length > MAX_LINES) - { + if (popup.lines.length > MAX_LINES) { popup.lines = popup.lines.slice(1); } var htmlMessage = '
' + playerName + "

"; var line; - for (line in popup.lines) - { + for (line in popup.lines) { htmlMessage = htmlMessage + popup.lines[line] + "
"; } htmlMessage = htmlMessage + "
"; @@ -421,7 +410,8 @@ DynMap.prototype = { popup.infoWindow.open(map, playerMarker); this.chatPopups[playerName] = popup; } - } else if (me.options.showchat === 'modal') { + } + if (me.options.showchatwindow) { var messagelist = me.messagelist; var messageRow = $('
') @@ -527,7 +517,9 @@ DynMap.prototype = { .text(player.name) ) .click(function(e) { - me.followPlayer(null); + if (me.followingPlayer !== player) { + me.followPlayer(null); + } me.panTo(player.location); }) .appendTo(me.playerlist); diff --git a/web/standalone.css b/web/standalone.css new file mode 100644 index 00000000..a7031590 --- /dev/null +++ b/web/standalone.css @@ -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 */ +} \ No newline at end of file