[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() { public SpawnerProvider getProvider() {
List<SpawnerProvider> availableProviders = Arrays.asList( List<Class<? extends SpawnerProvider>> availableProviders = Arrays.asList(
new BlockMetaSpawnerProvider(), BlockMetaSpawnerProvider.class,
new v1_8_R1SpawnerProvider(), v1_8_R1SpawnerProvider.class,
new LegacyProvider() LegacyProvider.class
); );
SpawnerProvider finalProvider = null; SpawnerProvider finalProvider = null;
for (SpawnerProvider provider : availableProviders) { for (Class<? extends SpawnerProvider> providerClass : availableProviders) {
finalProvider = provider; finalProvider = loadProvider(providerClass);
if (finalProvider.tryProvider()) { if (finalProvider != null && finalProvider.tryProvider()) {
break; break;
} }
} }
@ -33,4 +33,14 @@ public class SpawnerProviderFactory {
ess.getLogger().info("Using " + finalProvider.getHumanName() + " as spawner provider."); ess.getLogger().info("Using " + finalProvider.getHumanName() + " as spawner provider.");
return finalProvider; return finalProvider;
} }
private SpawnerProvider loadProvider(Class<? extends SpawnerProvider> providerClass) {
SpawnerProvider provider;
try {
provider = providerClass.newInstance();
return provider;
} catch (Throwable ignored) {
return null;
}
}
} }