Skip to content

Commit

Permalink
Added unParse
Browse files Browse the repository at this point in the history
  • Loading branch information
divios committed Jan 18, 2022
1 parent 913922c commit d30d3e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/main/java/io/github/divios/jtext/JTextBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ public List<String> parse(List<String> collection, Player p) {
return parsedList;
}

public String unParse(String s) {
if (parseLegacyColors) s = legacyParser.unparse(s);

return s;
}

public List<String> unParse(List<String> list) {
List<String> aux = new ArrayList<>(list.size());
list.forEach(s -> aux.add(unParse(s)));

return aux;
}


private JTextBuilder copy() {
JTextBuilder clone = new JTextBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ public String parse(String s) {
}

public String unparse(String s) {
return "#" + ChatColor.stripColor(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);
}

public @Nullable Template parseAsTemplate(final String s) {
Expand Down

0 comments on commit d30d3e0

Please sign in to comment.