Fixed errors when not having SWM installed (#97)

This commit is contained in:
OmerBenGera 2024-06-01 20:05:15 +03:00
parent f301d02544
commit b1b9d1639d

View File

@ -85,13 +85,13 @@ public final class ProvidersHandler implements ProvidersManager {
try { try {
Class.forName("com.infernalsuite.aswm.api.SlimePlugin"); Class.forName("com.infernalsuite.aswm.api.SlimePlugin");
worldsProvider = createInstance("WorldsProvider_AdvancedSlimePaper"); worldsProvider = createInstanceSilently("WorldsProvider_AdvancedSlimePaper");
} catch (Throwable ignored) { } catch (ClassNotFoundException ignored) {
try { try {
Class.forName("com.grinderwolf.swm.nms.world.AbstractSlimeNMSWorld"); Class.forName("com.grinderwolf.swm.nms.world.AbstractSlimeNMSWorld");
worldsProvider = createInstance("WorldsProvider_AdvancedSlimeWorldManager"); worldsProvider = createInstanceSilently("WorldsProvider_AdvancedSlimeWorldManager");
} catch (Throwable error) { } catch (Throwable error) {
worldsProvider = createInstance("WorldsProvider_SlimeWorldManager"); worldsProvider = createInstanceSilently("WorldsProvider_SlimeWorldManager");
} }
} }
@ -140,6 +140,14 @@ public final class ProvidersHandler implements ProvidersManager {
return null; return null;
} }
private <T> Optional<T> createInstanceSilently(String className) {
try {
return createInstance(className);
} catch (Throwable error) {
return Optional.empty();
}
}
private <T> Optional<T> createInstance(String className) { private <T> Optional<T> createInstance(String className) {
try { try {
Class<?> clazz = Class.forName("com.bgsoftware.wildloaders.hooks." + className); Class<?> clazz = Class.forName("com.bgsoftware.wildloaders.hooks." + className);