diff options
| author | Cow <cow@volloeko.de> | 2021-08-02 12:43:41 +0200 |
|---|---|---|
| committer | Cow <cow@volloeko.de> | 2021-08-02 12:43:41 +0200 |
| commit | d2490aad11dec8227b132d55b5afd9a65834011b (patch) | |
| tree | 7aa8433f9d8eb2f5137ad90f2da7f7ccc253ac29 /src/main/java/de/cowtipper/cowlection/util | |
| parent | ac41ecd855a511c76499d61983ddb6c723ae0844 (diff) | |
| download | Cowlection-d2490aad11dec8227b132d55b5afd9a65834011b.tar.gz Cowlection-d2490aad11dec8227b132d55b5afd9a65834011b.tar.bz2 Cowlection-d2490aad11dec8227b132d55b5afd9a65834011b.zip | |
Added Party Notes rule editor
Diffstat (limited to 'src/main/java/de/cowtipper/cowlection/util')
| -rw-r--r-- | src/main/java/de/cowtipper/cowlection/util/Utils.java | 19 |
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 |
