From bbb5db35244198d8d32e536e84163f57f7e50f0f Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Mon, 14 Nov 2011 14:08:24 +0800 Subject: [PATCH] Add cyrillic-support option for cyrillic codepage hack --- .../dynmap/ClientConfigurationComponent.java | 1 + src/main/resources/configuration.txt | 3 +++ web/js/chatballoon.js | 2 +- web/js/chatbox.js | 2 +- web/js/minecraft.js | 21 +++++++++++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dynmap/ClientConfigurationComponent.java b/src/main/java/org/dynmap/ClientConfigurationComponent.java index 6ad5de40..b5152d81 100644 --- a/src/main/java/org/dynmap/ClientConfigurationComponent.java +++ b/src/main/java/org/dynmap/ClientConfigurationComponent.java @@ -23,6 +23,7 @@ public class ClientConfigurationComponent extends Component { s(t, "defaultzoom", c.getInteger("defaultzoom", 0)); s(t, "sidebaropened", c.getString("sidebaropened", "false")); s(t, "dynmapversion", plugin.getDescription().getVersion()); + s(t, "cyrillic", c.getBoolean("cyrillic-support", false)); DynmapWorld defaultWorld = null; String defmap = null; diff --git a/src/main/resources/configuration.txt b/src/main/resources/configuration.txt index aef07993..d6b99e73 100644 --- a/src/main/resources/configuration.txt +++ b/src/main/resources/configuration.txt @@ -369,6 +369,9 @@ defaultzoom: 0 defaultworld: world defaultmap: flat +# Option to enable workaround for incorrectly encoded unicode in Cyrillic MC/Bukkit (not good for other code pages) +#cyrillic-support: true + # NOTE: the 'templates' section is now found in the 'templates' directory # Templates CAN still be defined in configuration.txt, as before 0.20 templates: diff --git a/web/js/chatballoon.js b/web/js/chatballoon.js index c0bf8c49..0155fe81 100644 --- a/web/js/chatballoon.js +++ b/web/js/chatballoon.js @@ -43,7 +43,7 @@ componentconstructors['chatballoon'] = function(dynmap, configuration) { } // Add line to balloon. - $('
').addClass('balloonmessage').text(message.text).appendTo(popup.content); + $('
').addClass('balloonmessage').text(chat_encoder(message)).appendTo(popup.content); // Remove older lines when too many messages are shown. var children = $(popup.content).children(); diff --git a/web/js/chatbox.js b/web/js/chatbox.js index ab7b1d53..7db4c446 100644 --- a/web/js/chatbox.js +++ b/web/js/chatbox.js @@ -104,7 +104,7 @@ componentconstructors['chatbox'] = function(dynmap, configuration) { var playerMessageContainer = $('') .addClass('messagetext') - .text(message.text); + .text(chat_encoder(message)); messageRow.append(playerIconContainer,playerChannelContainer,playerNameContainer,playerMessageContainer); addrow(messageRow); diff --git a/web/js/minecraft.js b/web/js/minecraft.js index fabe2867..588d450c 100644 --- a/web/js/minecraft.js +++ b/web/js/minecraft.js @@ -31,3 +31,24 @@ function getMinecraftTime(servertime) { night: !day }; } + +function chat_encoder(message) { + if (dynmap.options.cyrillic) { + if(message.source === 'player') { + var utftext = ""; + for (var n = 0; n < message.text.length; n++) { + var c = message.text.charCodeAt(n); + if (c >= 192) { + var c = message.text.charCodeAt(n); + utftext += String.fromCharCode(c+848); + } + else if (c == 184) { utftext += String.fromCharCode(1105); } + else { + utftext += String.fromCharCode(c); + } + } + return utftext + } + } + return message.text; +} \ No newline at end of file