diff --git a/src/main/java/com/cnaude/purpleirc/IRCMessageHandler.java b/src/main/java/com/cnaude/purpleirc/IRCMessageHandler.java index 79dbb10..6c37259 100644 --- a/src/main/java/com/cnaude/purpleirc/IRCMessageHandler.java +++ b/src/main/java/com/cnaude/purpleirc/IRCMessageHandler.java @@ -180,10 +180,9 @@ public class IRCMessageHandler { case "@a": if (plugin.adminPrivateChatHook != null) { String newMessage = ircBot.filterMessage( - plugin.tokenizer.ircChatToGameTokenizer(ircBot, user, channel, plugin.getMsgTemplate( - ircBot.botNick, channelName, TemplateName.IRC_A_CHAT), commandArgs), channelName); + plugin.tokenizer.ircChatToGameTokenizer(ircBot, user, channel, plugin.getMsgTemplate(ircBot.botNick, channelName, TemplateName.IRC_ADMIN_CHAT), commandArgs), channelName); plugin.adminPrivateChatHook.sendMessage(newMessage, user.getNick()); - String acResponse = plugin.tokenizer.msgChatResponseTokenizer(target, commandArgs, plugin.getMsgTemplate(TemplateName.IRC_A_RESPONSE)); + String acResponse = plugin.tokenizer.msgChatResponseTokenizer(target, commandArgs, plugin.getMsgTemplate(TemplateName.IRC_ADMIN_RESPONSE)); if (!acResponse.isEmpty()) { sendMessage(ircBot, target, acResponse, ctcpResponse); } diff --git a/src/main/java/com/cnaude/purpleirc/PlayerList.java b/src/main/java/com/cnaude/purpleirc/PlayerList.java new file mode 100644 index 0000000..da3047d --- /dev/null +++ b/src/main/java/com/cnaude/purpleirc/PlayerList.java @@ -0,0 +1,11 @@ +package com.cnaude.purpleirc; + +/** + * + * @author cnaude + */ +public class PlayerList { + public int count; + public int max; + public String list; +} diff --git a/src/main/java/com/cnaude/purpleirc/PurpleBot.java b/src/main/java/com/cnaude/purpleirc/PurpleBot.java index 6272614..ef279ff 100644 --- a/src/main/java/com/cnaude/purpleirc/PurpleBot.java +++ b/src/main/java/com/cnaude/purpleirc/PurpleBot.java @@ -1350,10 +1350,10 @@ public final class PurpleBot { return; } for (String channelName : botChannels) { - if (isMessageEnabled(channelName, TemplateName.GAME_A_CHAT)) { + if (isMessageEnabled(channelName, TemplateName.GAME_ADMIN_CHAT)) { asyncIRCMessage(channelName, plugin.tokenizer .gameChatToIRCTokenizer(name, plugin. - getMsgTemplate(botNick, channelName, TemplateName.GAME_A_CHAT), message) + getMsgTemplate(botNick, channelName, TemplateName.GAME_ADMIN_CHAT), message) .replace("%WORLD%", world) ); } @@ -1564,7 +1564,7 @@ public final class PurpleBot { if (isMessageEnabled(channelName, TemplateName.GAME_JOIN) && isPlayerInValidWorld(player, channelName)) { asyncIRCMessage(channelName, plugin.tokenizer - .gameChatToIRCTokenizer(player, plugin + .gameChatToIRCTokenizer(this, channelName, player, plugin .getMsgTemplate(botNick, channelName, TemplateName.GAME_JOIN), message)); } } @@ -1588,7 +1588,7 @@ public final class PurpleBot { if (isMessageEnabled(channelName, TemplateName.GAME_QUIT) && isPlayerInValidWorld(player, channelName)) { asyncIRCMessage(channelName, plugin.tokenizer - .gameChatToIRCTokenizer(player, plugin + .gameChatToIRCTokenizer(this, channelName, player, plugin .getMsgTemplate(botNick, channelName, TemplateName.GAME_QUIT), message)); } } @@ -1607,7 +1607,7 @@ public final class PurpleBot { if (isMessageEnabled(channelName, TemplateName.FAKE_JOIN) && isPlayerInValidWorld(player, channelName)) { asyncIRCMessage(channelName, plugin.tokenizer - .gameChatToIRCTokenizer(player, plugin + .gameChatToIRCTokenizer(this, channelName, player, plugin .getMsgTemplate(botNick, channelName, TemplateName.FAKE_JOIN), message)); } } @@ -1626,7 +1626,7 @@ public final class PurpleBot { if (isMessageEnabled(channelName, TemplateName.FAKE_QUIT) && isPlayerInValidWorld(player, channelName)) { asyncIRCMessage(channelName, plugin.tokenizer - .gameChatToIRCTokenizer(player, plugin + .gameChatToIRCTokenizer(this, channelName, player, plugin .getMsgTemplate(botNick, channelName, TemplateName.FAKE_QUIT), message)); } } @@ -2578,10 +2578,9 @@ public final class PurpleBot { Send messages to AdminPrivateChat if enabled */ if (plugin.adminPrivateChatHook != null) { - if (isMessageEnabled(channelName, TemplateName.IRC_A_CHAT) || override) { + if (isMessageEnabled(channelName, TemplateName.IRC_ADMIN_CHAT) || override) { String newMessage = filterMessage( - plugin.tokenizer.ircChatToGameTokenizer(this, user, channel, plugin.getMsgTemplate( - botNick, channelName, TemplateName.IRC_A_CHAT), message), channelName); + plugin.tokenizer.ircChatToGameTokenizer(this, user, channel, plugin.getMsgTemplate(botNick, channelName, TemplateName.IRC_ADMIN_CHAT), message), channelName); if (!newMessage.isEmpty()) { plugin.adminPrivateChatHook.sendMessage(newMessage, user.getNick()); messageSent = true; diff --git a/src/main/java/com/cnaude/purpleirc/PurpleIRC.java b/src/main/java/com/cnaude/purpleirc/PurpleIRC.java index b9bf8d5..a1d2a87 100644 --- a/src/main/java/com/cnaude/purpleirc/PurpleIRC.java +++ b/src/main/java/com/cnaude/purpleirc/PurpleIRC.java @@ -825,6 +825,25 @@ public class PurpleIRC extends JavaPlugin { * @return */ public String getMCPlayers(PurpleBot ircBot, String channelName) { + PlayerList pl = getMCPlayerList(ircBot, channelName); + + String msg = listFormat + .replace("%COUNT%", Integer.toString(pl.count)) + .replace("%MAX%", Integer.toString(pl.max)) + .replace("%PLAYERS%", pl.list); + + return colorConverter.gameColorsToIrc(msg); + } + + /** + * + * @param ircBot + * @param channelName + * @return + */ + public PlayerList getMCPlayerList(PurpleBot ircBot, String channelName) { + PlayerList pl = new PlayerList(); + Map playerList = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (Player player : getServer().getOnlinePlayers()) { if (ircBot.hideListWhenVanished.get(channelName)) { @@ -848,15 +867,15 @@ public class PurpleIRC extends JavaPlugin { // sort without nick prefixes pList = Joiner.on(listSeparator).join(playerList.values()); } - - String msg = listFormat - .replace("%COUNT%", Integer.toString(playerList.size())) - .replace("%MAX%", Integer.toString(getServer().getMaxPlayers())) - .replace("%PLAYERS%", pList); - logDebug("L: " + msg); - return colorConverter.gameColorsToIrc(msg); + + pl.count = playerList.size(); + pl.max = getServer().getMaxPlayers(); + pl.list = pList; + + return pl; + } - + public String getRemotePlayers(String commandArgs) { if (commandArgs != null) { String host; diff --git a/src/main/java/com/cnaude/purpleirc/TemplateName.java b/src/main/java/com/cnaude/purpleirc/TemplateName.java index a316550..b96fd33 100644 --- a/src/main/java/com/cnaude/purpleirc/TemplateName.java +++ b/src/main/java/com/cnaude/purpleirc/TemplateName.java @@ -130,9 +130,9 @@ public class TemplateName { public final static String REDDIT_MESSAGES = "reddit-messages"; - public final static String IRC_A_RESPONSE = "irc-a-response"; - public final static String GAME_A_CHAT = "game-a-chat"; - public final static String IRC_A_CHAT = "irc-a-chat"; + public final static String IRC_ADMIN_RESPONSE = "irc-a-response"; + public final static String GAME_ADMIN_CHAT = "game-a-chat"; + public final static String IRC_ADMIN_CHAT = "irc-a-chat"; public final static String FAKE_JOIN = "fake-join"; public final static String FAKE_QUIT = "fake-quit"; diff --git a/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java b/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java index 2b5ca09..625df4c 100644 --- a/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java +++ b/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java @@ -16,6 +16,7 @@ */ package com.cnaude.purpleirc.Utilities; +import com.cnaude.purpleirc.PlayerList; import com.cnaude.purpleirc.PurpleBot; import com.cnaude.purpleirc.PurpleIRC; import com.cnaude.purpleirc.TemplateName; @@ -370,7 +371,6 @@ public class ChatTokenizer { * * @param player * @param template - * * @param message * @return */ @@ -384,6 +384,29 @@ public class ChatTokenizer { /** * Game chat to IRC * + * @param ircBot + * @param channelName + * @param player + * @param template + * @param message + * @return + */ + public String gameChatToIRCTokenizer(PurpleBot ircBot, String channelName, Player player, String template, String message) { + if (message == null) { + message = ""; + } + PlayerList pl = plugin.getMCPlayerList(ircBot, channelName); + return plugin.colorConverter.gameColorsToIrc(playerTokenizer(player, template) + .replace("%MESSAGE%", message) + .replace("%COUNT%", Integer.toString(pl.count)) + .replace("%MAX%", Integer.toString(pl.max)) + .replace("%PLAYERS%", pl.list) + ); + } + + /** + * Dynmap web chat to IRC + * * @param source * @param name * @param template