Add global chat-ping-fix option. Inserts zero width space into tokenized payer names.

This commit is contained in:
cnaude 2015-12-05 22:17:30 -07:00
parent b27ecc59db
commit 1416950ede
6 changed files with 37 additions and 15 deletions

View File

@ -91,15 +91,6 @@ public class IRCMessageQueueWatcher {
plugin.logDebug("[blockingCTCPMessage] Message sent to " + target + ": " + message);
}
private String addZeroWidthSpace(String s) {
if (s.length() > 1) {
String a = s.substring(0, 1);
String b = s.substring(1);
return a + "\u200B" + b;
}
return s;
}
private String pingFix(String message) {
for (Channel channel : ircBot.bot.getUserBot().getChannels()) {
for (User user : channel.getUsers()) {
@ -107,7 +98,7 @@ public class IRCMessageQueueWatcher {
continue;
}
if (message.toLowerCase().contains(user.getNick().toLowerCase())) {
message = message.replaceAll("(?i)" + user.getNick(), addZeroWidthSpace(user.getNick()));
message = message.replaceAll("(?i)" + user.getNick(), plugin.tokenizer.addZeroWidthSpace(user.getNick()));
plugin.logDebug("Adding ZWS to " + user.getNick());
}
}
@ -116,7 +107,7 @@ public class IRCMessageQueueWatcher {
}
private String[] cleanupAndSplitMessage(String message) {
if (ircBot.pingFix) {
if (ircBot.pingFixFull) {
message = pingFix(message);
}
return message.replaceAll(REGEX_CLEAN, "").replaceAll(REGEX_CRLF, "\n").split(LF);

View File

@ -99,7 +99,7 @@ public final class PurpleBot {
public boolean relayPrivateChat;
public boolean logPrivateChat;
public boolean partInvalidChannels;
public boolean pingFix;
public boolean pingFixFull;
public int botServerPort;
public long chatDelay;
public String botServer;
@ -708,7 +708,7 @@ public final class PurpleBot {
relayPrivateChat = config.getBoolean("relay-private-chat", false);
logPrivateChat = config.getBoolean("log-private-chat", false);
partInvalidChannels = config.getBoolean("part-invalid-channels", false);
pingFix = config.getBoolean("zero-width-space", false);
pingFixFull = config.getBoolean("zero-width-space", false);
partInvalidChannelsMsg = config.getString("part-invalid-channels-message", "");
nick = config.getString("nick", "");
botNick = nick;
@ -3256,8 +3256,8 @@ public final class PurpleBot {
}
}
// Notify when player goes AFK
/**
* Send AFK message
*
* @param player
* @param afk
@ -3281,6 +3281,7 @@ public final class PurpleBot {
}
/**
* Send a private message to a player
*
* @param sender
* @param nick
@ -3369,6 +3370,7 @@ public final class PurpleBot {
}
/**
* Send a private message to remote player.
*
* @param sender
* @param remoteBot
@ -3582,6 +3584,12 @@ public final class PurpleBot {
}
}
/**
* Send an IRC join notice to the game.
*
* @param channel IRC channel of the user that joined
* @param user IRC user that joined the channel
*/
public void joinNotice(Channel channel, User user) {
if (user.getNick().equalsIgnoreCase(botNick)) {
return;
@ -3616,6 +3624,9 @@ public final class PurpleBot {
}
}
/**
* Change the bot's IRC nick to an alternate.
*/
public void altNickChange() {
if (altNicks.isEmpty()) {
return;

View File

@ -116,6 +116,7 @@ public class PurpleIRC extends JavaPlugin {
public static long startTime;
public boolean identServerEnabled;
private boolean autoSave;
public boolean pingFixTemplate;
private final CaseInsensitiveMap<HashMap<String, String>> messageTmpl;
private final CaseInsensitiveMap<CaseInsensitiveMap<String>> ircHeroChannelMessages;
private final CaseInsensitiveMap<CaseInsensitiveMap<String>> ircHeroActionChannelMessages;
@ -589,6 +590,7 @@ public class PurpleIRC extends JavaPlugin {
logError(ex.getMessage());
}
autoSave = getConfig().getBoolean("save-on-shutdown", false);
pingFixTemplate = getConfig().getBoolean("zero-width-space-template", false);
overrideMsgCmd = getConfig().getBoolean("override-msg-cmd", false);
smsgAlias = getConfig().getString("smsg-alias", "/m");
smsgReplyAlias = getConfig().getString("smsg-reply-alias", "/r");

View File

@ -643,7 +643,12 @@ public class ChatTokenizer {
* @return
*/
public String playerTokenizer(Player player, String message) {
String pName = player.getName();
String pName;
if (plugin.pingFixTemplate) {
pName = addZeroWidthSpace(player.getName());
} else {
pName = player.getName();
}
plugin.logDebug("Tokenizing " + pName + "(O: " + player.isOnline() + ")");
String pSuffix = plugin.getPlayerSuffix(player);
String pPrefix = plugin.getPlayerPrefix(player);
@ -890,4 +895,13 @@ public class ChatTokenizer {
.replace("%FILE%", file)
.replace("%LINE%", line));
}
public String addZeroWidthSpace(String s) {
if (s.length() > 1) {
String a = s.substring(0, 1);
String b = s.substring(1);
return a + "\u200B" + b;
}
return s;
}
}

View File

@ -95,6 +95,8 @@ part-invalid-channels: false
part-invalid-channels-message: 'I should not be here! Bye!'
# Insert zero width space into nicks of IRC output to prevent client pings
zero-width-space: false
# Insert zero width space into player names replaced in templates.
zero-width-space-tokenized: false
# Channel auto join delay in server ticks (20 ticks = 1 second)
channel-auto-join-delay: 20
# If your irc-chat message has a %CUSTOMPREFIX% then these custom prefixes can replace them.

View File

@ -20,6 +20,8 @@ override-msg-cmd: false
smsg-alias: '/m'
# Alias for /irc smsg <prev player>
smsg-reply-alias: '/r'
# Insert zero width space into tokenized player names.
chat-ping-fix: false
# Chat messages support standard Bukkit color codes using '&#'. See http://minecraft.gamepedia.com/Formatting_codes
# The following macro tokens are also supported.
# %WORLD%