diff --git a/src/main/java/com/cnaude/purpleirc/PurpleBot.java b/src/main/java/com/cnaude/purpleirc/PurpleBot.java index 55465cb..3d5206a 100644 --- a/src/main/java/com/cnaude/purpleirc/PurpleBot.java +++ b/src/main/java/com/cnaude/purpleirc/PurpleBot.java @@ -137,6 +137,7 @@ public final class PurpleBot { public CaseInsensitiveMap invalidCommandCTCP; public CaseInsensitiveMap logIrcToHeroChat; public CaseInsensitiveMap enableMessageFiltering; + public CaseInsensitiveMap channelPrefix; private final CaseInsensitiveMap shortify; public CaseInsensitiveMap heroChannel; public CaseInsensitiveMap townyChannel; @@ -216,6 +217,7 @@ public final class PurpleBot { this.joinMsg = new CaseInsensitiveMap<>(); this.msgOnJoin = new CaseInsensitiveMap<>(); this.enableMessageFiltering = new CaseInsensitiveMap<>(); + this.channelPrefix = new CaseInsensitiveMap<>(); this.plugin = plugin; this.file = file; this.reconnectCount = 0; @@ -820,6 +822,9 @@ public final class PurpleBot { enableMessageFiltering.put(channelName, config.getBoolean("channels." + enChannelName + ".enable-filtering", false)); plugin.logDebug(" EnableMessageFiltering => " + enableMessageFiltering.get(channelName)); + + channelPrefix.put(channelName, config.getString("channels." + enChannelName + ".prefix", "")); + plugin.logDebug(" ChannelPrefix => " + channelPrefix.get(channelName)); // build channel op list Collection cOps = new ArrayList<>(); @@ -2120,6 +2125,13 @@ public final class PurpleBot { } return ""; } + + public String getChannelPrefix(Channel channel) { + if (channelPrefix.containsKey(channel.getName())) { + return channelPrefix.get(channel.getName()); + } + return ""; + } /** * diff --git a/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java b/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java index 52b396b..856b28d 100644 --- a/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java +++ b/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java @@ -55,9 +55,12 @@ public class ChatTokenizer { * @return */ public String chatIRCTokenizer(PurpleBot ircBot, User user, org.pircbotx.Channel channel, String template) { - return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, user, ircBot) + return plugin.colorConverter.ircColorsToGame( + ircUserTokenizer(template, user, ircBot) .replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel)) - .replace("%CHANNEL%", channel.getName())); + .replace("%CHANNELPREFIX%", ircBot.getChannelPrefix(channel)) + .replace("%CHANNEL%", channel.getName()) + ); } public String ircUserTokenizer(String template, User user, PurpleBot ircBot) { @@ -139,6 +142,7 @@ public class ChatTokenizer { .replace("%HERONICK%", channelManager.getChannel(hChannel).getNick()) .replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString()) .replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel)) + .replace("%CHANNELPREFIX%", ircBot.getChannelPrefix(channel)) .replace("%CHANNEL%", channel.getName())); } @@ -164,6 +168,7 @@ public class ChatTokenizer { } return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user, ircBot) .replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel)) + .replace("%CHANNELPREFIX%", ircBot.getChannelPrefix(channel)) .replace("%MESSAGE%", message) .replace("%CHANNEL%", channel.getName())); } @@ -194,6 +199,7 @@ public class ChatTokenizer { .replace("%HERONICK%", channelManager.getChannel(hChannel).getNick()) .replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString()) .replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel)) + .replace("%CHANNELPREFIX%", ircBot.getChannelPrefix(channel)) .replace("%MESSAGE%", message) .replace("%CHANNEL%", channel.getName())); } @@ -221,6 +227,7 @@ public class ChatTokenizer { return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user, ircBot) .replace("%TOWNYCHANNEL%", tChannel) .replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel)) + .replace("%CHANNELPREFIX%", ircBot.getChannelPrefix(channel)) .replace("%MESSAGE%", message) .replace("%CHANNEL%", channel.getName())); } @@ -239,6 +246,7 @@ public class ChatTokenizer { public String ircKickTokenizer(PurpleBot ircBot, User recipient, User kicker, String reason, org.pircbotx.Channel channel, String template) { return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, recipient, kicker, ircBot) .replace("%NICKPREFIX%", ircBot.getNickPrefix(kicker, channel)) + .replace("%CHANNELPREFIX%", ircBot.getChannelPrefix(channel)) .replace("%REASON%", reason) .replace("%CHANNEL%", channel.getName())); } @@ -262,6 +270,7 @@ public class ChatTokenizer { .replace("%HERONICK%", channelManager.getChannel(hChannel).getNick()) .replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString()) .replace("%NICKPREFIX%", ircBot.getNickPrefix(kicker, channel)) + .replace("%CHANNELPREFIX%", ircBot.getChannelPrefix(channel)) .replace("%REASON%", reason) .replace("%CHANNEL%", channel.getName())); } @@ -280,6 +289,7 @@ public class ChatTokenizer { return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, user, ircBot) .replace("%MODE%", mode) .replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel)) + .replace("%CHANNELPREFIX%", ircBot.getChannelPrefix(channel)) .replace("%CHANNEL%", channel.getName())); } @@ -297,6 +307,7 @@ public class ChatTokenizer { public String ircNoticeTokenizer(PurpleBot ircBot, User user, String message, String notice, org.pircbotx.Channel channel, String template) { return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, user, ircBot) .replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel)) + .replace("%CHANNELPREFIX%", ircBot.getChannelPrefix(channel)) .replace("%MESSAGE%", message) .replace("%NOTICE%", notice) .replace("%CHANNEL%", channel.getName())); diff --git a/src/main/resources/SampleBot.yml b/src/main/resources/SampleBot.yml index 1e92c49..1063cdd 100644 --- a/src/main/resources/SampleBot.yml +++ b/src/main/resources/SampleBot.yml @@ -85,6 +85,8 @@ channels: # Use %2E instead of dots in the channel names. # Example: minecraft%2Etest == minecraft.test '#minecraft-test': + # message prefix (replaces %CHANNELPREFIX% + prefix: '' # worlds we listen to for this channel worlds: - '*' diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c9351a3..76848bf 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -23,6 +23,7 @@ channel-check-interval: 100 # %KICKERSERVER% - Server of IRC kicker # %KICKERAWAY% - IRC kicker away message # %NICKPREFIX% - IRC user's status (see nick-prefixes below) +# %CHANNELPREFIX% - Custom prefix per channel (see prefix option in SampleBot.yml) # %DISPLAYNAME% - Player's custom name # %PLAYERIP% - IP address of a player # %CHANNEL%