diff --git a/src/main/java/io/github/divios/jtext/JTextBuilder.java b/src/main/java/io/github/divios/jtext/JTextBuilder.java index fb6472d..dfb213e 100644 --- a/src/main/java/io/github/divios/jtext/JTextBuilder.java +++ b/src/main/java/io/github/divios/jtext/JTextBuilder.java @@ -2,7 +2,7 @@ import io.github.divios.jtext.parsers.HexColorParser; import io.github.divios.jtext.parsers.PlaceholderApiParser; -import io.github.divios.jtext.parsers.legacyColorsParser; +import io.github.divios.jtext.parsers.legacyColorParser; import io.github.divios.jtext.parsers.miniTextParser; import io.github.divios.jtext.wrappers.Template; import org.bukkit.ChatColor; @@ -18,7 +18,7 @@ public class JTextBuilder { private static final Map defaultValues; - private static final legacyColorsParser legacyParser = new legacyColorsParser(); + private static final legacyColorParser legacyParser = new legacyColorParser(); private static final HexColorParser hexParser = new HexColorParser(); private static final PlaceholderApiParser papiParser = new PlaceholderApiParser(); private static final miniTextParser adventureParser = new miniTextParser(); diff --git a/src/main/java/io/github/divios/jtext/parsers/HexColorParser.java b/src/main/java/io/github/divios/jtext/parsers/HexColorParser.java index f82b26c..4fe4445 100644 --- a/src/main/java/io/github/divios/jtext/parsers/HexColorParser.java +++ b/src/main/java/io/github/divios/jtext/parsers/HexColorParser.java @@ -30,14 +30,7 @@ public String parse(String s) { } public String unparse(String s) { - char[] array = s.toCharArray(); - for (int i = 0; i < array.length - 1; i++) { - if (array[i] == ChatColor.COLOR_CHAR && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(array[i + 1]) != -1) { - array[i] = '&'; - array[i + 1] = Character.toLowerCase(array[i + 1]); - } - } - return new String(array); + return s; } public @Nullable Template parseAsTemplate(final String s) { diff --git a/src/main/java/io/github/divios/jtext/parsers/legacyColorParser.java b/src/main/java/io/github/divios/jtext/parsers/legacyColorParser.java new file mode 100644 index 0000000..557d600 --- /dev/null +++ b/src/main/java/io/github/divios/jtext/parsers/legacyColorParser.java @@ -0,0 +1,22 @@ +package io.github.divios.jtext.parsers; + +import net.md_5.bungee.api.ChatColor; + +public class legacyColorParser { + + public String parse(String s) { + return ChatColor.translateAlternateColorCodes('&', s); + } + + public String unparse(String s) { + char[] array = s.toCharArray(); + for (int i = 0; i < array.length - 1; i++) { + if (array[i] == ChatColor.COLOR_CHAR && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(array[i + 1]) != -1) { + array[i] = '&'; + array[i + 1] = Character.toLowerCase(array[i + 1]); + } + } + return new String(array); + } + +} diff --git a/src/main/java/io/github/divios/jtext/parsers/legacyColorsParser.java b/src/main/java/io/github/divios/jtext/parsers/legacyColorsParser.java deleted file mode 100644 index f95adc6..0000000 --- a/src/main/java/io/github/divios/jtext/parsers/legacyColorsParser.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.divios.jtext.parsers; - -import net.md_5.bungee.api.ChatColor; - -public class legacyColorsParser { - - public String parse(String s) { - return ChatColor.translateAlternateColorCodes('&', s); - } - - public String unparse(String s) { - return ChatColor.stripColor(s); - } - -} diff --git a/src/test/java/parsers/HexColorParserTest.java b/src/test/java/parsers/HexColorParserTest.java index 766e43a..732219f 100644 --- a/src/test/java/parsers/HexColorParserTest.java +++ b/src/test/java/parsers/HexColorParserTest.java @@ -1,7 +1,7 @@ package parsers; import io.github.divios.jtext.parsers.HexColorParser; -import io.github.divios.jtext.parsers.legacyColorsParser; +import io.github.divios.jtext.parsers.legacyColorParser; import org.junit.Assert; import org.junit.Test; @@ -11,7 +11,7 @@ public class HexColorParserTest { public void testHex() { String hex = "#fb1239 This is an example #fc1245"; String parsed = new HexColorParser().parse(hex); - String expected = new legacyColorsParser().parse("&x&f&b&1&2&3&9 This is an example &x&f&c&1&2&4&5"); + String expected = new legacyColorParser().parse("&x&f&b&1&2&3&9 This is an example &x&f&c&1&2&4&5"); Assert.assertEquals(expected, parsed); } diff --git a/src/test/java/parsers/legacyColorParserText.java b/src/test/java/parsers/legacyColorParserText.java new file mode 100644 index 0000000..6e6d67d --- /dev/null +++ b/src/test/java/parsers/legacyColorParserText.java @@ -0,0 +1,28 @@ +package parsers; + +import io.github.divios.jtext.parsers.legacyColorParser; +import org.bukkit.ChatColor; +import org.junit.Assert; +import org.junit.Test; + +public class legacyColorParserText { + + @Test + public void testParse() { + String toParse = "&7Hello"; + String parsed = new legacyColorParser().parse(toParse); + String expected = ChatColor.COLOR_CHAR + "7Hello"; + + Assert.assertEquals(expected, parsed); + } + + @Test + public void testUnParse() { + String toParse = ChatColor.COLOR_CHAR + "7Hello"; + String parsed = new legacyColorParser().unparse(toParse); + String expected = "&7Hello"; + + Assert.assertEquals(expected, parsed); + } + +}