Class ServiceManager

java.lang.Object
de.Keyle.MyPet.api.util.service.ServiceManager

public class ServiceManager extends Object
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 Details

    • ServiceManager

      public ServiceManager()
      Creates a manager. MyPet builds one at startup; addons reach it through the API.
  • Method Details

    • getConfig

      public ConfigurationYAML getConfig()
      Returns the hook/service configuration, lazily creating it on first access. Hooks may read config from their constructor (during onLoad, before activate(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

      public void registerService(Class<? extends ServiceContainer> serviceClass)
      register new services here. A service needs the ServiceName annotation to be accepted.
      Parameters:
      serviceClass - the service class
    • activate

      public void activate(Load.State state)
      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

      public <T extends ServiceContainer> List<T> getServices(Class<? extends T> serviceClass)
      returns all services that inherit from a specific class/interface
      Type Parameters:
      T - the service type wanted
      Parameters:
      serviceClass - class that implements from ServiceContainer
      Returns:
      immutable list of instances of the service class
    • hasServices

      public boolean hasServices(Class<? extends ServiceContainer> serviceClass)
      returns if services that inherit from a specific class/interface are available
      Parameters:
      serviceClass - class that implements from ServiceContainer
      Returns:
      if any service was found
    • getService

      public <T extends ServiceContainer> Optional<T> getService(Class<? extends T> serviceClass)
      returns the services of a specific class
      Type Parameters:
      T - the service type wanted
      Parameters:
      serviceClass - class that implements from ServiceContainer
      Returns:
      instance of the service class
    • getService

      public Optional<ServiceContainer> getService(String name)
      returns the services with a specific ServiceName
      Parameters:
      name - name of the plugin
      Returns:
      instance of a service class associated with the plugin name
    • isServiceActive

      public boolean isServiceActive(String name)
      returns if a services with a specific ServiceName is available
      Parameters:
      name - name of the plugin
      Returns:
      if any service was found
    • isServiceActive

      public boolean isServiceActive(Class<? extends ServiceContainer> serviceClass)
      returns if a service that inherit from a specific class/interface is available
      Parameters:
      serviceClass - class that implements from ServiceContainer
      Returns:
      if any service was found
    • isPluginUsable

      public boolean isPluginUsable(String pluginName, String className)
      Reports whether a third-party plugin is present, enabled and exposes the named class.
      Parameters:
      pluginName - the plugin to look for
      className - a fully-qualified class it must provide
      Returns:
      true if the plugin can be used
    • isPluginAvailable

      public boolean isPluginAvailable(String pluginName, String className)
      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 for
      className - a fully-qualified class it must provide
      Returns:
      true if the plugin is installed
    • isPluginUsable

      public boolean isPluginUsable(String pluginName)
      Reports whether a third-party plugin is present and enabled.
      Parameters:
      pluginName - the plugin to look for
      Returns:
      true if the plugin can be used
    • isPluginAvailable

      public boolean isPluginAvailable(String pluginName)
      Reports whether a third-party plugin is installed, whether or not it is enabled.
      Parameters:
      pluginName - the plugin to look for
      Returns:
      true if the plugin is installed