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
public abstract class AbstractSubsystem<C extends SubsystemConfig<S>,S extends AbstractSubsystem<C,S>>
extends LoggerService
implements CoreMethods, ObservableConfig
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildMessage
(String key) Builds aMessageBuilder
using this Subsystems' config and the provided key
It will also automatically replace any {prefix} placeholders in the message with this subsystem's prefixprotected abstract C
abstract @NotNull String
abstract @NotNull File
abstract @NotNull String
@NotNull KamiConfigExt
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 prefixabstract String
getName()
abstract KamiPlugin
abstract @NotNull String
@UnknownNullability InputStream
getSupplementalConfigResource
(@NotNull String fileName) 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 anUnsupportedOperationException
.final void
final void
void
initializeConfig
(C config) boolean
isDebug()
void
logToConsole
(String message, Level level) abstract void
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.final void
abstract void
onEnable()
This method is called atAbstractSubsystem
initialization.final int
registerCommands
(KamiCommand... commands) Registers the provided commands with this subsystem.boolean
registerConfigObserver
(@NotNull ConfigObserver observer) Registers an observer to this config (if not already registered)
Refer to theConfigObserver
docs for information on its lifecycle.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.final int
registerListeners
(Listener... listeners) Registers one or more listeners for this subsystem.
The listeners will be automatically unregistered when the subsystem is disabled.final void
registerReloadHook
(@NotNull ObservableConfig config) Adds a hook to call this observable'sreloadObservableConfig()
method whenever this subsystem's config is reloaded.
This means that when this subsystem gets reloaded, this config will also be reloaded.final int
registerTasks
(BukkitTask... tasks) Registers one or more tasks for this subsystem.
The tasks will be automatically cancelled when the subsystem is disabled.final void
Reload the subsystem config from its yaml file on disk.
Will also call anyObservableConfig
hooks registered viaregisterReloadHook(ObservableConfig)
void
Reloads the backing config for this observable, notifying all registered observers of the change.
Equivalent to callingreloadConfig()
on this subsystem.void
final int
Unregisters ALL commands that this subsystem has registered.final int
unregisterCommands
(KamiCommand... commands) Unregisters the specified commands, if this subsystem has registered them prior.void
unregisterConfigObserver
(@NotNull ConfigObserver observer) Unregisters an observer from this configvoid
Unregisters ALL observers from this config.
Intended for shutdown logic, but can be used at any time.final int
Unregisters ALL disableable objects from this subsystem.final int
unregisterDisableables
(Disableable... disableables) Unregisters one or more disableable objects from this subsystem.final int
Unregisters ALL listeners from this subsystem.final int
unregisterListeners
(Listener... listeners) Unregisters one or more listeners from this subsystem.final int
Unregisters ALL tasks from this subsystem.final int
unregisterTasks
(BukkitTask... tasks) Unregisters one or more tasks from this subsystem.
-
Constructor Details
-
AbstractSubsystem
public AbstractSubsystem()
-
-
Method Details
-
getPlugin
- Returns:
- The KamiPlugin that this subsystem is registered to
-
onEnable
public abstract void onEnable()This method is called atAbstractSubsystem
initialization.
You should handle your enable logic here, including: configs/commands/listeners/tasks/disableables.
Registration Methods:registerCommands(com.kamikazejam.kamicommon.command.KamiCommand...)
,registerListeners(org.bukkit.event.Listener...)
,registerTasks(org.bukkit.scheduler.BukkitTask...)
,registerDisableables(com.kamikazejam.kamicommon.util.interfaces.Disableable...)
-
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
Registers the provided commands with this subsystem.
Previously registered commands will not be registered again.- Specified by:
registerCommands
in interfaceCoreMethods
- Parameters:
commands
- The commands to register- Returns:
- The number of commands that were registered with this subsystem
-
unregisterCommands
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 interfaceCoreMethods
- 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 interfaceCoreMethods
- Returns:
- The number of commands that were unregistered
-
getName
- Returns:
- The name of this subsystem
-
defaultPrefix
- Returns:
- The default logging prefix for this subsystem
-
getConfigFileDestination
-
reloadConfig
public final void reloadConfig()Reload the subsystem config from its yaml file on disk.
Will also call anyObservableConfig
hooks registered viaregisterReloadHook(ObservableConfig)
- Specified by:
reloadConfig
in interfaceCoreMethods
-
saveConfig
public void saveConfig()- Specified by:
saveConfig
in interfaceCoreMethods
-
getConfigResourcePath
-
getConfig
-
initializeConfig
-
createConfig
-
getKamiConfig
- Specified by:
getKamiConfig
in interfaceCoreMethods
-
registerReloadHook
Adds a hook to call this observable'sreloadObservableConfig()
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
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 interfaceCoreMethods
- Parameters:
listeners
- The listeners to register- Returns:
- The number of listeners that were registered from this call
-
unregisterListeners
Unregisters one or more listeners from this subsystem.- Specified by:
unregisterListeners
in interfaceCoreMethods
- 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 interfaceCoreMethods
- Returns:
- The number of listeners that were unregistered from this call
-
registerTasks
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 interfaceCoreMethods
- Parameters:
tasks
- The tasks to register- Returns:
- The number of tasks that were registered from this call
-
unregisterTasks
Unregisters one or more tasks from this subsystem.- Specified by:
unregisterTasks
in interfaceCoreMethods
- 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 interfaceCoreMethods
- Returns:
- The number of tasks that were unregistered from this call
-
registerDisableables
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 interfaceCoreMethods
- Parameters:
disableables
- The disableable objects to register- Returns:
- The number of disableables that were registered from this call
-
unregisterDisableables
Unregisters one or more disableable objects from this subsystem.- Specified by:
unregisterDisableables
in interfaceCoreMethods
- 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 interfaceCoreMethods
- Returns:
- The number of disableables that were unregistered from this call
-
getLoggerName
- Specified by:
getLoggerName
in classLoggerService
-
isDebug
public boolean isDebug()- Specified by:
isDebug
in classLoggerService
-
logToConsole
- Overrides:
logToConsole
in classLoggerService
-
getPrefix
- Returns:
- The prefix for this subsystem, as defined in the subsystem config
-
buildMessage
Builds aMessageBuilder
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
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
Description copied from interface:ObservableConfig
Registers an observer to this config (if not already registered)
Refer to theConfigObserver
docs for information on its lifecycle.- Specified by:
registerConfigObserver
in interfaceObservableConfig
- Returns:
- If the observer was successfully registered from this call (false if already registered)
-
unregisterConfigObserver
Description copied from interface:ObservableConfig
Unregisters an observer from this config- Specified by:
unregisterConfigObserver
in interfaceObservableConfig
-
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 interfaceObservableConfig
-
reloadObservableConfig
public void reloadObservableConfig()Reloads the backing config for this observable, notifying all registered observers of the change.
Equivalent to callingreloadConfig()
on this subsystem.- Specified by:
reloadObservableConfig
in interfaceObservableConfig
-
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 anUnsupportedOperationException
.- 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
-