From 890216a19acea1ff427101873f1ca2de4f7e0bc6 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Thu, 4 Apr 2024 21:53:06 -0500 Subject: [PATCH] fix ModMenu error if YACL isn't installed --- src/main/java/one/oth3r/sit/ModMenu.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/one/oth3r/sit/ModMenu.java b/src/main/java/one/oth3r/sit/ModMenu.java index 0d45772..bba82ea 100644 --- a/src/main/java/one/oth3r/sit/ModMenu.java +++ b/src/main/java/one/oth3r/sit/ModMenu.java @@ -21,6 +21,8 @@ public class ModMenu implements ModMenuApi { } @Override public ConfigScreenFactory getModConfigScreenFactory() { + // return null if YACL isn't installed to not throw an error + if (!yaclCheck()) return screen -> null; return parent -> YetAnotherConfigLib.createBuilder().save(Config::save) .title(Text.of("Sit!")) .category(ConfigCategory.createBuilder() @@ -198,4 +200,17 @@ public class ModMenu implements ModMenuApi { .build()) .build().generateScreen(parent); } + + /** + * check if YACL is installed by getting a class and seeing if it throws + * @return if YACL is installed + */ + public static boolean yaclCheck() { + try { + Class.forName("dev.isxander.yacl3.platform.fabric.YACLPlatformImpl"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } }