Update minimessage and add helper methods
This commit is contained in:
@@ -4,7 +4,7 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT") // Minimessage
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT") // Minimessage
|
||||
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
|
||||
compileOnly("net.luckperms:api:5.3") // Luckperms
|
||||
}
|
||||
|
||||
@@ -9,27 +9,28 @@ import java.util.stream.Collectors;
|
||||
|
||||
public final class ChatUserManager {
|
||||
|
||||
private static ArrayList<ChatUser> chatUsers;
|
||||
private static Map<UUID, ChatUser> chatUsers;
|
||||
|
||||
public static void initialize() {
|
||||
chatUsers = new ArrayList<>();
|
||||
chatUsers = new TreeMap<>();
|
||||
}
|
||||
|
||||
public static void addUser(ChatUser user) {
|
||||
chatUsers.add(user);
|
||||
chatUsers.put(user.getUuid(), user);
|
||||
}
|
||||
|
||||
public static void removeUser(ChatUser user) {
|
||||
chatUsers.remove(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ChatUser for this player or query the database to read the data.
|
||||
*
|
||||
* @param uuid the player who's ChatUser you'd like to get
|
||||
* @return The ChatUser loaded from database or null if it's not existing.
|
||||
*/
|
||||
public static ChatUser getChatUser(UUID uuid) {
|
||||
for(ChatUser user : chatUsers) {
|
||||
if(uuid.equals(user.getUuid())) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
return Queries.loadChatUser(uuid);
|
||||
return chatUsers.computeIfAbsent(uuid, k -> Queries.loadChatUser(uuid));
|
||||
}
|
||||
|
||||
public List<Mail> getUnReadMail(ChatUser user) {
|
||||
@@ -38,7 +39,4 @@ public final class ChatUserManager {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected static List<ChatUser> getChatUsers() {
|
||||
return Collections.unmodifiableList(chatUsers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
@@ -25,6 +27,8 @@ public class Utility {
|
||||
static final Pattern DEFAULT_URL_PATTERN = Pattern.compile("(?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?");
|
||||
static final Pattern URL_SCHEME_PATTERN = Pattern.compile("^[a-z][a-z0-9+\\-.]*:");
|
||||
|
||||
private static MiniMessage miniMessage = null;
|
||||
|
||||
public static String stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
|
||||
public static HashMap<String, String> colors;
|
||||
private static LegacyComponentSerializer legacySerializer;
|
||||
@@ -211,9 +215,8 @@ public class Utility {
|
||||
stringBuilder.append("<").append(hexColor1).append(">").append(split[i]);
|
||||
}
|
||||
}
|
||||
MiniMessage miniMessage = MiniMessage.get();
|
||||
return stringBuilder.length()==0 ? miniMessage.parse(message)
|
||||
: miniMessage.parse(stringBuilder.toString());
|
||||
return stringBuilder.length() == 0 ? Utility.parseMiniMessage(message)
|
||||
: Utility.parseMiniMessage(stringBuilder.toString());
|
||||
}
|
||||
|
||||
public static String formatText(String message) {
|
||||
@@ -241,4 +244,25 @@ public class Utility {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static Component parseMiniMessage(String message) {
|
||||
return parseMiniMessage(message, null);
|
||||
}
|
||||
|
||||
public static Component parseMiniMessage(String message, List<Template> templates) {
|
||||
if (templates == null) {
|
||||
return getMiniMessage().deserialize(message);
|
||||
} else {
|
||||
return getMiniMessage().deserialize(message, TemplateResolver.templates(templates));
|
||||
}
|
||||
}
|
||||
|
||||
public static String stripTokens(String input) {
|
||||
return getMiniMessage().stripTokens(input);
|
||||
}
|
||||
|
||||
public static MiniMessage getMiniMessage() {
|
||||
if (miniMessage == null) miniMessage = MiniMessage.miniMessage();
|
||||
return miniMessage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user