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 {
Class.forName("com.infernalsuite.aswm.api.SlimePlugin");
worldsProvider = createInstance("WorldsProvider_AdvancedSlimePaper");
} catch (Throwable ignored) {
worldsProvider = createInstanceSilently("WorldsProvider_AdvancedSlimePaper");
} catch (ClassNotFoundException ignored) {
try {
Class.forName("com.grinderwolf.swm.nms.world.AbstractSlimeNMSWorld");
worldsProvider = createInstance("WorldsProvider_AdvancedSlimeWorldManager");
worldsProvider = createInstanceSilently("WorldsProvider_AdvancedSlimeWorldManager");
} catch (Throwable error) {
worldsProvider = createInstance("WorldsProvider_SlimeWorldManager");
worldsProvider = createInstanceSilently("WorldsProvider_SlimeWorldManager");
}
}
@ -140,6 +140,14 @@ public final class ProvidersHandler implements ProvidersManager {
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) {
try {
Class<?> clazz = Class.forName("com.bgsoftware.wildloaders.hooks." + className);