Fix "magic" tag in components actually being "obfuscated" for my terrible chatcolor workaround

This commit is contained in:
libraryaddict 2024-09-18 23:34:10 +12:00
parent e2f019ad33
commit e0cf730d96
3 changed files with 13 additions and 7 deletions

View File

@ -291,7 +291,7 @@ public class DisguiseUtilities {
private static final Pattern urlMatcher = Pattern.compile("^(?:(https?)://)?([-\\w_.]{2,}\\.[a-z]{2,4})(/\\S*)?$");
/**
* -- GETTER --
* Returns the list of people who have /disguiseViewSelf toggled
* Returns the list of people who have /disguiseViewSelf toggled
*
* @return
*/
@ -299,7 +299,7 @@ public class DisguiseUtilities {
private final static List<UUID> viewSelf = new ArrayList<>();
/**
* -- GETTER --
* Returns the list of people who have /disguiseviewbar toggled
* Returns the list of people who have /disguiseviewbar toggled
*
* @return
*/
@ -2837,11 +2837,19 @@ public class DisguiseUtilities {
return ChatColor.translateAlternateColorCodes('&', string);
}
public static String getName(ChatColor color) {
if (color == ChatColor.MAGIC) {
return "obfuscated";
}
return color.name().toLowerCase(Locale.ENGLISH);
}
public static Component getAdventureChat(String message) {
// Hacky fix because some users use color codes and I probably do somewhere
// And adventure chat will break instead of letting people live in the past
for (ChatColor color : ChatColor.values()) {
message = message.replace("§" + color.getChar(), "<" + color.name().toLowerCase(Locale.ENGLISH) + ">");
message = message.replace("§" + color.getChar(), "<" + getName(color) + ">");
}
// The <underline> thing is because the proper syntax is <underlined> but the tag name is not consistant among several plugins

View File

@ -9,8 +9,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.Locale;
public enum LibsMsg {
NO_DISGUISES_IN_USE("<red>There are no disguises in use!"),
ACTIVE_DISGUISES_COUNT("<dark_green>There are %s disguises active"),
@ -357,7 +355,7 @@ public enum LibsMsg {
String raw = getRaw();
for (ChatColor c : ChatColor.values()) {
raw = raw.replace("<" + c.name().toLowerCase(Locale.ENGLISH) + ">", "§" + c.getChar());
raw = raw.replace("<" + DisguiseUtilities.getName(c) + ">", "§" + c.getChar());
}
return raw;

View File

@ -174,7 +174,7 @@ public enum TranslateType {
value = translated.get(vanilla);
for (ChatColor color : ChatColor.values()) {
value = value.replace("§" + color.getChar(), "<" + color.name().toLowerCase(Locale.ENGLISH) + ">");
value = value.replace("§" + color.getChar(), "<" + DisguiseUtilities.getName(color) + ">");
}
}
}