Transfered chat/webchat functionality to their components.
This commit is contained in:
parent
e2f0307eeb
commit
5f8c44ee6b
8 changed files with 142 additions and 47 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue