diff --git a/src/main/java/com/songoda/core/utils/TextUtils.java b/src/main/java/com/songoda/core/utils/TextUtils.java
index bfdbbf6d..73bcb8ce 100644
--- a/src/main/java/com/songoda/core/utils/TextUtils.java
+++ b/src/main/java/com/songoda/core/utils/TextUtils.java
@@ -26,14 +26,51 @@ public class TextUtils {
return ChatColor.translateAlternateColorCodes('&', text);
}
+ /**
+ * Convert a string to an invisible colored string that's lore-safe
+ * (Safe to use as lore)
+ * Note: Do not use semi-colons in this string, or they will be lost when decoding!
+ *
+ * @param s string to convert
+ * @return encoded string
+ */
+ public static String convertToInvisibleLoreString(String s) {
+ if (s == null || s.equals(""))
+ return "";
+ StringBuilder hidden = new StringBuilder();
+ for (char c : s.toCharArray()) hidden.append(ChatColor.COLOR_CHAR).append(';').append(ChatColor.COLOR_CHAR).append(c);
+ return hidden.toString();
+ }
+
+ /**
+ * Convert a string to an invisible colored string
+ * (Not safe to use as lore)
+ * Note: Do not use semi-colons in this string, or they will be lost when decoding!
+ *
+ * @param s string to convert
+ * @return encoded string
+ */
public static String convertToInvisibleString(String s) {
if (s == null || s.equals(""))
return "";
StringBuilder hidden = new StringBuilder();
- for (char c : s.toCharArray()) hidden.append(ChatColor.COLOR_CHAR + "").append(c);
+ for (char c : s.toCharArray()) hidden.append(ChatColor.COLOR_CHAR).append(c);
return hidden.toString();
}
+ /**
+ * Removes color markers used to encode strings as invisible text
+ *
+ * @param s encoded string
+ * @return string with color markers removed
+ */
+ public static String convertFromInvisibleString(String s) {
+ if (s == null || s.equals("")) {
+ return "";
+ }
+ return s.replaceAll(ChatColor.COLOR_CHAR + ";" + ChatColor.COLOR_CHAR + "|" + ChatColor.COLOR_CHAR, "");
+ }
+
protected static final List supportedCharsets = new ArrayList();
static {