[Experimental] Also catch provider instanciation exceptions

This commit is contained in:
vemacs 2015-06-17 10:38:25 -04:00
parent 8793add589
commit 51b52ac343

View File

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