From 64cf78101cd4acc3b2d309230c74b7ca7f3e16da Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 2 Aug 2019 16:07:37 +0300 Subject: [PATCH] Register DataExtension super class Providers Affects issues: - Close #1121 --- .../extractor/ExtensionExtractor.java | 6 +- .../ExtensionServiceImplementation.java | 13 ++-- .../implementation/ExtensionRegister.java | 68 +++++++++++-------- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java index 81f164a74..90c9a924d 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java @@ -73,7 +73,7 @@ public final class ExtensionExtractor { } private Method[] getMethods() { - return extension.getClass().getDeclaredMethods(); + return extension.getClass().getMethods(); } public void extractAnnotationInformation() { @@ -92,7 +92,9 @@ public final class ExtensionExtractor { methodAnnotations = new MethodAnnotations(); for (Method method : getMethods()) { - if (!Modifier.isPublic(method.getModifiers())) { + int modifiers = method.getModifiers(); + if (!Modifier.isPublic(modifiers) + || Modifier.isStatic(modifiers)) { continue; } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java index dc1302d1a..0b2ed0ec5 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java @@ -82,9 +82,14 @@ public class ExtensionServiceImplementation implements ExtensionService { } public void register() { - extensionRegister.registerBuiltInExtensions(); - if (Check.isBukkitAvailable()) extensionRegister.registerBukkitExtensions(); - if (Check.isBungeeAvailable()) extensionRegister.registerBungeeExtensions(); + try { + extensionRegister.registerBuiltInExtensions(); + if (Check.isBukkitAvailable()) extensionRegister.registerBukkitExtensions(); + if (Check.isBungeeAvailable()) extensionRegister.registerBungeeExtensions(); + } catch (IllegalStateException failedToRegisterOne) { + logger.warn("One or more extensions failed to register:"); + errorHandler.log(L.WARN, this.getClass(), failedToRegisterOne); + } } @Override @@ -104,7 +109,7 @@ public class ExtensionServiceImplementation implements ExtensionService { processing.submitNonCritical(() -> updateServerValues(gatherer, CallEvents.SERVER_EXTENSION_REGISTER)); - logger.getDebugLogger().logOn(DebugChannels.DATA_EXTENSIONS, pluginName + " extension registered."); + logger.info("Registered extension: " + pluginName); return Optional.of(new CallerImplementation(gatherer, this, processing)); } diff --git a/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java b/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java index fda3265cd..43bcdde31 100644 --- a/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java +++ b/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java @@ -22,7 +22,8 @@ import com.djrapitops.plan.extension.ExtensionService; import javax.inject.Inject; import javax.inject.Singleton; -import java.util.function.Consumer; +import java.util.Optional; +import java.util.function.Supplier; /** * In charge of registering built in {@link com.djrapitops.plan.extension.DataExtension} implementations. @@ -32,6 +33,8 @@ import java.util.function.Consumer; @Singleton public class ExtensionRegister { + private IllegalStateException registerException; + @Inject public ExtensionRegister() { /* Required for dagger injection */ @@ -42,43 +45,36 @@ public class ExtensionRegister { // registerBuiltInExtensions method will not be called unless Plan has enabled properly ExtensionService extensionService = ExtensionService.getInstance(); - Consumer register = extensionService::register; - new AACExtensionFactory().createExtension().ifPresent(register); - new AdvancedAchievementsExtensionFactory().createExtension().ifPresent(register); - new AdvancedBanExtensionFactory().createExtension().ifPresent(register); - new ASkyBlockExtensionFactory().createExtension().ifPresent(register); - new BanManagerExtensionFactory().createExtension().ifPresent(register); - new CoreProtectExtensionFactory().createExtension().ifPresent(register); - new DiscordSRVExtensionFactory().createExtension().ifPresent(register); + register(new AACExtensionFactory()::createExtension); + register(new AdvancedAchievementsExtensionFactory()::createExtension); + register(new AdvancedBanExtensionFactory()::createExtension); + register(new ASkyBlockExtensionFactory()::createExtension); + register(new BanManagerExtensionFactory()::createExtension); + register(new CoreProtectExtensionFactory()::createExtension); + register(new DiscordSRVExtensionFactory()::createExtension); registerEssentialsExtension(extensionService); - new GriefPreventionExtensionFactory().createExtension().ifPresent(register); - new GriefPreventionSpongeExtensionFactory().createExtension().ifPresent(register); - new GriefPreventionPlusExtensionFactory().createExtension().ifPresent(register); - new McMMOExtensionFactory().createExtension().ifPresent(register); + register(new GriefPreventionExtensionFactory()::createExtension); + register(new GriefPreventionSpongeExtensionFactory()::createExtension); + register(new GriefPreventionPlusExtensionFactory()::createExtension); + register(new McMMOExtensionFactory()::createExtension); registerMinigameLibExtensions(extensionService); - new NucleusExtensionFactory().createExtension().ifPresent(register); - new NuVotifierExtensionFactory().createExtension().ifPresent(register); - new ProtocolSupportExtensionFactory().createExtension().ifPresent(register); - new RedProtectExtensionFactory().createExtension().ifPresent(register); - new SpongeEconomyExtensionFactory().createExtension().ifPresent(register); - new SuperbVoteExtensionFactory().createExtension().ifPresent(register); - new VaultExtensionFactory().createExtension().ifPresent(register); + register(new NucleusExtensionFactory()::createExtension); + register(new NuVotifierExtensionFactory()::createExtension); + register(new ProtocolSupportExtensionFactory()::createExtension); + register(new RedProtectExtensionFactory()::createExtension); + register(new SpongeEconomyExtensionFactory()::createExtension); + register(new SuperbVoteExtensionFactory()::createExtension); + register(new VaultExtensionFactory()::createExtension); + + if (registerException != null) throw registerException; } public void registerBukkitExtensions() { - // No need to catch exceptions here, - // registerBuiltInExtensions method will not be called unless Plan has enabled properly - ExtensionService extensionService = ExtensionService.getInstance(); - - new ViaVersionBukkitExtensionFactory().createExtension().ifPresent(extensionService::register); + register(new ViaVersionBukkitExtensionFactory()::createExtension); } public void registerBungeeExtensions() { - // No need to catch exceptions here, - // registerBuiltInExtensions method will not be called unless Plan has enabled properly - ExtensionService extensionService = ExtensionService.getInstance(); - - new ViaVersionBungeeExtensionFactory().createExtension().ifPresent(extensionService::register); + register(new ViaVersionBungeeExtensionFactory()::createExtension); } private void registerEssentialsExtension(ExtensionService extensionService) { @@ -94,4 +90,16 @@ public class ExtensionRegister { } } + private void register(Supplier> extension) { + ExtensionService extensionService = ExtensionService.getInstance(); + try { + extension.get().ifPresent(extensionService::register); + } catch (IllegalStateException e) { + if (registerException == null) { + registerException = e; + } else { + registerException.addSuppressed(e); + } + } + } } \ No newline at end of file