Skip to content

Commit

Permalink
check for necessary methods as well to avoid errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 7, 2024
1 parent 1b9986f commit 006252e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions shared/src/main/java/me/xginko/aef/utils/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -90,11 +91,11 @@ public static int getApproximateByteSize(@Nullable Iterable<ItemStack> 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())
Expand Down

0 comments on commit 006252e

Please sign in to comment.