Add option to set placeholder prefix and suffix

This commit is contained in:
ceze88 2024-08-21 11:28:19 +02:00
parent d2766ca7c7
commit 2fbdf10627

View File

@ -1,11 +1,15 @@
package com.craftaro.core.chat; package com.craftaro.core.chat;
public class MiniMessagePlaceholder { public class MiniMessagePlaceholder {
public static String PLACEHOLDER_PREFIX = "%";
public static String PLACEHOLDER_SUFFIX = "%";
private final String placeholder; private final String placeholder;
private final String value; private final String value;
public MiniMessagePlaceholder(String placeholder, String value) { public MiniMessagePlaceholder(String placeholder, String value) {
this.placeholder = "%" + placeholder + "%"; this.placeholder = PLACEHOLDER_PREFIX + placeholder + PLACEHOLDER_SUFFIX;
this.value = value; this.value = value;
} }
@ -16,4 +20,38 @@ public class MiniMessagePlaceholder {
public String getValue() { public String getValue() {
return this.value; return this.value;
} }
public static void setPlaceholderPrefix(String prefix) {
if (prefix == null) {
throw new IllegalArgumentException("Prefix cannot be null");
}
if (prefix.isEmpty()) {
throw new IllegalArgumentException("Prefix cannot be empty");
}
if (prefix.equals(PLACEHOLDER_SUFFIX)) {
throw new IllegalArgumentException("Prefix cannot be the same as the suffix");
}
PLACEHOLDER_PREFIX = prefix;
}
public static void setPlaceholderSuffix(String suffix) {
if (suffix == null) {
throw new IllegalArgumentException("Suffix cannot be null");
}
if (suffix.isEmpty()) {
throw new IllegalArgumentException("Suffix cannot be empty");
}
if (suffix.equals(PLACEHOLDER_PREFIX)) {
throw new IllegalArgumentException("Suffix cannot be the same as the prefix");
}
PLACEHOLDER_SUFFIX = suffix;
}
public static String getPlaceholderPrefix() {
return PLACEHOLDER_PREFIX;
}
public static String getPlaceholderSuffix() {
return PLACEHOLDER_SUFFIX;
}
} }