From 51b52ac343f7070f58f58b2bc52324ce8fce8883 Mon Sep 17 00:00:00 2001 From: vemacs Date: Wed, 17 Jun 2015 10:38:25 -0400 Subject: [PATCH] [Experimental] Also catch provider instanciation exceptions --- .../utils/SpawnerProviderFactory.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/utils/SpawnerProviderFactory.java b/Essentials/src/com/earth2me/essentials/utils/SpawnerProviderFactory.java index 2613c25ad..3e27d7a36 100644 --- a/Essentials/src/com/earth2me/essentials/utils/SpawnerProviderFactory.java +++ b/Essentials/src/com/earth2me/essentials/utils/SpawnerProviderFactory.java @@ -17,15 +17,15 @@ public class SpawnerProviderFactory { } public SpawnerProvider getProvider() { - List availableProviders = Arrays.asList( - new BlockMetaSpawnerProvider(), - new v1_8_R1SpawnerProvider(), - new LegacyProvider() + List> 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 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 providerClass) { + SpawnerProvider provider; + try { + provider = providerClass.newInstance(); + return provider; + } catch (Throwable ignored) { + return null; + } + } }