mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Remove InjectionFeature loading.
This commit is contained in:
parent
376fc8db18
commit
cbc3bace58
@ -165,7 +165,6 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
|||||||
* Function to Register all the Events needed.
|
* Function to Register all the Events needed.
|
||||||
*/
|
*/
|
||||||
private void registerEvents() {
|
private void registerEvents() {
|
||||||
// TODO add automatic listener registration through hk2
|
|
||||||
PluginManager pluginManager = getServer().getPluginManager();
|
PluginManager pluginManager = getServer().getPluginManager();
|
||||||
getAllServices(Listener.class).forEach(listener -> pluginManager.registerEvents(listener, this));
|
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.
|
* Register Multiverse-Core commands to Command Manager.
|
||||||
*/
|
*/
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
// TODO add automatic command registration through hk2
|
|
||||||
var commandManager = serviceLocator.getService(MVCommandManager.class);
|
var commandManager = serviceLocator.getService(MVCommandManager.class);
|
||||||
serviceLocator.getAllServices(MultiverseCommand.class).forEach(commandManager::registerCommand);
|
serviceLocator.getAllServices(MultiverseCommand.class).forEach(commandManager::registerCommand);
|
||||||
}
|
}
|
||||||
@ -194,7 +192,6 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
|||||||
* Register all the destinations.
|
* Register all the destinations.
|
||||||
*/
|
*/
|
||||||
private void registerDestinations() {
|
private void registerDestinations() {
|
||||||
// TODO add automatic destination registration through hk2
|
|
||||||
var destinationsProvider = serviceLocator.getService(DestinationsProvider.class);
|
var destinationsProvider = serviceLocator.getService(DestinationsProvider.class);
|
||||||
serviceLocator.getAllServices(Destination.class).forEach(destinationsProvider::registerDestination);
|
serviceLocator.getAllServices(Destination.class).forEach(destinationsProvider::registerDestination);
|
||||||
}
|
}
|
||||||
|
@ -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.
|
|
||||||
* <br/>
|
|
||||||
* 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.
|
|
||||||
* <br/>
|
|
||||||
* 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.
|
|
||||||
* <br/>
|
|
||||||
* All {@link AutoLoadedService} instances should be created by this point.
|
|
||||||
*
|
|
||||||
* @param pluginServiceLocator The service locator for the plugin.
|
|
||||||
*/
|
|
||||||
default void postServicesCreation(ServiceLocator pluginServiceLocator) {}
|
|
||||||
}
|
|
@ -6,7 +6,6 @@ import com.onarandombox.MultiverseCore.inject.binder.ServerBinder;
|
|||||||
import io.vavr.control.Try;
|
import io.vavr.control.Try;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.glassfish.hk2.api.DynamicConfigurationService;
|
import org.glassfish.hk2.api.DynamicConfigurationService;
|
||||||
import org.glassfish.hk2.api.MultiException;
|
|
||||||
import org.glassfish.hk2.api.ServiceLocator;
|
import org.glassfish.hk2.api.ServiceLocator;
|
||||||
import org.glassfish.hk2.api.ServiceLocatorFactory;
|
import org.glassfish.hk2.api.ServiceLocatorFactory;
|
||||||
import org.glassfish.hk2.internal.ServiceLocatorFactoryImpl;
|
import org.glassfish.hk2.internal.ServiceLocatorFactoryImpl;
|
||||||
@ -14,8 +13,6 @@ import org.glassfish.hk2.utilities.ClasspathDescriptorFileFinder;
|
|||||||
import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
|
import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides methods to set up dependency injection for plugins.
|
* Provides methods to set up dependency injection for plugins.
|
||||||
* <br/>
|
* <br/>
|
||||||
@ -39,15 +36,9 @@ public final class PluginInjection {
|
|||||||
public static Try<ServiceLocator> createServiceLocator(@NotNull PluginBinder<?> pluginBinder) {
|
public static Try<ServiceLocator> createServiceLocator(@NotNull PluginBinder<?> pluginBinder) {
|
||||||
var factory = new ServiceLocatorFactoryImpl();
|
var factory = new ServiceLocatorFactoryImpl();
|
||||||
|
|
||||||
var systemServiceLocator = createSystemServiceLocator(factory);
|
return createSystemServiceLocator(factory)
|
||||||
|
|
||||||
var features = systemServiceLocator
|
|
||||||
.mapTry(locator -> locator.getAllServices(InjectionFeature.class));
|
|
||||||
|
|
||||||
return systemServiceLocator
|
|
||||||
.flatMap(systemLocator -> createServerServiceLocator(factory, systemLocator))
|
.flatMap(systemLocator -> createServerServiceLocator(factory, systemLocator))
|
||||||
.map(serverLocator -> new PluginInjection(pluginBinder, factory, serverLocator))
|
.flatMap(serverLocator -> new PluginInjection(pluginBinder, factory, serverLocator).load());
|
||||||
.flatMap(pluginInjection -> features.flatMap(pluginInjection::load));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,16 +81,10 @@ public final class PluginInjection {
|
|||||||
pluginServiceLocator = serviceLocatorFactory.create(plugin.getName(), serverServiceLocator);
|
pluginServiceLocator = serviceLocatorFactory.create(plugin.getName(), serverServiceLocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Try<ServiceLocator> load(List<InjectionFeature> features) {
|
private Try<ServiceLocator> load() {
|
||||||
return Try.runRunnable(() -> ServiceLocatorUtilities.bind(pluginServiceLocator, pluginBinder))
|
return Try.runRunnable(() -> ServiceLocatorUtilities.bind(pluginServiceLocator, pluginBinder))
|
||||||
.flatMap(ignored -> populatePluginServiceLocator(pluginServiceLocator, plugin))
|
.flatMap(ignored -> populatePluginServiceLocator(pluginServiceLocator, plugin))
|
||||||
.andThenTry(() -> loadAncillaryServices(features));
|
.andThenTry(locator -> locator.getAllServices(AutoLoadedService.class));
|
||||||
}
|
|
||||||
|
|
||||||
private void loadAncillaryServices(List<InjectionFeature> features) throws MultiException {
|
|
||||||
features.forEach(feature -> feature.preServicesCreation(pluginServiceLocator));
|
|
||||||
pluginServiceLocator.getAllServices(AutoLoadedService.class);
|
|
||||||
features.forEach(feature -> feature.postServicesCreation(pluginServiceLocator));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
Loading…
Reference in New Issue
Block a user