Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Strip color annoying IRC color codes...
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed May 11, 2014
1 parent 2f15741 commit a1e61d2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/java/com/cnaude/purpleirc/Utilities/ColorConverter.java
Expand Up @@ -22,6 +22,7 @@ public class ColorConverter {
private final HashMap<String, ChatColor> gameColorMap = new HashMap<String, ChatColor>();
private final Pattern bgColorPattern;
private final Pattern singleDigitColorPattern;
private final Pattern colorHack;

/**
*
Expand All @@ -38,6 +39,7 @@ public ColorConverter(PurpleIRC plugin, boolean stripGameColors, boolean stripIR
buildDefaultColorMaps();
this.bgColorPattern = Pattern.compile("((\\u0003\\d+),\\d+)");
this.singleDigitColorPattern = Pattern.compile("((\\u0003)(\\d))\\D+");
this.colorHack = Pattern.compile("((\\u0003\\d+)(,\\d+))\\D");
}

/**
Expand All @@ -63,7 +65,7 @@ public String gameColorsToIrc(String message) {
* @param message
* @return
*/
public String ircColorsToGame(String message) {
public String ircColorsToGame(String message) {
if (stripIRCBackgroundColors) {
Matcher m = bgColorPattern.matcher(message);
while (m.find()) {
Expand All @@ -74,11 +76,18 @@ public String ircColorsToGame(String message) {
try {
Matcher m2 = singleDigitColorPattern.matcher(message);
while (m2.find()) {
plugin.logDebug("Single to double: " + m2.group(3) + " => "
plugin.logDebug("Single to double: " + m2.group(3) + " => "
+ m2.group(2) + "0" + m2.group(3));
// replace \u0003N with \u00030N
message = message.replace(m2.group(1), m2.group(2) + "0" + m2.group(3));
}
m2 = colorHack.matcher(message);
while (m2.find()) {
plugin.logDebug("Silly IRC colors: " + m2.group(1) + " => "
+ m2.group(2));
// replace \u0003N,N with \u00030N
message = message.replace(m2.group(1), m2.group(2));
}
} catch (Exception ex) {
plugin.logDebug(ex.getMessage());
}
Expand Down

0 comments on commit a1e61d2

Please sign in to comment.