From 5d2e68a3626edd06020ed45489ca2d1f7fa0ffeb Mon Sep 17 00:00:00 2001 From: Jeremy Wood Date: Fri, 24 Mar 2023 23:31:30 -0400 Subject: [PATCH] Revert "Add automatic destination registration through DestinationFeature." This reverts commit c6a2cee050e43d056aea74908afe7ad1a048a023. --- .../MultiverseCore/MultiverseCore.java | 12 +++++ .../MultiverseCore/api/Destination.java | 3 +- .../inject/features/DestinationFeature.java | 47 ------------------- 3 files changed, 13 insertions(+), 49 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/inject/features/DestinationFeature.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index eefc90a6..5ef6eb8b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -16,11 +16,13 @@ import java.util.stream.Collectors; import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.anchor.AnchorManager; +import com.onarandombox.MultiverseCore.api.Destination; import com.onarandombox.MultiverseCore.api.MVCore; import com.onarandombox.MultiverseCore.api.MVWorld; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider; +import com.onarandombox.MultiverseCore.destination.DestinationsProvider; import com.onarandombox.MultiverseCore.inject.PluginInjection; import com.onarandombox.MultiverseCore.utils.TestingMode; import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator; @@ -115,6 +117,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore { // TODO consider moving this into the AnchorManager constructor serviceLocator.getService(AnchorManager.class).loadAnchors(); this.setUpLocales(); + this.registerDestinations(); this.setupMetrics(); this.saveMVConfig(); this.logEnableMessage(); @@ -164,6 +167,15 @@ public class MultiverseCore extends JavaPlugin implements MVCore { commandManager.getLocales().addMessageBundles("multiverse-core"); } + /** + * 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); + } + /** * Setup bstats Metrics. */ diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Destination.java b/src/main/java/com/onarandombox/MultiverseCore/api/Destination.java index 1329fd87..8fd8d17f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/Destination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/Destination.java @@ -3,13 +3,12 @@ package com.onarandombox.MultiverseCore.api; import java.util.Collection; import co.aikar.commands.BukkitCommandIssuer; -import com.onarandombox.MultiverseCore.inject.AutoLoadedService; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jvnet.hk2.annotations.Contract; @Contract -public interface Destination extends AutoLoadedService { +public interface Destination { /** * Returns the identifier or prefix that is required for this destination. * diff --git a/src/main/java/com/onarandombox/MultiverseCore/inject/features/DestinationFeature.java b/src/main/java/com/onarandombox/MultiverseCore/inject/features/DestinationFeature.java deleted file mode 100644 index bef20cdc..00000000 --- a/src/main/java/com/onarandombox/MultiverseCore/inject/features/DestinationFeature.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.onarandombox.MultiverseCore.inject.features; - -import com.onarandombox.MultiverseCore.api.Destination; -import com.onarandombox.MultiverseCore.destination.DestinationsProvider; -import com.onarandombox.MultiverseCore.inject.InjectionFeature; -import com.onarandombox.MultiverseCore.inject.registration.AbstractAutoRegistration; -import com.onarandombox.MultiverseCore.inject.registration.AutoRegistrationBinder; -import com.onarandombox.MultiverseCore.inject.registration.RegistrationFilter; -import jakarta.inject.Inject; -import jakarta.inject.Provider; -import org.glassfish.hk2.api.ServiceLocator; -import org.glassfish.hk2.utilities.ServiceLocatorUtilities; -import org.jetbrains.annotations.NotNull; -import org.jvnet.hk2.annotations.Service; - -@Service -class DestinationFeature implements InjectionFeature { - - @Override - public void postServicesCreation(ServiceLocator locator) { - ServiceLocatorUtilities.bind(locator, AutoRegistrationBinder.with(DestinationAutoRegistration.class)); - } - - @Service - private static final class DestinationAutoRegistration extends AbstractAutoRegistration { - - private final @NotNull Provider destinationsProviderProvider; - - @Inject - private DestinationAutoRegistration( - @NotNull Provider destinationsProviderProvider, - @NotNull Provider filterProvider - ) { - super(filterProvider, Destination.class); - this.destinationsProviderProvider = destinationsProviderProvider; - } - - private DestinationsProvider getDestinationsProvider() { - return destinationsProviderProvider.get(); - } - - @Override - protected void register(Destination instance) { - getDestinationsProvider().registerDestination(instance); - } - } -}