Now building the color char regex dynamically.

The regex is now built from values in org.bukkit.ChatColor!
This commit is contained in:
main() 2012-10-16 20:04:44 +02:00
parent 88088548f8
commit 256d4b0abd
4 changed files with 15 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -20,8 +21,16 @@ public class SimpleMessageProvider implements LazyLocaleMessageProvider {
private static final String LOCALIZATION_FOLDER_NAME = "localization"; private static final String LOCALIZATION_FOLDER_NAME = "localization";
// Regex 1: replace all single & with the section char // Regex 1: replace all single & with the section char
private static final String FORMAT_PATTERN_1 = "([^&])(&)([^&])"; private static final String FORMAT_PATTERN_1;
private static final String FORMAT_REPL_1 = "$1\u00A7$3"; private static final String FORMAT_REPL_1;
static {
StringBuilder formatBuilder = new StringBuilder("([^&])&([");
for (ChatColor c : ChatColor.values())
formatBuilder.append(c.getChar());
FORMAT_PATTERN_1 = formatBuilder.append("])").toString();
FORMAT_REPL_1 = new StringBuilder().append("$1").append(ChatColor.COLOR_CHAR).append("$2").toString();
}
// Regex 2: replace all double & with single & // Regex 2: replace all double & with single &
private static final String FORMAT_PATTERN_2 = "&&"; private static final String FORMAT_PATTERN_2 = "&&";

View File

@ -109,6 +109,7 @@ public class TestLocalization {
assertFalse(new File(TestInstanceCreator.pluginDirectory, "en.yml").exists()); assertFalse(new File(TestInstanceCreator.pluginDirectory, "en.yml").exists());
assertTrue(new File("src/main/resources/localization/en.yml").exists()); assertTrue(new File("src/main/resources/localization/en.yml").exists());
doAnswer(new Answer<InputStream>() { doAnswer(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock invocation) throws Throwable { public InputStream answer(InvocationOnMock invocation) throws Throwable {
try { try {
return new FileInputStream("src/main/resources/" + (String) invocation.getArguments()[0]); return new FileInputStream("src/main/resources/" + (String) invocation.getArguments()[0]);
@ -165,6 +166,7 @@ public class TestLocalization {
assertTrue(file.exists()); assertTrue(file.exists());
assertTrue(new File("src/main/resources/localization/en.yml").exists()); assertTrue(new File("src/main/resources/localization/en.yml").exists());
doAnswer(new Answer<InputStream>() { doAnswer(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock invocation) throws Throwable { public InputStream answer(InvocationOnMock invocation) throws Throwable {
try { try {
return new FileInputStream("src/main/resources/" + (String) invocation.getArguments()[0]); return new FileInputStream("src/main/resources/" + (String) invocation.getArguments()[0]);

View File

@ -21,6 +21,7 @@ import java.util.logging.LogRecord;
public class MVTestLogFormatter extends Formatter { public class MVTestLogFormatter extends Formatter {
private static final DateFormat df = new SimpleDateFormat("HH:mm:ss"); private static final DateFormat df = new SimpleDateFormat("HH:mm:ss");
@Override
public String format(LogRecord record) { public String format(LogRecord record) {
StringBuilder ret = new StringBuilder(); StringBuilder ret = new StringBuilder();

View File

@ -28,6 +28,7 @@ public class WorldCreatorMatcher extends ArgumentMatcher<WorldCreator> {
this.careAboutGenerators = doICare; this.careAboutGenerators = doICare;
} }
@Override
public boolean matches(Object creator) { public boolean matches(Object creator) {
Util.log("Checking world creators."); Util.log("Checking world creators.");
if (creator == null) { if (creator == null) {