mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-24 19:25:15 +01:00
Transfered chat/webchat functionality to their components.
This commit is contained in:
parent
e2f0307eeb
commit
5f8c44ee6b
@ -5,11 +5,15 @@ components:
|
||||
|
||||
- class: org.dynmap.InternalClientUpdateComponent
|
||||
sendhealth: true
|
||||
allowwebchat: true
|
||||
webchat-interval: 5
|
||||
#- class: org.dynmap.JsonFileClientUpdateComponent
|
||||
# writeinterval: 1
|
||||
# sendhealth: true
|
||||
# interval: 1
|
||||
# allowwebchat: false
|
||||
|
||||
- class: org.dynmap.SimpleWebChatComponent
|
||||
allowchat: true
|
||||
#- class: org.dynmap.herochat.HeroWebChatComponent
|
||||
# # Control which HeroChat channel messages from web are directed to
|
||||
# herochatwebchannel: Global
|
||||
|
@ -15,13 +15,10 @@ public class ClientConfigurationComponent extends Component {
|
||||
public void triggered(JSONObject t) {
|
||||
ConfigurationNode c = plugin.configuration;
|
||||
s(t, "updaterate", c.getFloat("updaterate", 1.0f));
|
||||
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, "showplayerfacesinmenu", c.getBoolean("showplayerfacesinmenu", true));
|
||||
s(t, "joinmessage", c.getString("joinmessage", "%playername% joined"));
|
||||
s(t, "quitmessage", c.getString("joinmessage", "%playername% quit"));
|
||||
s(t, "spammessage", c.getString("joinmessage", "You may only chat once every %interval% seconds."));
|
||||
s(t, "quitmessage", c.getString("quitmessage", "%playername% quit"));
|
||||
s(t, "spammessage", c.getString("spammessage", "You may only chat once every %interval% seconds."));
|
||||
|
||||
for(ConfigurationNode wn : plugin.configuration.getNodes("worlds")) {
|
||||
DynmapWorld world = plugin.mapManager.getWorld(wn.getString("name"));
|
||||
|
@ -141,21 +141,6 @@ public class DynmapPlugin extends JavaPlugin {
|
||||
webServer.handlers.put("/", new FilesystemHandler(getFile(configuration.getString("webpath", "web"))));
|
||||
webServer.handlers.put("/tiles/", new FilesystemHandler(tilesDirectory));
|
||||
webServer.handlers.put("/up/configuration", new ClientConfigurationHandler(this));
|
||||
|
||||
if (configuration.getBoolean("allowwebchat", false)) {
|
||||
SendMessageHandler messageHandler = new SendMessageHandler() {{
|
||||
maximumMessageInterval = (configuration.getInteger("webchat-interval", 1) * 1000);
|
||||
spamMessage = "\""+configuration.getString("spammessage", "You may only chat once every %interval% seconds.")+"\"";
|
||||
onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() {
|
||||
@Override
|
||||
public void triggered(Message t) {
|
||||
webChat(t.name, t.message);
|
||||
}
|
||||
});
|
||||
}};
|
||||
|
||||
webServer.handlers.put("/up/sendmessage", messageHandler);
|
||||
}
|
||||
}
|
||||
|
||||
public void startWebserver() {
|
||||
@ -245,17 +230,6 @@ public class DynmapPlugin extends JavaPlugin {
|
||||
//if (isTrigger("chunkgenerated")) pm.registerEvent(Event.Type.CHUNK_GENERATED, renderTrigger, Priority.Monitor, this);
|
||||
}
|
||||
|
||||
// To announce when players have joined/quit/chatted.
|
||||
if (configuration.getBoolean("allowchat", false)) {
|
||||
// To handle webchat.
|
||||
PlayerListener playerListener = new DynmapPlayerChatListener(this);
|
||||
//getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(org.bukkit.event.Event.Type.PLAYER_CHAT, playerListener, org.bukkit.event.Event.Priority.Monitor, this);
|
||||
pm.registerEvent(org.bukkit.event.Event.Type.PLAYER_LOGIN, playerListener, org.bukkit.event.Event.Priority.Monitor, this);
|
||||
pm.registerEvent(org.bukkit.event.Event.Type.PLAYER_JOIN, playerListener, org.bukkit.event.Event.Priority.Monitor, this);
|
||||
pm.registerEvent(org.bukkit.event.Event.Type.PLAYER_QUIT, playerListener, org.bukkit.event.Event.Priority.Monitor, this);
|
||||
}
|
||||
|
||||
// To link configuration to real loaded worlds.
|
||||
WorldListener worldListener = new WorldListener() {
|
||||
@Override
|
||||
@ -381,11 +355,4 @@ public class DynmapPlugin extends JavaPlugin {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void webChat(String name, String message) {
|
||||
mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null));
|
||||
Log.info("[WEB]" + name + ": " + message);
|
||||
ChatEvent event = new ChatEvent("web", name, message);
|
||||
events.trigger("webchat", event);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,51 @@
|
||||
package org.dynmap;
|
||||
|
||||
import org.dynmap.Event.Listener;
|
||||
import org.dynmap.web.handlers.ClientUpdateHandler;
|
||||
import org.dynmap.web.handlers.SendMessageHandler;
|
||||
import org.dynmap.web.handlers.SendMessageHandler.Message;
|
||||
import org.json.simple.JSONObject;
|
||||
import static org.dynmap.JSONUtils.*;
|
||||
|
||||
public class InternalClientUpdateComponent extends ClientUpdateComponent {
|
||||
|
||||
public InternalClientUpdateComponent(DynmapPlugin plugin, ConfigurationNode configuration) {
|
||||
public InternalClientUpdateComponent(DynmapPlugin plugin, final ConfigurationNode configuration) {
|
||||
super(plugin, configuration);
|
||||
plugin.webServer.handlers.put("/up/", new ClientUpdateHandler(plugin));
|
||||
}
|
||||
final Boolean allowwebchat = configuration.getBoolean("allowwebchat", false);
|
||||
final float webchatInterval = configuration.getFloat("webchat-interval", 1);
|
||||
final String spammessage = plugin.configuration.getString("spammessage", "You may only chat once every %interval% seconds.");
|
||||
|
||||
plugin.events.addListener("buildclientconfiguration", new Event.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void triggered(JSONObject t) {
|
||||
s(t, "allowwebchat", allowwebchat);
|
||||
s(t, "webchat-interval", webchatInterval);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.webServer.handlers.put("/up/", new ClientUpdateHandler(plugin));
|
||||
|
||||
if (allowwebchat) {
|
||||
SendMessageHandler messageHandler = new SendMessageHandler() {{
|
||||
maximumMessageInterval = (int)(webchatInterval * 1000);
|
||||
spamMessage = "\""+spammessage+"\"";
|
||||
onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() {
|
||||
@Override
|
||||
public void triggered(Message t) {
|
||||
webChat(t.name, t.message);
|
||||
}
|
||||
});
|
||||
}};
|
||||
|
||||
plugin.webServer.handlers.put("/up/sendmessage", messageHandler);
|
||||
}
|
||||
}
|
||||
|
||||
protected void webChat(String name, String message) {
|
||||
// TODO: Change null to something meaningful.
|
||||
plugin.mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null));
|
||||
Log.info("[WEB]" + name + ": " + message);
|
||||
ChatEvent event = new ChatEvent("web", name, message);
|
||||
plugin.events.trigger("webchat", event);
|
||||
}
|
||||
}
|
||||
|
@ -26,13 +26,16 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
|
||||
protected long jsonInterval;
|
||||
protected long lastTimestamp = 0;
|
||||
protected JSONParser parser = new JSONParser();
|
||||
public JsonFileClientUpdateComponent(final DynmapPlugin plugin, ConfigurationNode configuration) {
|
||||
public JsonFileClientUpdateComponent(final DynmapPlugin plugin, final ConfigurationNode configuration) {
|
||||
super(plugin, configuration);
|
||||
jsonInterval = (long)(configuration.getFloat("interval", 1) * 1000);
|
||||
jsonInterval = (long)(configuration.getFloat("writeinterval", 1) * 1000);
|
||||
task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
writeUpdates();
|
||||
if (configuration.getBoolean("allowwebchat", false)) {
|
||||
handleWebChat();
|
||||
}
|
||||
}
|
||||
};
|
||||
timer = new Timer();
|
||||
@ -132,10 +135,20 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
|
||||
while (iter.hasNext()) {
|
||||
JSONObject o = (JSONObject) iter.next();
|
||||
if (Long.parseLong(String.valueOf(o.get("timestamp"))) >= (lastTimestamp)) {
|
||||
plugin.webChat(String.valueOf(o.get("name")), String.valueOf(o.get("message")));
|
||||
String name = String.valueOf(o.get("name"));
|
||||
String message = String.valueOf(o.get("message"));
|
||||
webChat(name, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void webChat(String name, String message) {
|
||||
// TODO: Change null to something meaningful.
|
||||
plugin.mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null));
|
||||
Log.info("[WEB]" + name + ": " + message);
|
||||
ChatEvent event = new ChatEvent("web", name, message);
|
||||
plugin.events.trigger("webchat", event);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,17 @@
|
||||
package org.dynmap;
|
||||
|
||||
import static org.dynmap.JSONUtils.s;
|
||||
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class SimpleWebChatComponent extends Component {
|
||||
|
||||
public SimpleWebChatComponent(final DynmapPlugin plugin, ConfigurationNode configuration) {
|
||||
public SimpleWebChatComponent(final DynmapPlugin plugin, final ConfigurationNode configuration) {
|
||||
super(plugin, configuration);
|
||||
plugin.events.addListener("webchat", new Event.Listener<ChatEvent>() {
|
||||
@Override
|
||||
@ -10,6 +19,40 @@ public class SimpleWebChatComponent extends Component {
|
||||
plugin.getServer().broadcastMessage("[WEB]" + t.name + ": " + t.message);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.events.addListener("buildclientconfiguration", new Event.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void triggered(JSONObject t) {
|
||||
s(t, "allowchat", configuration.getBoolean("allowchat", false));
|
||||
}
|
||||
});
|
||||
|
||||
if (configuration.getBoolean("allowchat", false)) {
|
||||
PlayerChatListener playerListener = new PlayerChatListener();
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
pm.registerEvent(org.bukkit.event.Event.Type.PLAYER_CHAT, playerListener, org.bukkit.event.Event.Priority.Monitor, plugin);
|
||||
pm.registerEvent(org.bukkit.event.Event.Type.PLAYER_LOGIN, playerListener, org.bukkit.event.Event.Priority.Monitor, plugin);
|
||||
pm.registerEvent(org.bukkit.event.Event.Type.PLAYER_JOIN, playerListener, org.bukkit.event.Event.Priority.Monitor, plugin);
|
||||
pm.registerEvent(org.bukkit.event.Event.Type.PLAYER_QUIT, playerListener, org.bukkit.event.Event.Priority.Monitor, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
protected class PlayerChatListener extends PlayerListener {
|
||||
@Override
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
plugin.mapManager.pushUpdate(new Client.ChatMessage("player", "", event.getPlayer().getDisplayName(), event.getMessage(), event.getPlayer().getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
plugin.mapManager.pushUpdate(new Client.PlayerJoinMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
plugin.mapManager.pushUpdate(new Client.PlayerQuitMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ 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";
|
||||
|
@ -1,10 +1,18 @@
|
||||
package org.dynmap.herochat;
|
||||
|
||||
import static org.dynmap.JSONUtils.s;
|
||||
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.dynmap.ChatEvent;
|
||||
import org.dynmap.Client;
|
||||
import org.dynmap.Component;
|
||||
import org.dynmap.ConfigurationNode;
|
||||
import org.dynmap.DynmapPlugin;
|
||||
import org.dynmap.Event;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class HeroWebChatComponent extends Component {
|
||||
HeroChatHandler handler;
|
||||
@ -20,6 +28,31 @@ public class HeroWebChatComponent extends Component {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.events.addListener("buildclientconfiguration", new Event.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void triggered(JSONObject t) {
|
||||
s(t, "allowchat", true);
|
||||
}
|
||||
});
|
||||
|
||||
// Also make HeroChat announce joins and quits.
|
||||
PlayerChatListener playerListener = new PlayerChatListener();
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
pm.registerEvent(org.bukkit.event.Event.Type.PLAYER_LOGIN, playerListener, org.bukkit.event.Event.Priority.Monitor, plugin);
|
||||
pm.registerEvent(org.bukkit.event.Event.Type.PLAYER_JOIN, playerListener, org.bukkit.event.Event.Priority.Monitor, plugin);
|
||||
pm.registerEvent(org.bukkit.event.Event.Type.PLAYER_QUIT, playerListener, org.bukkit.event.Event.Priority.Monitor, plugin);
|
||||
}
|
||||
|
||||
protected class PlayerChatListener extends PlayerListener {
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
plugin.mapManager.pushUpdate(new Client.PlayerJoinMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
plugin.mapManager.pushUpdate(new Client.PlayerQuitMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user