Don't send duplicate messages to from VentureChat. #14

This commit is contained in:
BuildTools 2016-02-28 10:33:39 -07:00
parent d290a818ef
commit e2bd187844
4 changed files with 35 additions and 23 deletions

0
dependency-reduced-pom.xml Normal file → Executable file
View File

View File

@ -32,15 +32,18 @@ public class VentureChatEvent extends Event {
private static final HandlerList HANDLERS = new HandlerList();
private final AsyncPlayerChatEvent event;
private final PurpleBot bot;
private final String ircChannel;
/**
*
* @param event
* @param bot
* @param ircChannel
*/
public VentureChatEvent(AsyncPlayerChatEvent event, PurpleBot bot) {
public VentureChatEvent(AsyncPlayerChatEvent event, PurpleBot bot, String ircChannel) {
this.event = event;
this.bot = bot;
this.ircChannel = ircChannel;
}
/**
@ -66,6 +69,14 @@ public class VentureChatEvent extends Event {
public PurpleBot getBot() {
return bot;
}
/**
*
* @return
*/
public String getIrcChannel() {
return ircChannel;
}
/**
*

View File

@ -50,17 +50,19 @@ public class VentureChatListener implements Listener {
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onVentureChatEvent(VentureChatEvent event) {
ventureChat(event.getPlayer(), event.getMessage(), event.getBot());
plugin.logDebug("Entering onVentureChatEvent: " + event.getMessage());
ventureChat(event.getPlayer(), event.getMessage(), event.getBot(), event.getIrcChannel());
}
/**
* VentureChat from game to IRC
*
* @param player
* @param message
* @param player the player
* @param message the message
* @param bot the calling bot
* @param channelName destination IRC channel
*/
public void ventureChat(Player player, String message, PurpleBot bot) {
public void ventureChat(Player player, String message, PurpleBot bot, String channelName) {
MineverseChatPlayer mcp = MineverseChatAPI.getMineverseChatPlayer(player);
ChatChannel eventChannel = mcp.getCurrentChannel();
if (mcp.isQuickChat()) { //for single message chat detection
@ -75,23 +77,21 @@ public class VentureChatListener implements Listener {
}
String vcChannel = eventChannel.getName();
String vcColor = eventChannel.getColor();
for (String channelName : bot.botChannels) {
if (!bot.isPlayerInValidWorld(player, channelName)) {
continue;
}
plugin.logDebug("VC Channel: " + vcChannel);
String channelTemplateName = "venture-" + vcChannel + "-chat";
if (bot.isMessageEnabled(channelName, channelTemplateName)
|| bot.isMessageEnabled(channelName, TemplateName.VENTURE_CHAT)) {
String template = plugin.getVentureChatTemplate(bot.botNick, vcChannel);
plugin.logDebug("VC Template: " + template);
bot.asyncIRCMessage(channelName, plugin.tokenizer
.ventureChatTokenizer(player, vcChannel, vcColor, message, template));
} else {
plugin.logDebug("Player " + player.getName() + " is in VentureChat channel "
+ vcChannel + ". Message types " + channelTemplateName + " and "
+ TemplateName.VENTURE_CHAT + " are disabled. No message sent to IRC.");
}
if (!bot.isPlayerInValidWorld(player, channelName)) {
return;
}
plugin.logDebug("VC Channel: " + vcChannel);
String channelTemplateName = "venture-" + vcChannel + "-chat";
if (bot.isMessageEnabled(channelName, channelTemplateName)
|| bot.isMessageEnabled(channelName, TemplateName.VENTURE_CHAT)) {
String template = plugin.getVentureChatTemplate(bot.botNick, vcChannel);
plugin.logDebug("VC Template: " + template);
bot.asyncIRCMessage(channelName, plugin.tokenizer
.ventureChatTokenizer(player, vcChannel, vcColor, message, template));
} else {
plugin.logDebug("Player " + player.getName() + " is in VentureChat channel "
+ vcChannel + ". Message types " + channelTemplateName + " and "
+ TemplateName.VENTURE_CHAT + " are disabled. No message sent to IRC.");
}
}

View File

@ -1243,7 +1243,8 @@ public final class PurpleBot {
plugin.logDebug("No Factions");
}
if (plugin.ventureChatEnabled) {
plugin.getServer().getPluginManager().callEvent(new VentureChatEvent(event, this));
plugin.logDebug("Calling VentureChatEvent: " + event.getMessage());
plugin.getServer().getPluginManager().callEvent(new VentureChatEvent(event, this, channelName));
}
if (isMessageEnabled(channelName, TemplateName.GAME_CHAT)) {
asyncIRCMessage(channelName, plugin.tokenizer