diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 019b87ab..2e4de5f3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -165,7 +165,6 @@ public class MultiverseCore extends JavaPlugin implements MVCore { * Function to Register all the Events needed. */ private void registerEvents() { - // TODO add automatic listener registration through hk2 PluginManager pluginManager = getServer().getPluginManager(); getAllServices(Listener.class).forEach(listener -> pluginManager.registerEvents(listener, this)); } @@ -174,7 +173,6 @@ public class MultiverseCore extends JavaPlugin implements MVCore { * Register Multiverse-Core commands to Command Manager. */ private void registerCommands() { - // TODO add automatic command registration through hk2 var commandManager = serviceLocator.getService(MVCommandManager.class); serviceLocator.getAllServices(MultiverseCommand.class).forEach(commandManager::registerCommand); } @@ -194,7 +192,6 @@ public class MultiverseCore extends JavaPlugin implements MVCore { * Register all the destinations. */ private void registerDestinations() { - // TODO add automatic destination registration through hk2 var destinationsProvider = serviceLocator.getService(DestinationsProvider.class); serviceLocator.getAllServices(Destination.class).forEach(destinationsProvider::registerDestination); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/inject/InjectionFeature.java b/src/main/java/com/onarandombox/MultiverseCore/inject/InjectionFeature.java deleted file mode 100644 index 671ec373..00000000 --- a/src/main/java/com/onarandombox/MultiverseCore/inject/InjectionFeature.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.onarandombox.MultiverseCore.inject; - -import org.glassfish.hk2.api.ServiceLocator; -import org.jvnet.hk2.annotations.Contract; - -/** - * Marker interface for injection features. - *
- * Injection features are used to extend the functionality of the {@link PluginInjection} class. They are only used - * internally and should not be implemented by plugins. - */ -@Contract -public interface InjectionFeature { - - /** - * Called prior to the eager loading of {@link AutoLoadedService}s. - *
- * It's possible that performing injection in feature related services will cause {@link AutoLoadedService} instances to - * be created. - * - * @param pluginServiceLocator The service locator for the plugin. - */ - default void preServicesCreation(ServiceLocator pluginServiceLocator) {} - - /** - * Called after the eager loading of {@link AutoLoadedService}s. - *
- * All {@link AutoLoadedService} instances should be created by this point. - * - * @param pluginServiceLocator The service locator for the plugin. - */ - default void postServicesCreation(ServiceLocator pluginServiceLocator) {} -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/inject/PluginInjection.java b/src/main/java/com/onarandombox/MultiverseCore/inject/PluginInjection.java index 954a30d5..8d1a26f8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/inject/PluginInjection.java +++ b/src/main/java/com/onarandombox/MultiverseCore/inject/PluginInjection.java @@ -6,7 +6,6 @@ import com.onarandombox.MultiverseCore.inject.binder.ServerBinder; import io.vavr.control.Try; import org.bukkit.plugin.Plugin; import org.glassfish.hk2.api.DynamicConfigurationService; -import org.glassfish.hk2.api.MultiException; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.api.ServiceLocatorFactory; import org.glassfish.hk2.internal.ServiceLocatorFactoryImpl; @@ -14,8 +13,6 @@ import org.glassfish.hk2.utilities.ClasspathDescriptorFileFinder; import org.glassfish.hk2.utilities.ServiceLocatorUtilities; import org.jetbrains.annotations.NotNull; -import java.util.List; - /** * Provides methods to set up dependency injection for plugins. *
@@ -39,15 +36,9 @@ public final class PluginInjection { public static Try createServiceLocator(@NotNull PluginBinder pluginBinder) { var factory = new ServiceLocatorFactoryImpl(); - var systemServiceLocator = createSystemServiceLocator(factory); - - var features = systemServiceLocator - .mapTry(locator -> locator.getAllServices(InjectionFeature.class)); - - return systemServiceLocator + return createSystemServiceLocator(factory) .flatMap(systemLocator -> createServerServiceLocator(factory, systemLocator)) - .map(serverLocator -> new PluginInjection(pluginBinder, factory, serverLocator)) - .flatMap(pluginInjection -> features.flatMap(pluginInjection::load)); + .flatMap(serverLocator -> new PluginInjection(pluginBinder, factory, serverLocator).load()); } /** @@ -90,16 +81,10 @@ public final class PluginInjection { pluginServiceLocator = serviceLocatorFactory.create(plugin.getName(), serverServiceLocator); } - private Try load(List features) { + private Try load() { return Try.runRunnable(() -> ServiceLocatorUtilities.bind(pluginServiceLocator, pluginBinder)) .flatMap(ignored -> populatePluginServiceLocator(pluginServiceLocator, plugin)) - .andThenTry(() -> loadAncillaryServices(features)); - } - - private void loadAncillaryServices(List features) throws MultiException { - features.forEach(feature -> feature.preServicesCreation(pluginServiceLocator)); - pluginServiceLocator.getAllServices(AutoLoadedService.class); - features.forEach(feature -> feature.postServicesCreation(pluginServiceLocator)); + .andThenTry(locator -> locator.getAllServices(AutoLoadedService.class)); } @NotNull