mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 05:05:16 +01:00
Remove HeroChat code - HeroChat 4 API doesn't work as of 1.1-R5
This commit is contained in:
parent
0c9057949d
commit
fa80af8e81
@ -1,305 +0,0 @@
|
|||||||
package org.dynmap.herochat;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.event.CustomEventListener;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
|
||||||
import org.bukkit.event.server.ServerListener;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.dynmap.Client;
|
|
||||||
import org.dynmap.ConfigurationNode;
|
|
||||||
import org.dynmap.DynmapCore;
|
|
||||||
import org.dynmap.Log;
|
|
||||||
import org.dynmap.bukkit.DynmapPlugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bukkit specific module - alternate chat handler for interfacing with HeroChat
|
|
||||||
*/
|
|
||||||
public class HeroChatHandler {
|
|
||||||
private static final String DEF_CHANNEL = "Global";
|
|
||||||
private static final List<String> DEF_CHANNELS = Collections
|
|
||||||
.singletonList(DEF_CHANNEL);
|
|
||||||
|
|
||||||
private List<String> hcchannels;
|
|
||||||
private String hcwebinputchannel;
|
|
||||||
private DynmapCore core;
|
|
||||||
private HeroChatChannel hcwebinputchan;
|
|
||||||
|
|
||||||
private class OurPluginListener implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginEnable(PluginEnableEvent event) {
|
|
||||||
Plugin plugin = event.getPlugin();
|
|
||||||
String name = plugin.getDescription().getName();
|
|
||||||
|
|
||||||
if (name.equals("HeroChat")) {
|
|
||||||
activateHeroChat(plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reflection-based access wrapper for ChannelChatEvent from HeroChat */
|
|
||||||
private static class HeroChatChannelChatEvent {
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
private static Class channelchatevent;
|
|
||||||
private static Method getsource;
|
|
||||||
private static Method getmessage;
|
|
||||||
private static Method issentbyplayer;
|
|
||||||
private static boolean isgood = false;
|
|
||||||
private Event evt;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean initialize() {
|
|
||||||
try {
|
|
||||||
channelchatevent = Class
|
|
||||||
.forName("com.herocraftonline.dthielke.herochat.event.ChannelChatEvent");
|
|
||||||
getsource = channelchatevent.getMethod("getSource", new Class[0]);
|
|
||||||
getmessage = channelchatevent.getMethod("getMessage", new Class[0]);
|
|
||||||
issentbyplayer = channelchatevent.getMethod("isSentByPlayer", new Class[0]);
|
|
||||||
isgood = true;
|
|
||||||
} catch (ClassNotFoundException cnfx) {
|
|
||||||
} catch (NoSuchMethodException nsmx) {
|
|
||||||
}
|
|
||||||
return isgood;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HeroChatChannelChatEvent(Event evt) {
|
|
||||||
this.evt = evt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isInstance(Event evt) {
|
|
||||||
return channelchatevent.isInstance(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSource() {
|
|
||||||
try {
|
|
||||||
return (String) getsource.invoke(evt);
|
|
||||||
} catch (Exception x) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
try {
|
|
||||||
return (String) getmessage.invoke(evt);
|
|
||||||
} catch (Exception x) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSentByPlayer() {
|
|
||||||
try {
|
|
||||||
return (Boolean) issentbyplayer.invoke(evt);
|
|
||||||
} catch (Exception x) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reflection-based access wrapper for ChannelEvent from HeroChat */
|
|
||||||
private static class HeroChatChannelEvent {
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
private static Class channelevent;
|
|
||||||
private static Method getchannel;
|
|
||||||
private static Method iscancelled;
|
|
||||||
private static boolean isgood = false;
|
|
||||||
private Event evt;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean initialize() {
|
|
||||||
try {
|
|
||||||
channelevent = Class
|
|
||||||
.forName("com.herocraftonline.dthielke.herochat.event.ChannelEvent");
|
|
||||||
getchannel = channelevent.getMethod("getChannel", new Class[0]);
|
|
||||||
iscancelled = channelevent.getMethod("isCancelled", new Class[0]);
|
|
||||||
isgood = true;
|
|
||||||
} catch (ClassNotFoundException cnfx) {
|
|
||||||
} catch (NoSuchMethodException nsmx) {
|
|
||||||
}
|
|
||||||
return isgood;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HeroChatChannelEvent(Event evt) {
|
|
||||||
this.evt = evt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isInstance(Event evt) {
|
|
||||||
return channelevent.isInstance(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
public HeroChatChannel getChannel() {
|
|
||||||
try {
|
|
||||||
Object o;
|
|
||||||
o = getchannel.invoke(evt);
|
|
||||||
if (o != null) {
|
|
||||||
return new HeroChatChannel(o);
|
|
||||||
}
|
|
||||||
} catch (Exception x) {
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCancelled() {
|
|
||||||
try {
|
|
||||||
return (Boolean) iscancelled.invoke(evt);
|
|
||||||
} catch (Exception x) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reflection-based access wrapper for Channel from HeroChat */
|
|
||||||
private static class HeroChatChannel {
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
private static Class channel;
|
|
||||||
private static Method getname;
|
|
||||||
private static Method getnick;
|
|
||||||
private static Method sendmessage;
|
|
||||||
private static boolean isgood = false;
|
|
||||||
private Object chan;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean initialize() {
|
|
||||||
try {
|
|
||||||
channel = Class
|
|
||||||
.forName("com.herocraftonline.dthielke.herochat.channels.Channel");
|
|
||||||
getname = channel.getMethod("getName");
|
|
||||||
getnick = channel.getMethod("getNick", new Class[0]);
|
|
||||||
sendmessage = channel.getMethod("sendMessage", new Class[] {
|
|
||||||
String.class, String.class, String.class, boolean.class } );
|
|
||||||
isgood = true;
|
|
||||||
} catch (ClassNotFoundException cnfx) {
|
|
||||||
} catch (NoSuchMethodException nsmx) {
|
|
||||||
Log.severe(nsmx);
|
|
||||||
}
|
|
||||||
return isgood;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HeroChatChannel(Object chan) {
|
|
||||||
this.chan = chan;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
try {
|
|
||||||
return (String) getname.invoke(chan);
|
|
||||||
} catch (Exception x) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNick() {
|
|
||||||
try {
|
|
||||||
return (String) getnick.invoke(chan);
|
|
||||||
} catch (Exception x) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(String source, String msg, String format, boolean sentByPlayer) {
|
|
||||||
try {
|
|
||||||
sendmessage.invoke(chan, source, msg, format, sentByPlayer);
|
|
||||||
} catch (Exception x) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OurEventListener extends CustomEventListener {
|
|
||||||
/**
|
|
||||||
* Handle custom events
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onCustomEvent(Event event) {
|
|
||||||
if (HeroChatChannelEvent.isInstance(event)) {
|
|
||||||
HeroChatChannelEvent ce = new HeroChatChannelEvent(event);
|
|
||||||
/* Snoop for our web channel - we'll need it, and we'll see it before it matters,
|
|
||||||
* since anyone that joins the channel will give us an event (and reflection on
|
|
||||||
* the plugin class to get the manager didn't work, due to a dependency on the IRC
|
|
||||||
* plugin that may not be present....)
|
|
||||||
*/
|
|
||||||
HeroChatChannel c = ce.getChannel();
|
|
||||||
if (ce.isCancelled())
|
|
||||||
return;
|
|
||||||
if((hcwebinputchannel != null) && ((hcwebinputchannel.equals(c.getName())) ||
|
|
||||||
(hcwebinputchannel.equals(c.getNick())))) {
|
|
||||||
hcwebinputchan = c;
|
|
||||||
}
|
|
||||||
if (HeroChatChannelChatEvent.isInstance(event)) {
|
|
||||||
HeroChatChannelChatEvent cce = new HeroChatChannelChatEvent(
|
|
||||||
event);
|
|
||||||
/* Match on name or nickname of channel */
|
|
||||||
if (hcchannels.contains(c.getName()) ||
|
|
||||||
hcchannels.contains(c.getNick())) {
|
|
||||||
if(cce.isSentByPlayer()) { /* Player message? */
|
|
||||||
org.bukkit.entity.Player p = DynmapPlugin.plugin.getServer().getPlayer(cce.getSource());
|
|
||||||
if((p != null) && (core.mapManager != null)) {
|
|
||||||
core.mapManager.pushUpdate(new Client.ChatMessage("player",
|
|
||||||
c.getNick(),
|
|
||||||
p.getDisplayName(),
|
|
||||||
cce.getMessage(),
|
|
||||||
p.getName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public HeroChatHandler(ConfigurationNode cfg, DynmapCore core) {
|
|
||||||
/* If we're enabling hero chat support */
|
|
||||||
Log.verboseinfo("HeroChat support configured");
|
|
||||||
this.core = core;
|
|
||||||
/* 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 = DynmapPlugin.plugin.getServer().getPluginManager().getPlugin("HeroChat");
|
|
||||||
if(hc != null) {
|
|
||||||
activateHeroChat(hc);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* Set up to hear when HeroChat is enabled */
|
|
||||||
DynmapPlugin.plugin.pm.registerEvents(new OurPluginListener(), DynmapPlugin.plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void activateHeroChat(Plugin herochat) {
|
|
||||||
if (HeroChatChannelChatEvent.initialize() == false) {
|
|
||||||
Log.severe("Cannot load HeroChat chat event class!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (HeroChatChannel.initialize() == false) {
|
|
||||||
Log.severe("Cannot load HeroChat channel class!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (HeroChatChannelEvent.initialize() == false) {
|
|
||||||
Log.severe("Cannot load HeroChat channel event class!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* Register event handler */
|
|
||||||
DynmapPlugin.plugin.pm.registerEvent(Event.Type.CUSTOM_EVENT, new OurEventListener(), Event.Priority.Monitor, DynmapPlugin.plugin);
|
|
||||||
|
|
||||||
Log.verboseinfo("HeroChat integration active");
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Send message from web to appropriate HeroChat channel
|
|
||||||
* @param sender - sender ID
|
|
||||||
* @param message - message
|
|
||||||
* @return true if herochat is handling this, false if not
|
|
||||||
*/
|
|
||||||
public boolean sendWebMessageToHeroChat(String sender, String message) {
|
|
||||||
if(hcwebinputchannel != null) { /* Are we handling them? */
|
|
||||||
if(hcwebinputchan != null) { /* Have we seen it yet? Maybe no if nobody has logged on or
|
|
||||||
* joined it, but then who would see it anyway?
|
|
||||||
*/
|
|
||||||
hcwebinputchan.sendMessage(sender, message, "{default}", false);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
package org.dynmap.herochat;
|
|
||||||
|
|
||||||
import static org.dynmap.JSONUtils.s;
|
|
||||||
|
|
||||||
import org.dynmap.ChatEvent;
|
|
||||||
import org.dynmap.Client;
|
|
||||||
import org.dynmap.Component;
|
|
||||||
import org.dynmap.ConfigurationNode;
|
|
||||||
import org.dynmap.DynmapCore;
|
|
||||||
import org.dynmap.Event;
|
|
||||||
import org.dynmap.common.DynmapListenerManager;
|
|
||||||
import org.dynmap.common.DynmapListenerManager.EventType;
|
|
||||||
import org.dynmap.common.DynmapPlayer;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
|
|
||||||
public class HeroWebChatComponent extends Component {
|
|
||||||
HeroChatHandler handler;
|
|
||||||
public HeroWebChatComponent(final DynmapCore plugin, ConfigurationNode configuration) {
|
|
||||||
super(plugin, configuration);
|
|
||||||
handler = new HeroChatHandler(configuration, plugin);
|
|
||||||
plugin.events.addListener("webchat", new Event.Listener<ChatEvent>() {
|
|
||||||
@Override
|
|
||||||
public void triggered(ChatEvent t) {
|
|
||||||
if(plugin.getServer().sendWebChatEvent(t.source, t.name, t.message)) {
|
|
||||||
/* Let HeroChat take a look - only broadcast to players if it doesn't handle it */
|
|
||||||
if (!handler.sendWebMessageToHeroChat(t.name, t.message)) {
|
|
||||||
String msg;
|
|
||||||
String msgfmt = plugin.configuration.getString("webmsgformat", null);
|
|
||||||
if(msgfmt != null) {
|
|
||||||
msgfmt = unescapeString(msgfmt);
|
|
||||||
msg = msgfmt.replace("%playername%", t.name).replace("%message%", t.message);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
msg = unescapeString(plugin.configuration.getString("webprefix", "\u00A72[WEB] ")) + t.name + ": " + unescapeString(plugin.configuration.getString("websuffix", "\u00A7f")) + t.message;
|
|
||||||
}
|
|
||||||
plugin.getServer().broadcastMessage(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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.
|
|
||||||
core.listenerManager.addListener(EventType.PLAYER_JOIN, new DynmapListenerManager.PlayerEventListener() {
|
|
||||||
@Override
|
|
||||||
public void playerEvent(DynmapPlayer p) {
|
|
||||||
if((core.mapManager != null) && (core.playerList != null) && (core.playerList.isVisiblePlayer(p.getName()))) {
|
|
||||||
core.mapManager.pushUpdate(new Client.PlayerJoinMessage(p.getDisplayName(), p.getName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
core.listenerManager.addListener(EventType.PLAYER_QUIT, new DynmapListenerManager.PlayerEventListener() {
|
|
||||||
@Override
|
|
||||||
public void playerEvent(DynmapPlayer p) {
|
|
||||||
if((core.mapManager != null) && (core.playerList != null) && (core.playerList.isVisiblePlayer(p.getName()))) {
|
|
||||||
core.mapManager.pushUpdate(new Client.PlayerQuitMessage(p.getDisplayName(), p.getName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -53,14 +53,6 @@ components:
|
|||||||
allowchat: true
|
allowchat: true
|
||||||
# If true, web UI users can supply name for chat using 'playername' URL parameter. 'trustclientname' must also be set true.
|
# If true, web UI users can supply name for chat using 'playername' URL parameter. 'trustclientname' must also be set true.
|
||||||
allowurlname: false
|
allowurlname: false
|
||||||
#- 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
|
|
||||||
|
|
||||||
# Note: this component is needed for the dmarker commands, and for the Marker API to be available to other plugins
|
# Note: this component is needed for the dmarker commands, and for the Marker API to be available to other plugins
|
||||||
- class: org.dynmap.MarkersComponent
|
- class: org.dynmap.MarkersComponent
|
||||||
|
Loading…
Reference in New Issue
Block a user