Package de.Keyle.MyPet.api.util.service
Class ServiceManager
java.lang.Object
de.Keyle.MyPet.api.util.service.ServiceManager
The
ServiceManager manages all interactions with other plugins. Services are stored by class and by the
interfaces they implement so they can also be retrieved by them. You can get instances of other plugins and check if
other plugins are active.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate(Load.State state) Activates the services registered for one startup phase.voidDisables every active service.Returns the hook/service configuration, lazily creating it on first access.<T extends ServiceContainer>
Optional<T> getService(Class<? extends T> serviceClass) returns the services of a specific classgetService(String name) returns the services with a specificServiceName<T extends ServiceContainer>
List<T> getServices(Class<? extends T> serviceClass) returns all services that inherit from a specific class/interfacebooleanhasServices(Class<? extends ServiceContainer> serviceClass) returns if services that inherit from a specific class/interface are availablebooleanisPluginAvailable(String pluginName) Reports whether a third-party plugin is installed, whether or not it is enabled.booleanisPluginAvailable(String pluginName, String className) Reports whether a third-party plugin is installed and exposes the named class, whether or not it is enabled.booleanisPluginUsable(String pluginName) Reports whether a third-party plugin is present and enabled.booleanisPluginUsable(String pluginName, String className) Reports whether a third-party plugin is present, enabled and exposes the named class.booleanisServiceActive(Class<? extends ServiceContainer> serviceClass) returns if a service that inherit from a specific class/interface is availablebooleanisServiceActive(String name) returns if a services with a specificServiceNameis availablevoidLogs every registered service and whether it is active.voidregisterService(Class<? extends ServiceContainer> serviceClass) register new services here.
-
Constructor Details
-
ServiceManager
public ServiceManager()Creates a manager. MyPet builds one at startup; addons reach it through the API.
-
-
Method Details
-
getConfig
Returns the hook/service configuration, lazily creating it on first access. Hooks may read config from their constructor (duringonLoad, beforeactivate(de.Keyle.MyPet.api.util.service.Load.State)runs), so this must always return a live config rather than the possibly-null backing field.- Returns:
- the service configuration file
-
listServices
public void listServices()Logs every registered service and whether it is active. -
registerService
register new services here. A service needs theServiceNameannotation to be accepted.- Parameters:
serviceClass- the service class
-
activate
Activates the services registered for one startup phase.- Parameters:
state- the phase whose services to activate
-
disableServices
public void disableServices()Disables every active service. Called as MyPet shuts down. -
getServices
returns all services that inherit from a specific class/interface- Type Parameters:
T- the service type wanted- Parameters:
serviceClass- class that implements fromServiceContainer- Returns:
- immutable list of instances of the service class
-
hasServices
returns if services that inherit from a specific class/interface are available- Parameters:
serviceClass- class that implements fromServiceContainer- Returns:
- if any service was found
-
getService
returns the services of a specific class- Type Parameters:
T- the service type wanted- Parameters:
serviceClass- class that implements fromServiceContainer- Returns:
- instance of the service class
-
getService
returns the services with a specificServiceName- Parameters:
name- name of the plugin- Returns:
- instance of a service class associated with the plugin name
-
isServiceActive
returns if a services with a specificServiceNameis available- Parameters:
name- name of the plugin- Returns:
- if any service was found
-
isServiceActive
returns if a service that inherit from a specific class/interface is available- Parameters:
serviceClass- class that implements fromServiceContainer- Returns:
- if any service was found
-
isPluginUsable
Reports whether a third-party plugin is present, enabled and exposes the named class.- Parameters:
pluginName- the plugin to look forclassName- a fully-qualified class it must provide- Returns:
trueif the plugin can be used
-
isPluginAvailable
Reports whether a third-party plugin is installed and exposes the named class, whether or not it is enabled.- Parameters:
pluginName- the plugin to look forclassName- a fully-qualified class it must provide- Returns:
trueif the plugin is installed
-
isPluginUsable
Reports whether a third-party plugin is present and enabled.- Parameters:
pluginName- the plugin to look for- Returns:
trueif the plugin can be used
-
isPluginAvailable
Reports whether a third-party plugin is installed, whether or not it is enabled.- Parameters:
pluginName- the plugin to look for- Returns:
trueif the plugin is installed
-