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

Commit

Permalink
Don't strip single digit color codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed May 11, 2014
1 parent 2ab9c0c commit 8bc909e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main/java/com/cnaude/purpleirc/Utilities/ColorConverter.java
Expand Up @@ -28,6 +28,7 @@ public class ColorConverter {
private final EnumMap<ChatColor, String> ircColorMap = new EnumMap<ChatColor, String>(ChatColor.class);
private final HashMap<String, ChatColor> gameColorMap = new HashMap<String, ChatColor>();
private final Pattern pattern;
private final Pattern pattern2;

/**
*
Expand All @@ -43,6 +44,7 @@ public ColorConverter(PurpleIRC plugin, boolean stripGameColors, boolean stripIR
this.plugin = plugin;
buildDefaultColorMaps();
this.pattern = Pattern.compile("((\\u0003\\d+),\\d+)");
this.pattern2 = Pattern.compile("((\\u0003)(\\d))\\D+");
}

/**
Expand All @@ -69,20 +71,19 @@ public String gameColorsToIrc(String message) {
* @return
*/
public String ircColorsToGame(String message) {
try {
Matcher m2 = pattern2.matcher(message);
while (m2.find()) {
plugin.logDebug("Single to double: " + m2.group(2) + "0" + m2.group(3));
message = message.replace(m2.group(1), m2.group(2) + "0" + m2.group(3));
}
} catch (Exception ex) {
plugin.logDebug(ex.getMessage());
}
if (stripIRCBackgroundColors) {
Matcher m = pattern.matcher(message);
while (m.find()) {
plugin.logDebug("m2=" + m.group(2));
int c = Integer.parseInt(m.group(2).trim());
plugin.logDebug("c=" + c);
String c1 = String.valueOf(c);
plugin.logDebug("c1 before: " + c1);
if (c < 10) {
c1 = "\u00030" + c1;
}
plugin.logDebug("c1 after: " + c1);
plugin.logDebug("Stripping background colors: " + m.group(1) + "=>" + c1);
message = message.replace(m.group(1), c1);
message = message.replace(m.group(1), m.group(2));
}
}
if (stripIRCColors) {
Expand Down

0 comments on commit 8bc909e

Please sign in to comment.