Merge pull request #6074 from raiyni/issue-6069

Force clan chat names to a specific format
This commit is contained in:
Tomas Slusny
2018-10-23 16:14:48 +02:00
committed by GitHub
2 changed files with 15 additions and 1 deletions

View File

@@ -49,6 +49,7 @@ import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.ClanManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.util.Text;
@PluginDescriptor(
name = "Clan Chat",
@@ -132,7 +133,7 @@ public class ClanChatPlugin extends Plugin
{
if (strChanged.getIndex() == VarClientStr.RECENT_CLAN_CHAT.getIndex() && config.recentChats())
{
updateRecentChat(client.getVar(VarClientStr.RECENT_CLAN_CHAT));
updateRecentChat(Text.toJagexName(client.getVar(VarClientStr.RECENT_CLAN_CHAT)));
}
}

View File

@@ -25,6 +25,7 @@
*/
package net.runelite.client.util;
import com.google.common.base.CharMatcher;
import java.util.regex.Pattern;
/**
@@ -56,6 +57,18 @@ public class Text
return removeTags(str).replace('\u00A0', ' ').trim().toLowerCase();
}
/**
* Convert a string into Jagex username format
* Remove all non-ascii characters, replace nbsp with space, replace _- with spaces, and trim
*
* @param str The string to standardize
* @return The given `str` that is in Jagex name format
*/
public static String toJagexName(String str)
{
return CharMatcher.ascii().retainFrom(str.replace('\u00A0', ' ')).replaceAll("[_-]+", " ").trim();
}
/**
* In addition to removing all tags, replaces all <br> delimited text with spaces and all multiple continuous
* spaces with single space