mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-06 02:51:32 +01:00
[Experimental] Also catch provider instanciation exceptions
This commit is contained in:
parent
8793add589
commit
51b52ac343
@ -17,15 +17,15 @@ public class SpawnerProviderFactory {
|
||||
}
|
||||
|
||||
public SpawnerProvider getProvider() {
|
||||
List<SpawnerProvider> availableProviders = Arrays.asList(
|
||||
new BlockMetaSpawnerProvider(),
|
||||
new v1_8_R1SpawnerProvider(),
|
||||
new LegacyProvider()
|
||||
List<Class<? extends SpawnerProvider>> availableProviders = Arrays.asList(
|
||||
BlockMetaSpawnerProvider.class,
|
||||
v1_8_R1SpawnerProvider.class,
|
||||
LegacyProvider.class
|
||||
);
|
||||
SpawnerProvider finalProvider = null;
|
||||
for (SpawnerProvider provider : availableProviders) {
|
||||
finalProvider = provider;
|
||||
if (finalProvider.tryProvider()) {
|
||||
for (Class<? extends SpawnerProvider> providerClass : availableProviders) {
|
||||
finalProvider = loadProvider(providerClass);
|
||||
if (finalProvider != null && finalProvider.tryProvider()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -33,4 +33,14 @@ public class SpawnerProviderFactory {
|
||||
ess.getLogger().info("Using " + finalProvider.getHumanName() + " as spawner provider.");
|
||||
return finalProvider;
|
||||
}
|
||||
|
||||
private SpawnerProvider loadProvider(Class<? extends SpawnerProvider> providerClass) {
|
||||
SpawnerProvider provider;
|
||||
try {
|
||||
provider = providerClass.newInstance();
|
||||
return provider;
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user