Skip to content

Commit

Permalink
Fix plugin initialization on Purpur 1.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Krakenied committed Dec 26, 2024
1 parent 8897026 commit 423d865
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,34 @@
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public final class MiniMessageParser {

private final MiniMessage miniMessage;

public MiniMessageParser() {
this.miniMessage = MiniMessage.miniMessage();
Method miniMessageGetter;

try {
miniMessageGetter = MiniMessage.class.getMethod("miniMessage");
} catch (final NoSuchMethodException e) {
try {
// For some reason on latest Purpur 1.17.1 there is no MiniMessage#miniMessage method
// https://github.com/LMBishop/Quests/issues/756
//noinspection JavaReflectionMemberAccess
miniMessageGetter = MiniMessage.class.getMethod("get");
} catch (final NoSuchMethodException e2) {
throw new IllegalStateException("could not find MiniMessage getter");
}
}

try {
this.miniMessage = (MiniMessage) miniMessageGetter.invoke(null);
} catch (final IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("could not get MiniMessage instance", e);
}
}

public void send(final @NotNull CommandSender who, final @NotNull String message) {
Expand Down

0 comments on commit 423d865

Please sign in to comment.