From 006252ef420f561a35e9079fc491caa5d4c1a618 Mon Sep 17 00:00:00 2001 From: xGinko Date: Wed, 7 Aug 2024 23:31:43 +0200 Subject: [PATCH] check for necessary methods as well to avoid errors --- .../src/main/java/me/xginko/aef/utils/ItemUtil.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/shared/src/main/java/me/xginko/aef/utils/ItemUtil.java b/shared/src/main/java/me/xginko/aef/utils/ItemUtil.java index 2c8879b1..9dffb90f 100644 --- a/shared/src/main/java/me/xginko/aef/utils/ItemUtil.java +++ b/shared/src/main/java/me/xginko/aef/utils/ItemUtil.java @@ -17,12 +17,13 @@ public class ItemUtil { - private static final boolean BUNDLES_SUPPPORTED, MINI_MESSAGE_SUPPORTED; + private static final boolean BUNDLES_SUPPPORTED, USE_MINIMSG_BOOKMETA; static { - MINI_MESSAGE_SUPPORTED + USE_MINIMSG_BOOKMETA = Crafty.hasClass("net.kyori.adventure.text.minimessage.MiniMessage") - && Crafty.hasMethod(MiniMessage.class, "miniMessage"); + && Crafty.hasMethod(MiniMessage.class, "miniMessage") + && Crafty.hasMethod(BookMeta.class, "pages"); BUNDLES_SUPPPORTED = XMaterial.BUNDLE.isSupported() @@ -90,11 +91,11 @@ public static int getApproximateByteSize(@Nullable Iterable inventory } public static int getApproximateByteSize(@NotNull BookMeta bookMeta, boolean utf16) { - return MINI_MESSAGE_SUPPORTED ? getApproximateByteSizeMM(bookMeta, utf16) : getApproximateByteSizeLegacy(bookMeta, utf16); + return USE_MINIMSG_BOOKMETA ? getApproximateByteSizeModern(bookMeta, utf16) : getApproximateByteSizeLegacy(bookMeta, utf16); } @SuppressWarnings("DataFlowIssue") // Legitimate because we make sure no values are null by testing .hasX() - private static int getApproximateByteSizeMM(@NotNull BookMeta bookMeta, boolean utf16) { + private static int getApproximateByteSizeModern(@NotNull BookMeta bookMeta, boolean utf16) { StringBuilder content = new StringBuilder(); if (bookMeta.hasTitle())