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

Commit

Permalink
Strip IRC background colors.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed May 6, 2014
1 parent f993734 commit 42784ff
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Expand Up @@ -4,7 +4,7 @@
<groupId>com.cnaude</groupId>
<artifactId>PurpleIRC</artifactId>
<name>PurpleIRC</name>
<version>2.1.13</version>
<version>2.1.14-SNAPSHOT</version>
<description>A CraftBukkit plugin for bridging game chat with IRC. Connect to any number of IRC servers and channels simultaneously.</description>
<url>http://dev.bukkit.org/server-mods/purpleirc/</url>
<build>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -339,7 +339,7 @@
<tasks>
<copy file="../${project.name}/target/${project.name}-${project.version}.jar" tofile="../${project.name}/target/${project.name}.jar"/>
<exec dir="../${project.name}/target" executable="scp">
<arg line="${project.name}.jar cnaude@cn.revisited.us:minetest/plugins/"/>
<arg line="${project.name}.jar cnaude@h.cnaude.org:minetest/plugins/"/>
</exec>
</tasks>
</configuration>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/cnaude/purpleirc/PurpleIRC.java
Expand Up @@ -107,6 +107,7 @@ public class PurpleIRC extends JavaPlugin {
private boolean debugEnabled;
private boolean stripGameColors;
private boolean stripIRCColors;
private boolean stripIRCBackgroundColors;
private boolean customTabList;
private boolean listSortByName;
public boolean exactNickMatch;
Expand Down Expand Up @@ -515,8 +516,9 @@ private void loadConfig() {
logDebug("Debug enabled");
stripGameColors = getConfig().getBoolean("strip-game-colors", false);
stripIRCColors = getConfig().getBoolean("strip-irc-colors", false);
stripIRCBackgroundColors = getConfig().getBoolean("strip-irc-bg-colors", true);
exactNickMatch = getConfig().getBoolean("nick-exact-match", true);
colorConverter = new ColorConverter(this, stripGameColors, stripIRCColors);
colorConverter = new ColorConverter(this, stripGameColors, stripIRCColors, stripIRCBackgroundColors);
logDebug("strip-game-colors: " + stripGameColors);
logDebug("strip-irc-colors: " + stripIRCColors);

Expand Down
19 changes: 16 additions & 3 deletions src/main/java/com/cnaude/purpleirc/Utilities/ColorConverter.java
Expand Up @@ -10,6 +10,8 @@
import com.cnaude.purpleirc.PurpleIRC;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.pircbotx.Colors;

Expand All @@ -22,20 +24,24 @@ public class ColorConverter {
PurpleIRC plugin;
private final boolean stripGameColors;
private final boolean stripIRCColors;
private final boolean stripIRCBackgroundColors;
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;

/**
*
* @param plugin
* @param stripGameColors
* @param stripIRCColors
*/
public ColorConverter(PurpleIRC plugin, boolean stripGameColors, boolean stripIRCColors) {
public ColorConverter(PurpleIRC plugin, boolean stripGameColors, boolean stripIRCColors, boolean stripIRCBackgroundColors) {
this.stripGameColors = stripGameColors;
this.stripIRCColors = stripIRCColors;
this.stripIRCBackgroundColors = stripIRCBackgroundColors;
this.plugin = plugin;
buildDefaultColorMaps();
this.pattern = Pattern.compile("((\\u0003\\d+),\\d+)");
}

/**
Expand All @@ -62,6 +68,13 @@ public String gameColorsToIrc(String message) {
* @return
*/
public String ircColorsToGame(String message) {
if (stripIRCBackgroundColors) {
Matcher m = pattern.matcher(message);
while (m.find()) {
plugin.logDebug("Stripping background colors: " + m.group(1) + "=>" + m.group(2));
message = message.replace(m.group(1), m.group(2));
}
}
if (stripIRCColors) {
return Colors.removeFormattingAndColors(message);
} else {
Expand Down Expand Up @@ -99,11 +112,11 @@ public void addGameColorMap(String ircColor, String gameColor) {
plugin.logDebug("addGameColorMap: " + ircColor + " => " + gameColor);
gameColorMap.put(getIrcColor(ircColor), chatColor);
}

private String getIrcColor(String ircColor) {
String s = "";
try {
s = (String)Colors.class.getField(ircColor.toUpperCase()).get(null);
s = (String) Colors.class.getField(ircColor.toUpperCase()).get(null);
} catch (NoSuchFieldException ex) {
plugin.logError(ex.getMessage());
} catch (SecurityException ex) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Expand Up @@ -154,6 +154,8 @@ list-sort-by-name: true
strip-game-colors: false
# Prevent IRC colors from appearing in game
strip-irc-colors: false
# Strip IRC background colors (recommend leaving this as true)
strip-irc-bg-colors: true
# Add IRC names to in-game tab list
custom-tab-list: false
# Nothing to see here
Expand Down

0 comments on commit 42784ff

Please sign in to comment.