Add a way to convert colorcodes into minimessage format

This commit is contained in:
len 2021-05-16 17:03:26 +02:00
parent 2096d85b53
commit 4a8f98da9f
2 changed files with 36 additions and 4 deletions

View File

@ -1,22 +1,52 @@
package com.alttd.chat.util;
import com.alttd.chat.ChatAPI;
import com.alttd.chat.ChatImplementation;
import com.alttd.chat.config.Config;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.model.group.Group;
import net.luckperms.api.model.user.User;
import net.luckperms.api.node.Node;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.UUID;
public class Utility {
public static HashMap<String, String> colors;
static { // this might be in minimessage already?
colors = new HashMap<>(); // todo map all colors to minimessage
colors.put("&0", "<black"); // and confirm these are correct
colors.put("&1", "<dark_blue"); // could also add some default hex colors here?
colors.put("&2", "<dark_green");
colors.put("&3", "<dark_aqua");
colors.put("&4", "<dark_red");
colors.put("&5", "<dark_purple");
colors.put("&6", "<gold");
colors.put("&7", "<gray");
colors.put("&8", "<dark_gray");
colors.put("&9", "<blue");
colors.put("&a", "<green");
colors.put("&b", "<aqua");
colors.put("&c", "<red>");
colors.put("&d", "<light_purple>");
colors.put("&e", "<yellow>");
colors.put("&f", "<white>");
colors.put("&g", "<minecoin_gold>"); // is this a thing?
}
public static String parseColors(String message) {
// split string in sections and check those vs looping hashmap?:/
// think this is better, but will check numbers on this
for (String key : colors.keySet()) {
if (message.contains(key)) {
message = message.replace(key, colors.get(key));
}
}
return message;
}
public static String getPrefix(UUID uuid, boolean highest) {
StringBuilder prefix = new StringBuilder();
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();

View File

@ -4,6 +4,7 @@ import com.alttd.chat.ChatPlugin;
import com.alttd.chat.config.Config;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.Utility;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.kyori.adventure.text.Component;
@ -41,6 +42,7 @@ public class ChatHandler {
prefix = plugin.getChatAPI().getPrefix(player.getUniqueId());
MiniMessage miniMessage = MiniMessage.get();
message = Utility.parseColors(message);
if(!player.hasPermission("chat.format"))
message = miniMessage.stripTokens(message);
if(message.contains("[i]"))