From 987e6bcb5463f18b13fc77b68365239724847615 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Thu, 19 May 2011 23:23:50 +0200 Subject: [PATCH] Moved HeroChat code to HeroWebChatModule. --- configuration.txt | 18 ++++----- src/main/java/org/dynmap/ChatEvent.java | 12 ++++++ .../dynmap/ClientConfigurationComponent.java | 3 -- src/main/java/org/dynmap/DynmapPlugin.java | 8 +--- .../org/dynmap/SimpleWebChatComponent.java | 15 ++++++++ .../{ => herochat}/HeroChatHandler.java | 37 ++++++++++--------- .../dynmap/herochat/HeroWebChatComponent.java | 25 +++++++++++++ 7 files changed, 83 insertions(+), 35 deletions(-) create mode 100644 src/main/java/org/dynmap/ChatEvent.java create mode 100644 src/main/java/org/dynmap/SimpleWebChatComponent.java rename src/main/java/org/dynmap/{ => herochat}/HeroChatHandler.java (92%) create mode 100644 src/main/java/org/dynmap/herochat/HeroWebChatComponent.java diff --git a/configuration.txt b/configuration.txt index 3bbb840f..ba469013 100644 --- a/configuration.txt +++ b/configuration.txt @@ -2,6 +2,15 @@ components: - class: org.dynmap.ClientConfigurationComponent + - class: org.dynmap.SimpleWebChatComponent + #- class: org.dynmap.herochat.HeroWebChatComponent + # # Control which HeroChat channel messages from web are directed to + # herochatwebchannel: Global + # # Control which channels are monitored and reported to the web + # herochatchannels: + # - Global + # #- Trade + # #- Haggle - class: org.dynmap.ClientComponent type: chat - class: org.dynmap.ClientComponent @@ -90,15 +99,6 @@ updaterate: 2000 allowchat: true allowwebchat: true webchat-interval: 5 -# Set to true to enable HeroChat support -enableherochat: false -# Control which HeroChat channel messages from web are directed to -herochatwebchannel: Global -# Control which channels are monitored and reported to the web -herochatchannels: - - Global - #- Trade - #- Haggle showplayerfacesinmenu: true diff --git a/src/main/java/org/dynmap/ChatEvent.java b/src/main/java/org/dynmap/ChatEvent.java new file mode 100644 index 00000000..99f0a830 --- /dev/null +++ b/src/main/java/org/dynmap/ChatEvent.java @@ -0,0 +1,12 @@ +package org.dynmap; + +public class ChatEvent { + public String source; + public String name; + public String message; + public ChatEvent(String source, String name, String message) { + this.source = source; + this.name = name; + this.message = message; + } +} diff --git a/src/main/java/org/dynmap/ClientConfigurationComponent.java b/src/main/java/org/dynmap/ClientConfigurationComponent.java index 85f71639..15a37fa6 100644 --- a/src/main/java/org/dynmap/ClientConfigurationComponent.java +++ b/src/main/java/org/dynmap/ClientConfigurationComponent.java @@ -19,9 +19,6 @@ public class ClientConfigurationComponent extends Component { s(t, "allowchat", c.getBoolean("allowchat", true)); s(t, "allowwebchat", c.getBoolean("allowwebchat", true)); s(t, "webchat-interval", c.getFloat("webchat-interval", 5.0f)); - s(t, "enableherochat", c.getBoolean("enableherochat", false)); - s(t, "herochatwebchannel", c.getString("herochatwebchannel", "Global")); - s(t, "herochatchannels", l(c.getStrings("herochatchannels", null))); s(t, "showplayerfacesinmenu", c.getBoolean("showplayerfacesinmenu", true)); s(t, "joinmessage", c.getString("joinmessage", "%playername% joined")); s(t, "quitmessage", c.getString("joinmessage", "%playername% quit")); diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 4f99209b..879e5b53 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -54,7 +54,6 @@ public class DynmapPlugin extends JavaPlugin { public ConfigurationNode configuration; public HashSet enabledTriggers = new HashSet(); public PermissionProvider permissions; - public HeroChatHandler hchand; public ComponentManager componentManager = new ComponentManager(); public Events events = new Events(); @@ -106,8 +105,6 @@ public class DynmapPlugin extends JavaPlugin { timer.scheduleAtFixedRate(new JsonTimerTask(this, configuration), jsonInterval, jsonInterval); } - hchand = new HeroChatHandler(configuration, this, getServer()); - enabledTriggers.clear(); List triggers = configuration.getStrings("render-triggers", new ArrayList()); if (triggers != null) @@ -415,8 +412,7 @@ public class DynmapPlugin extends JavaPlugin { public void webChat(String name, String message) { mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null)); Log.info("[WEB]" + name + ": " + message); - /* Let HeroChat take a look - only broadcast to players if it doesn't handle it */ - if(hchand.sendWebMessageToHeroChat(name, message) == false) - getServer().broadcastMessage("[WEB]" + name + ": " + message); + ChatEvent event = new ChatEvent("web", name, message); + events.trigger("webchat", event); } } diff --git a/src/main/java/org/dynmap/SimpleWebChatComponent.java b/src/main/java/org/dynmap/SimpleWebChatComponent.java new file mode 100644 index 00000000..a8f7e145 --- /dev/null +++ b/src/main/java/org/dynmap/SimpleWebChatComponent.java @@ -0,0 +1,15 @@ +package org.dynmap; + +public class SimpleWebChatComponent extends Component { + + public SimpleWebChatComponent(final DynmapPlugin plugin, ConfigurationNode configuration) { + super(plugin, configuration); + plugin.events.addListener("webchat", new Event.Listener() { + @Override + public void triggered(ChatEvent t) { + plugin.getServer().broadcastMessage("[WEB]" + t.name + ": " + t.message); + } + }); + } + +} diff --git a/src/main/java/org/dynmap/HeroChatHandler.java b/src/main/java/org/dynmap/herochat/HeroChatHandler.java similarity index 92% rename from src/main/java/org/dynmap/HeroChatHandler.java rename to src/main/java/org/dynmap/herochat/HeroChatHandler.java index 8c3ddac7..8474221c 100644 --- a/src/main/java/org/dynmap/HeroChatHandler.java +++ b/src/main/java/org/dynmap/herochat/HeroChatHandler.java @@ -1,4 +1,4 @@ -package org.dynmap; +package org.dynmap.herochat; import java.lang.reflect.Method; import java.util.Collections; @@ -11,6 +11,11 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.ServerListener; import org.bukkit.plugin.Plugin; import java.lang.reflect.Field; +import org.dynmap.Client; +import org.dynmap.ConfigurationNode; +import org.dynmap.DynmapPlugin; +import org.dynmap.Log; +import org.dynmap.Client.ChatMessage; public class HeroChatHandler { private static final String DEF_CHANNEL = "Global"; @@ -239,22 +244,20 @@ public class HeroChatHandler { public HeroChatHandler(ConfigurationNode cfg, DynmapPlugin plugin, Server server) { /* If we're enabling hero chat support */ - if (cfg.getBoolean("enableherochat", false)) { - Log.info("HeroChat support configured"); - this.plugin = plugin; - /* Now, get the monitored channel list */ - hcchannels = cfg.getStrings("herochatchannels", DEF_CHANNELS); - /* And get channel to send web messages */ - hcwebinputchannel = cfg.getString("herochatwebchannel", DEF_CHANNEL); - Plugin hc = server.getPluginManager().getPlugin("HeroChat"); - if(hc != null) { - activateHeroChat(hc); - } - else { - /* Set up to hear when HeroChat is enabled */ - server.getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE, - new OurPluginListener(), Event.Priority.Normal, plugin); - } + Log.info("HeroChat support configured"); + this.plugin = plugin; + /* Now, get the monitored channel list */ + hcchannels = cfg.getStrings("herochatchannels", DEF_CHANNELS); + /* And get channel to send web messages */ + hcwebinputchannel = cfg.getString("herochatwebchannel", DEF_CHANNEL); + Plugin hc = server.getPluginManager().getPlugin("HeroChat"); + if(hc != null) { + activateHeroChat(hc); + } + else { + /* Set up to hear when HeroChat is enabled */ + server.getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE, + new OurPluginListener(), Event.Priority.Normal, plugin); } } diff --git a/src/main/java/org/dynmap/herochat/HeroWebChatComponent.java b/src/main/java/org/dynmap/herochat/HeroWebChatComponent.java new file mode 100644 index 00000000..071e44ef --- /dev/null +++ b/src/main/java/org/dynmap/herochat/HeroWebChatComponent.java @@ -0,0 +1,25 @@ +package org.dynmap.herochat; + +import org.dynmap.ChatEvent; +import org.dynmap.Component; +import org.dynmap.ConfigurationNode; +import org.dynmap.DynmapPlugin; +import org.dynmap.Event; + +public class HeroWebChatComponent extends Component { + HeroChatHandler handler; + public HeroWebChatComponent(final DynmapPlugin plugin, ConfigurationNode configuration) { + super(plugin, configuration); + handler = new HeroChatHandler(configuration, plugin, plugin.getServer()); + plugin.events.addListener("webchat", new Event.Listener() { + @Override + public void triggered(ChatEvent t) { + /* Let HeroChat take a look - only broadcast to players if it doesn't handle it */ + if (!handler.sendWebMessageToHeroChat(t.name, t.message)) { + plugin.getServer().broadcastMessage("[WEB]" + t.name + ": " + t.message); + } + } + }); + } + +}