mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-28 03:01:23 +01:00
Add automatic destination registration through DestinationFeature.
This commit is contained in:
parent
0c97aea3dc
commit
c6a2cee050
@ -16,13 +16,11 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import com.dumptruckman.minecraft.util.Logging;
|
import com.dumptruckman.minecraft.util.Logging;
|
||||||
import com.onarandombox.MultiverseCore.anchor.AnchorManager;
|
import com.onarandombox.MultiverseCore.anchor.AnchorManager;
|
||||||
import com.onarandombox.MultiverseCore.api.Destination;
|
|
||||||
import com.onarandombox.MultiverseCore.api.MVCore;
|
import com.onarandombox.MultiverseCore.api.MVCore;
|
||||||
import com.onarandombox.MultiverseCore.api.MVWorld;
|
import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||||
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
|
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
|
||||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||||
import com.onarandombox.MultiverseCore.destination.DestinationsProvider;
|
|
||||||
import com.onarandombox.MultiverseCore.inject.PluginInjection;
|
import com.onarandombox.MultiverseCore.inject.PluginInjection;
|
||||||
import com.onarandombox.MultiverseCore.utils.TestingMode;
|
import com.onarandombox.MultiverseCore.utils.TestingMode;
|
||||||
import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator;
|
import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator;
|
||||||
@ -117,7 +115,6 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
|||||||
// TODO consider moving this into the AnchorManager constructor
|
// TODO consider moving this into the AnchorManager constructor
|
||||||
serviceLocator.getService(AnchorManager.class).loadAnchors();
|
serviceLocator.getService(AnchorManager.class).loadAnchors();
|
||||||
this.setUpLocales();
|
this.setUpLocales();
|
||||||
this.registerDestinations();
|
|
||||||
this.setupMetrics();
|
this.setupMetrics();
|
||||||
this.saveMVConfig();
|
this.saveMVConfig();
|
||||||
this.logEnableMessage();
|
this.logEnableMessage();
|
||||||
@ -167,15 +164,6 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
|||||||
commandManager.getLocales().addMessageBundles("multiverse-core");
|
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.
|
* Setup bstats Metrics.
|
||||||
*/
|
*/
|
||||||
|
@ -3,12 +3,13 @@ package com.onarandombox.MultiverseCore.api;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import co.aikar.commands.BukkitCommandIssuer;
|
import co.aikar.commands.BukkitCommandIssuer;
|
||||||
|
import com.onarandombox.MultiverseCore.inject.AutoLoadedService;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jvnet.hk2.annotations.Contract;
|
import org.jvnet.hk2.annotations.Contract;
|
||||||
|
|
||||||
@Contract
|
@Contract
|
||||||
public interface Destination<T extends DestinationInstance> {
|
public interface Destination<T extends DestinationInstance> extends AutoLoadedService {
|
||||||
/**
|
/**
|
||||||
* Returns the identifier or prefix that is required for this destination.
|
* Returns the identifier or prefix that is required for this destination.
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
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<Destination> {
|
||||||
|
|
||||||
|
private final @NotNull Provider<DestinationsProvider> destinationsProviderProvider;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private DestinationAutoRegistration(
|
||||||
|
@NotNull Provider<DestinationsProvider> destinationsProviderProvider,
|
||||||
|
@NotNull Provider<RegistrationFilter> filterProvider
|
||||||
|
) {
|
||||||
|
super(filterProvider, Destination.class);
|
||||||
|
this.destinationsProviderProvider = destinationsProviderProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DestinationsProvider getDestinationsProvider() {
|
||||||
|
return destinationsProviderProvider.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void register(Destination instance) {
|
||||||
|
getDestinationsProvider().registerDestination(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user