Test for adventure text support by trying to use it

This commit is contained in:
libraryaddict 2021-06-11 05:57:45 +12:00
parent cafc9f22d6
commit d0ce9c0536

View File

@ -222,8 +222,15 @@ public class DisguiseUtilities {
public static boolean hasAdventureTextSupport() {
if (adventureTextSupport == null) {
try {
Class.forName("net.kyori.adventure.text.minimessage.MiniMessage");
adventureTextSupport = true;
// Force a test for support by actually trying to use it all
BaseComponent[] test1 = ComponentSerializer.parse(GsonComponentSerializer.gson().serialize(getAdventureChat("<green>test")));
WrappedChatComponent test2 = AdventureComponentConverter.fromComponent(DisguiseUtilities.getAdventureChat("<green>test"));
if (test1 == null || test1.length == 0 || test2 == null) {
adventureTextSupport = false;
}
} catch (Throwable ex) {
adventureTextSupport = false;
}