mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-25 03:35:18 +01:00
Add cancelable custom event for reporting of messages received from web
This commit is contained in:
parent
88fde1fcd6
commit
f4e9b8ffce
31
src/main/java/org/dynmap/DynmapWebChatEvent.java
Normal file
31
src/main/java/org/dynmap/DynmapWebChatEvent.java
Normal file
@ -0,0 +1,31 @@
|
||||
package org.dynmap;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
/**
|
||||
* Custom bukkit event, corresponding to the receiving of a web-chat message from a web UI user
|
||||
*/
|
||||
public class DynmapWebChatEvent extends Event implements Cancellable {
|
||||
private String source;
|
||||
private String name;
|
||||
private String message;
|
||||
private boolean cancelled;
|
||||
|
||||
public DynmapWebChatEvent(String source, String name, String message) {
|
||||
super("org.dynmap.DynmapWebChatEvent");
|
||||
this.source = source;
|
||||
this.name = name;
|
||||
this.message = message;
|
||||
this.cancelled = false;
|
||||
}
|
||||
public boolean isCancelled() { return cancelled; }
|
||||
|
||||
public void setCancelled(boolean cancel) { cancelled = cancel; }
|
||||
|
||||
public String getSource() { return source; }
|
||||
|
||||
public String getName() { return name; }
|
||||
|
||||
public String getMessage() { return message; }
|
||||
|
||||
}
|
@ -16,7 +16,10 @@ public class SimpleWebChatComponent extends Component {
|
||||
plugin.events.addListener("webchat", new Event.Listener<ChatEvent>() {
|
||||
@Override
|
||||
public void triggered(ChatEvent t) {
|
||||
plugin.getServer().broadcastMessage(plugin.configuration.getString("webprefix", "\u00A72[WEB] ") + t.name + ": " + plugin.configuration.getString("websuffix", "\u00A7f") + t.message);
|
||||
DynmapWebChatEvent evt = new DynmapWebChatEvent(t.source, t.name, t.message);
|
||||
plugin.getServer().getPluginManager().callEvent(evt);
|
||||
if(evt.isCancelled() == false)
|
||||
plugin.getServer().broadcastMessage(plugin.configuration.getString("webprefix", "\u00A72[WEB] ") + t.name + ": " + plugin.configuration.getString("websuffix", "\u00A7f") + t.message);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -11,6 +11,7 @@ import org.dynmap.Client;
|
||||
import org.dynmap.Component;
|
||||
import org.dynmap.ConfigurationNode;
|
||||
import org.dynmap.DynmapPlugin;
|
||||
import org.dynmap.DynmapWebChatEvent;
|
||||
import org.dynmap.Event;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@ -22,9 +23,13 @@ public class HeroWebChatComponent extends Component {
|
||||
plugin.events.addListener("webchat", new Event.Listener<ChatEvent>() {
|
||||
@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(plugin.configuration.getString("webprefix", "\u00A72[WEB] ") + t.name + ": " + plugin.configuration.getString("websuffix", "\u00A7f") + t.message);
|
||||
DynmapWebChatEvent evt = new DynmapWebChatEvent(t.source, t.name, t.message);
|
||||
plugin.getServer().getPluginManager().callEvent(evt);
|
||||
if(evt.isCancelled() == false) {
|
||||
/* 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(plugin.configuration.getString("webprefix", "\u00A72[WEB] ") + t.name + ": " + plugin.configuration.getString("websuffix", "\u00A7f") + t.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user