From 714a3ca0fb3b7d184c6a7fe2b89f6c49be912d51 Mon Sep 17 00:00:00 2001 From: unurled Date: Fri, 18 Oct 2024 17:42:42 +0200 Subject: [PATCH] adding check for Plugin --- src/main/java/me/unurled/srcore/SRCore.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/unurled/srcore/SRCore.java b/src/main/java/me/unurled/srcore/SRCore.java index 128e16d..abcd38a 100644 --- a/src/main/java/me/unurled/srcore/SRCore.java +++ b/src/main/java/me/unurled/srcore/SRCore.java @@ -25,7 +25,10 @@ public final class SRCore { * @return The instance of the SRCore */ public static @NotNull SRCore getInstance() { - return instance == null ? new SRCore() : instance; + if (instance == null) { + instance = new SRCore(); + } + return instance; } /** @@ -39,7 +42,7 @@ public final class SRCore { if (plugin == null) throw new IllegalStateException( - "Plugin is not set. Set it using SRCore.setPlugin(Plugin plugin)"); + "Plugin is not set. Set it using SRCore.getInstance().setPlugin(Plugin plugin)"); } return plugin; @@ -53,7 +56,10 @@ public final class SRCore { public void setPlugin(@Nullable Plugin plugin) { if (this.plugin != null) throw new IllegalStateException("Plugin is already set"); - if (plugin == null) return; + if (plugin == null) { + error("Plugin passed was null"); + return; + } this.plugin = plugin; } @@ -65,7 +71,8 @@ public final class SRCore { if (PLUGIN_CLASS_LOADER_CLASS.isInstance(loader)) { return ReflectionUtils.getFieldValue(PLUGIN_CLASS_LOADER_PLUGIN_FIELD, loader); } else if (PAPER_PLUGIN_CLASS_LOADER_CLASS != null - && PAPER_PLUGIN_CLASS_LOADER_CLASS.isInstance(loader)) { + && PAPER_PLUGIN_CLASS_LOADER_CLASS.isInstance(loader) + && PAPER_PLUGIN_CLASS_LOADER_GET_LOADED_JAVA_PLUGIN_METHOD != null) { return ReflectionUtils.invokeMethod( PAPER_PLUGIN_CLASS_LOADER_GET_LOADED_JAVA_PLUGIN_METHOD, loader); }