aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/cowtipper/cowlection/util/Utils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/cowtipper/cowlection/util/Utils.java')
-rw-r--r--src/main/java/de/cowtipper/cowlection/util/Utils.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/util/Utils.java b/src/main/java/de/cowtipper/cowlection/util/Utils.java
index 35b1231..2db72d1 100644
--- a/src/main/java/de/cowtipper/cowlection/util/Utils.java
+++ b/src/main/java/de/cowtipper/cowlection/util/Utils.java
@@ -24,12 +24,15 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public final class Utils {
public static final Pattern VALID_UUID_PATTERN = Pattern.compile("^(\\w{8})-(\\w{4})-(\\w{4})-(\\w{4})-(\\w{12})$");
private static final Pattern VALID_USERNAME = Pattern.compile("^[\\w]{1,16}$");
+ private static final Pattern ALTERNATE_COLOR_CODES_PATTERN = Pattern.compile("&([0-9a-fk-or])");
+ private static final Pattern MC_COLOR_CODES_PATTERN = Pattern.compile("§([0-9a-fk-or])");
private static final NavigableMap<Double, Character> NUMBER_SUFFIXES = new TreeMap<>();
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#,##0.#", new DecimalFormatSymbols(Locale.ENGLISH));
private static final DecimalFormat NUMBER_FORMAT = new DecimalFormat("#,##0", new DecimalFormatSymbols(Locale.ENGLISH));
@@ -57,6 +60,22 @@ public final class Utils {
}
/**
+ * Replaces &colorCode with §colorCode
+ */
+ public static String toMcColorCodes(String string) {
+ Matcher matcher = ALTERNATE_COLOR_CODES_PATTERN.matcher(string);
+ return matcher.replaceAll("§$1");
+ }
+
+ /**
+ * Replaces §colorCode with &colorCode
+ */
+ public static String toHumanColorCodes(String string) {
+ Matcher matcher = MC_COLOR_CODES_PATTERN.matcher(string);
+ return matcher.replaceAll("&$1");
+ }
+
+ /**
* Turn timestamp into pretty-formatted duration and date details.
*
* @param timestamp last login/logout