Class AbstractSubsystem<C extends SubsystemConfig<S>,S extends AbstractSubsystem<C,S>>

java.lang.Object
com.kamikazejam.kamicommon.util.log.LoggerService
com.kamikazejam.kamicommon.subsystem.AbstractSubsystem<C,S>
All Implemented Interfaces:
ObservableConfig, CoreMethods
Direct Known Subclasses:
Feature, Module

public abstract class AbstractSubsystem<C extends SubsystemConfig<S>,S extends AbstractSubsystem<C,S>> extends LoggerService implements CoreMethods, ObservableConfig
  • Constructor Details

    • AbstractSubsystem

      public AbstractSubsystem()
  • Method Details

    • getPlugin

      public abstract KamiPlugin getPlugin()
      Returns:
      The KamiPlugin that this subsystem is registered to
    • onEnable

      public abstract void onEnable()
    • onDisable

      public abstract void onDisable()
      This method is called when a subsystem is shutting down (server shut down most likely, but it could be manually called)
      You should handle your disable logic here, not including any unregistration of commands/listeners/tasks/disableables. (That is handled automatically)
    • registerCommands

      public final int registerCommands(KamiCommand... commands)
      Registers the provided commands with this subsystem.
      Previously registered commands will not be registered again.
      Specified by:
      registerCommands in interface CoreMethods
      Parameters:
      commands - The commands to register
      Returns:
      The number of commands that were registered with this subsystem
    • unregisterCommands

      public final int unregisterCommands(KamiCommand... commands)
      Unregisters the specified commands, if this subsystem has registered them prior.
      ! If a KamiCommand is passed here that was not registered by this subsystem, it will not be unregistered !
      Specified by:
      unregisterCommands in interface CoreMethods
      Returns:
      The number of commands that were unregistered from this subsystem
    • unregisterCommands

      public final int unregisterCommands()
      Unregisters ALL commands that this subsystem has registered.
      Specified by:
      unregisterCommands in interface CoreMethods
      Returns:
      The number of commands that were unregistered
    • getName

      public abstract String getName()
      Returns:
      The name of this subsystem
    • defaultPrefix

      @NotNull public abstract @NotNull String defaultPrefix()
      Returns:
      The default logging prefix for this subsystem
    • getConfigFileDestination

      @NotNull public abstract @NotNull File getConfigFileDestination()
    • reloadConfig

      public final void reloadConfig()
      Reload the subsystem config from its yaml file on disk.
      Will also call any ObservableConfig hooks registered via registerReloadHook(ObservableConfig)
      Specified by:
      reloadConfig in interface CoreMethods
    • saveConfig

      public void saveConfig()
      Specified by:
      saveConfig in interface CoreMethods
    • getConfigResourcePath

      @NotNull public abstract @NotNull String getConfigResourcePath()
    • getConfig

      @NotNull public C getConfig()
    • initializeConfig

      @Internal public void initializeConfig(@NotNull C config)
    • createConfig

      @NotNull protected abstract C createConfig()
    • getKamiConfig

      @NotNull public @NotNull KamiConfigExt getKamiConfig()
      Specified by:
      getKamiConfig in interface CoreMethods
    • registerReloadHook

      public final void registerReloadHook(@NotNull @NotNull ObservableConfig config)
      Adds a hook to call this observable's reloadObservableConfig() method whenever this subsystem's config is reloaded.

      This means that when this subsystem gets reloaded, this config will also be reloaded.
    • handleEnable

      public final void handleEnable()
    • handleDisable

      public final void handleDisable()
    • onDisableLater

      public final void onDisableLater()
    • registerListeners

      public final int registerListeners(Listener... listeners)
      Registers one or more listeners for this subsystem.
      The listeners will be automatically unregistered when the subsystem is disabled.
      Previously registered listeners will not be registered again.
      Specified by:
      registerListeners in interface CoreMethods
      Parameters:
      listeners - The listeners to register
      Returns:
      The number of listeners that were registered from this call
    • unregisterListeners

      public final int unregisterListeners(Listener... listeners)
      Unregisters one or more listeners from this subsystem.
      Specified by:
      unregisterListeners in interface CoreMethods
      Parameters:
      listeners - The listeners to unregister
      Returns:
      The number of listeners that were unregistered from this call
    • unregisterListeners

      public final int unregisterListeners()
      Unregisters ALL listeners from this subsystem.
      Specified by:
      unregisterListeners in interface CoreMethods
      Returns:
      The number of listeners that were unregistered from this call
    • registerTasks

      public final int registerTasks(BukkitTask... tasks)
      Registers one or more tasks for this subsystem.
      The tasks will be automatically cancelled when the subsystem is disabled.
      Previously registered tasks will not be registered again.
      Specified by:
      registerTasks in interface CoreMethods
      Parameters:
      tasks - The tasks to register
      Returns:
      The number of tasks that were registered from this call
    • unregisterTasks

      public final int unregisterTasks(BukkitTask... tasks)
      Unregisters one or more tasks from this subsystem.
      Specified by:
      unregisterTasks in interface CoreMethods
      Parameters:
      tasks - The tasks to unregister
      Returns:
      The number of tasks that were unregistered from this call
    • unregisterTasks

      public final int unregisterTasks()
      Unregisters ALL tasks from this subsystem.
      Specified by:
      unregisterTasks in interface CoreMethods
      Returns:
      The number of tasks that were unregistered from this call
    • registerDisableables

      public final int registerDisableables(Disableable... disableables)
      Registers one or more disableable objects for this subsystem.
      The disableables will be automatically disabled when the subsystem is disabled.
      Previously registered disableables will not be registered again.
      Specified by:
      registerDisableables in interface CoreMethods
      Parameters:
      disableables - The disableable objects to register
      Returns:
      The number of disableables that were registered from this call
    • unregisterDisableables

      public final int unregisterDisableables(Disableable... disableables)
      Unregisters one or more disableable objects from this subsystem.
      Specified by:
      unregisterDisableables in interface CoreMethods
      Parameters:
      disableables - The disableable objects to unregister
      Returns:
      The number of disableables that were unregistered from this call
    • unregisterDisableables

      public final int unregisterDisableables()
      Unregisters ALL disableable objects from this subsystem.
      Specified by:
      unregisterDisableables in interface CoreMethods
      Returns:
      The number of disableables that were unregistered from this call
    • getLoggerName

      public String getLoggerName()
      Specified by:
      getLoggerName in class LoggerService
    • isDebug

      public boolean isDebug()
      Specified by:
      isDebug in class LoggerService
    • logToConsole

      public void logToConsole(String message, Level level)
      Overrides:
      logToConsole in class LoggerService
    • getPrefix

      @NotNull public abstract @NotNull String getPrefix()
      Returns:
      The prefix for this subsystem, as defined in the subsystem config
    • buildMessage

      public MessageBuilder buildMessage(String key)
      Builds a MessageBuilder using this Subsystems' config and the provided key
      It will also automatically replace any {prefix} placeholders in the message with this subsystem's prefix
      Parameters:
      key - The key to get the message from the config
      Returns:
      The MessageBuilder (see above)
    • getMessage

      public MessageBuilder getMessage(String key)
      Builds a MessageBuilder using this Subsystems' config and the provided key
      It will also automatically replace any {prefix} placeholders in the message with this subsystem's prefix
      Parameters:
      key - The key to get the message from the config
      Returns:
      The MessageBuilder (see above)
    • registerConfigObserver

      public boolean registerConfigObserver(@NotNull @NotNull ConfigObserver observer)
      Description copied from interface: ObservableConfig
      Registers an observer to this config (if not already registered)
      Refer to the ConfigObserver docs for information on its lifecycle.
      Specified by:
      registerConfigObserver in interface ObservableConfig
      Returns:
      If the observer was successfully registered from this call (false if already registered)
    • unregisterConfigObserver

      public void unregisterConfigObserver(@NotNull @NotNull ConfigObserver observer)
      Description copied from interface: ObservableConfig
      Unregisters an observer from this config
      Specified by:
      unregisterConfigObserver in interface ObservableConfig
    • unregisterConfigObservers

      public void unregisterConfigObservers()
      Description copied from interface: ObservableConfig
      Unregisters ALL observers from this config.
      Intended for shutdown logic, but can be used at any time.
      Specified by:
      unregisterConfigObservers in interface ObservableConfig
    • reloadObservableConfig

      public void reloadObservableConfig()
      Reloads the backing config for this observable, notifying all registered observers of the change.

      Equivalent to calling reloadConfig() on this subsystem.
      Specified by:
      reloadObservableConfig in interface ObservableConfig
    • getSupplementalConfigResource

      public @UnknownNullability InputStream getSupplementalConfigResource(@NotNull @NotNull String fileName) throws UnsupportedOperationException
      Placeholder for your own implementation in order to support supplemental configuration files.
      This method should return an InputStream to the supplemental config resource.

      By default, this method throws an UnsupportedOperationException.
      Parameters:
      fileName - The YAML file name of the resource to load. Includes ONLY the name, not the path.
      Throws:
      UnsupportedOperationException - Always, unless overridden with new behavior