Skip to content

Commit

Permalink
[MiniMessage] Fix critical error when an ancient MM version is present
Browse files Browse the repository at this point in the history
  • Loading branch information
NEZNAMY committed Jan 25, 2025
1 parent 2a4f918 commit 9c2fac6
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.neznamy.tab.shared.hook;

import lombok.Getter;
import me.neznamy.tab.shared.TAB;
import me.neznamy.tab.shared.chat.AdventureComponent;
import me.neznamy.tab.shared.chat.TabComponent;
Expand All @@ -14,14 +13,28 @@
*/
public class MiniMessageHook {

/** Flag tracking whether MiniMessage is available on the server or not */
@Getter
private static final boolean available = ReflectionUtils.classExists("net.kyori.adventure.text.minimessage.MiniMessage") &&
ReflectionUtils.classExists("net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer");

/** Minimessage deserializer with disabled component post-processing */
@Nullable
private static final MiniMessage mm = available ? MiniMessage.builder().postProcessor(c->c).build() : null;
private static final MiniMessage mm = createMiniMessage();

@Nullable
private static MiniMessage createMiniMessage() {
try {
if (ReflectionUtils.classExists("net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer")) {
return MiniMessage.builder().postProcessor(c->c).build();
}
} catch (Throwable ignored) {}
return null;
}

/**
* Returns {@code true} if MiniMessage is available on the server, {@code false} if not.
*
* @return {@code true} if MiniMessage is available on the server, {@code false} if not
*/
public static boolean isAvailable() {
return mm != null;
}

/**
* Attempts to parse the text into an adventure component using MiniMessage syntax. If MiniMessage is
Expand Down

0 comments on commit 9c2fac6

Please sign in to comment.