mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2024-09-29 06:57:31 +02:00
Add global chat-ping-fix option. Inserts zero width space into tokenized payer names.
This commit is contained in:
parent
b27ecc59db
commit
1416950ede
@ -91,15 +91,6 @@ public class IRCMessageQueueWatcher {
|
|||||||
plugin.logDebug("[blockingCTCPMessage] Message sent to " + target + ": " + message);
|
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) {
|
private String pingFix(String message) {
|
||||||
for (Channel channel : ircBot.bot.getUserBot().getChannels()) {
|
for (Channel channel : ircBot.bot.getUserBot().getChannels()) {
|
||||||
for (User user : channel.getUsers()) {
|
for (User user : channel.getUsers()) {
|
||||||
@ -107,7 +98,7 @@ public class IRCMessageQueueWatcher {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (message.toLowerCase().contains(user.getNick().toLowerCase())) {
|
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());
|
plugin.logDebug("Adding ZWS to " + user.getNick());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,7 +107,7 @@ public class IRCMessageQueueWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String[] cleanupAndSplitMessage(String message) {
|
private String[] cleanupAndSplitMessage(String message) {
|
||||||
if (ircBot.pingFix) {
|
if (ircBot.pingFixFull) {
|
||||||
message = pingFix(message);
|
message = pingFix(message);
|
||||||
}
|
}
|
||||||
return message.replaceAll(REGEX_CLEAN, "").replaceAll(REGEX_CRLF, "\n").split(LF);
|
return message.replaceAll(REGEX_CLEAN, "").replaceAll(REGEX_CRLF, "\n").split(LF);
|
||||||
|
@ -99,7 +99,7 @@ public final class PurpleBot {
|
|||||||
public boolean relayPrivateChat;
|
public boolean relayPrivateChat;
|
||||||
public boolean logPrivateChat;
|
public boolean logPrivateChat;
|
||||||
public boolean partInvalidChannels;
|
public boolean partInvalidChannels;
|
||||||
public boolean pingFix;
|
public boolean pingFixFull;
|
||||||
public int botServerPort;
|
public int botServerPort;
|
||||||
public long chatDelay;
|
public long chatDelay;
|
||||||
public String botServer;
|
public String botServer;
|
||||||
@ -708,7 +708,7 @@ public final class PurpleBot {
|
|||||||
relayPrivateChat = config.getBoolean("relay-private-chat", false);
|
relayPrivateChat = config.getBoolean("relay-private-chat", false);
|
||||||
logPrivateChat = config.getBoolean("log-private-chat", false);
|
logPrivateChat = config.getBoolean("log-private-chat", false);
|
||||||
partInvalidChannels = config.getBoolean("part-invalid-channels", 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", "");
|
partInvalidChannelsMsg = config.getString("part-invalid-channels-message", "");
|
||||||
nick = config.getString("nick", "");
|
nick = config.getString("nick", "");
|
||||||
botNick = nick;
|
botNick = nick;
|
||||||
@ -3256,8 +3256,8 @@ public final class PurpleBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify when player goes AFK
|
|
||||||
/**
|
/**
|
||||||
|
* Send AFK message
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param afk
|
* @param afk
|
||||||
@ -3281,6 +3281,7 @@ public final class PurpleBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Send a private message to a player
|
||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* @param nick
|
* @param nick
|
||||||
@ -3369,6 +3370,7 @@ public final class PurpleBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Send a private message to remote player.
|
||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* @param remoteBot
|
* @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) {
|
public void joinNotice(Channel channel, User user) {
|
||||||
if (user.getNick().equalsIgnoreCase(botNick)) {
|
if (user.getNick().equalsIgnoreCase(botNick)) {
|
||||||
return;
|
return;
|
||||||
@ -3616,6 +3624,9 @@ public final class PurpleBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the bot's IRC nick to an alternate.
|
||||||
|
*/
|
||||||
public void altNickChange() {
|
public void altNickChange() {
|
||||||
if (altNicks.isEmpty()) {
|
if (altNicks.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -116,6 +116,7 @@ public class PurpleIRC extends JavaPlugin {
|
|||||||
public static long startTime;
|
public static long startTime;
|
||||||
public boolean identServerEnabled;
|
public boolean identServerEnabled;
|
||||||
private boolean autoSave;
|
private boolean autoSave;
|
||||||
|
public boolean pingFixTemplate;
|
||||||
private final CaseInsensitiveMap<HashMap<String, String>> messageTmpl;
|
private final CaseInsensitiveMap<HashMap<String, String>> messageTmpl;
|
||||||
private final CaseInsensitiveMap<CaseInsensitiveMap<String>> ircHeroChannelMessages;
|
private final CaseInsensitiveMap<CaseInsensitiveMap<String>> ircHeroChannelMessages;
|
||||||
private final CaseInsensitiveMap<CaseInsensitiveMap<String>> ircHeroActionChannelMessages;
|
private final CaseInsensitiveMap<CaseInsensitiveMap<String>> ircHeroActionChannelMessages;
|
||||||
@ -589,6 +590,7 @@ public class PurpleIRC extends JavaPlugin {
|
|||||||
logError(ex.getMessage());
|
logError(ex.getMessage());
|
||||||
}
|
}
|
||||||
autoSave = getConfig().getBoolean("save-on-shutdown", false);
|
autoSave = getConfig().getBoolean("save-on-shutdown", false);
|
||||||
|
pingFixTemplate = getConfig().getBoolean("zero-width-space-template", false);
|
||||||
overrideMsgCmd = getConfig().getBoolean("override-msg-cmd", false);
|
overrideMsgCmd = getConfig().getBoolean("override-msg-cmd", false);
|
||||||
smsgAlias = getConfig().getString("smsg-alias", "/m");
|
smsgAlias = getConfig().getString("smsg-alias", "/m");
|
||||||
smsgReplyAlias = getConfig().getString("smsg-reply-alias", "/r");
|
smsgReplyAlias = getConfig().getString("smsg-reply-alias", "/r");
|
||||||
|
@ -643,7 +643,12 @@ public class ChatTokenizer {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String playerTokenizer(Player player, String message) {
|
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() + ")");
|
plugin.logDebug("Tokenizing " + pName + "(O: " + player.isOnline() + ")");
|
||||||
String pSuffix = plugin.getPlayerSuffix(player);
|
String pSuffix = plugin.getPlayerSuffix(player);
|
||||||
String pPrefix = plugin.getPlayerPrefix(player);
|
String pPrefix = plugin.getPlayerPrefix(player);
|
||||||
@ -890,4 +895,13 @@ public class ChatTokenizer {
|
|||||||
.replace("%FILE%", file)
|
.replace("%FILE%", file)
|
||||||
.replace("%LINE%", line));
|
.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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,8 @@ part-invalid-channels: false
|
|||||||
part-invalid-channels-message: 'I should not be here! Bye!'
|
part-invalid-channels-message: 'I should not be here! Bye!'
|
||||||
# Insert zero width space into nicks of IRC output to prevent client pings
|
# Insert zero width space into nicks of IRC output to prevent client pings
|
||||||
zero-width-space: false
|
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 in server ticks (20 ticks = 1 second)
|
||||||
channel-auto-join-delay: 20
|
channel-auto-join-delay: 20
|
||||||
# If your irc-chat message has a %CUSTOMPREFIX% then these custom prefixes can replace them.
|
# If your irc-chat message has a %CUSTOMPREFIX% then these custom prefixes can replace them.
|
||||||
|
@ -20,6 +20,8 @@ override-msg-cmd: false
|
|||||||
smsg-alias: '/m'
|
smsg-alias: '/m'
|
||||||
# Alias for /irc smsg <prev player>
|
# Alias for /irc smsg <prev player>
|
||||||
smsg-reply-alias: '/r'
|
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
|
# Chat messages support standard Bukkit color codes using '&#'. See http://minecraft.gamepedia.com/Formatting_codes
|
||||||
# The following macro tokens are also supported.
|
# The following macro tokens are also supported.
|
||||||
# %WORLD%
|
# %WORLD%
|
||||||
|
Loading…
Reference in New Issue
Block a user