adding check for Plugin

This commit is contained in:
unurled 2024-10-18 17:42:42 +02:00
parent d4df3c0845
commit 714a3ca0fb
Signed by: unurled
GPG key ID: EFC5F5E709B47DDD

View file

@ -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);
}