Class AbstractSubsystem<C extends SubsystemConfig<S>,S extends AbstractSubsystem<C,S>>
java.lang.Object
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 Object
implements CoreMethods, ObservableConfig
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull MessageBuilderbuildMessage(@NotNull String key) Deprecated.@NotNull MiniMessageBuilderbuildMiniMessage(@NotNull String key) Builds aMiniMessageBuilderusing this Subsystems' config and the provided key
It will also automatically replace any {prefix} placeholders in the message with this subsystem's prefixabstract Cabstract @NotNull VersionedComponentabstract @NotNull Fileabstract @NotNull String@NotNull KamiConfigExtgetMessage(String key) Deprecated.As of 5.0.0-alpha.26, replaced bybuildMiniMessage(String)getMiniMessage(String key) Deprecated.abstract StringgetName()abstract @NotNull KamiPluginabstract @NotNull VersionedComponent@UnknownNullability InputStreamgetSupplementalConfigResource(@NotNull ConfigSource source) 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.@UnknownNullability InputStreamgetSupplementalConfigResource(@NotNull File file) 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 voidfinal voidvoidinitializeConfig(C config) abstract voidThis 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 voidabstract voidonEnable()This method is called atAbstractSubsysteminitialization.final intregisterCommands(KamiCommand... commands) Registers the provided commands with this subsystem.booleanregisterConfigObserver(@NotNull ConfigObserver observer) Registers an observer to this config (if not already registered)
Refer to theConfigObserverdocs for information on its lifecycle.final intregisterDisableables(Disableable... disableables) Registers one or more disableable objects for this subsystem.
The disableables will be automatically disabled when the subsystem is disabled.final intregisterListeners(Listener... listeners) Registers one or more listeners for this subsystem.
The listeners will be automatically unregistered when the subsystem is disabled.final voidregisterReloadHook(@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 intregisterTasks(BukkitTask... tasks) Registers one or more tasks for this subsystem.
The tasks will be automatically cancelled when the subsystem is disabled.final voidReload the subsystem config from its yaml file on disk.
Will also call anyObservableConfighooks registered viaregisterReloadHook(ObservableConfig)voidReloads the backing config for this observable, notifying all registered observers of the change.
Equivalent to callingreloadConfig()on this subsystem.voidfinal intUnregisters ALL commands that this subsystem has registered.final intunregisterCommands(KamiCommand... commands) Unregisters the specified commands, if this subsystem has registered them prior.voidunregisterConfigObserver(@NotNull ConfigObserver observer) Unregisters an observer from this configvoidUnregisters ALL observers from this config.
Intended for shutdown logic, but can be used at any time.final intUnregisters ALL disableable objects from this subsystem.final intunregisterDisableables(Disableable... disableables) Unregisters one or more disableable objects from this subsystem.final intUnregisters ALL listeners from this subsystem.final intunregisterListeners(Listener... listeners) Unregisters one or more listeners from this subsystem.final intUnregisters ALL tasks from this subsystem.final intunregisterTasks(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 atAbstractSubsysteminitialization.
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:
registerCommandsin 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:
unregisterCommandsin 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:
unregisterCommandsin 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 anyObservableConfighooks registered viaregisterReloadHook(ObservableConfig)- Specified by:
reloadConfigin interfaceCoreMethods
-
saveConfig
public void saveConfig()- Specified by:
saveConfigin interfaceCoreMethods
-
getConfigResourcePath
-
getConfig
-
initializeConfig
-
createConfig
-
getKamiConfig
- Specified by:
getKamiConfigin 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:
registerListenersin 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:
unregisterListenersin 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:
unregisterListenersin 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:
registerTasksin 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:
unregisterTasksin 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:
unregisterTasksin 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:
registerDisableablesin 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:
unregisterDisableablesin 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:
unregisterDisableablesin interfaceCoreMethods- Returns:
- The number of disableables that were unregistered from this call
-
getPrefix
- Returns:
- The prefix for this subsystem, as defined in the subsystem config
-
buildMessage
Deprecated.As of 5.0.0-alpha.26, replaced bybuildMiniMessage(String)Builds aMessageBuilderusing 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
Deprecated.As of 5.0.0-alpha.26, replaced bybuildMiniMessage(String)Builds aMessageBuilderusing 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)
-
buildMiniMessage
Builds aMiniMessageBuilderusing 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 MiniMessageBuilder (see above)
-
getMiniMessage
Deprecated.Builds aMiniMessageBuilderusing 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 MiniMessageBuilder (see above)
-
registerConfigObserver
Description copied from interface:ObservableConfigRegisters an observer to this config (if not already registered)
Refer to theConfigObserverdocs for information on its lifecycle.- Specified by:
registerConfigObserverin interfaceObservableConfig- Returns:
- If the observer was successfully registered from this call (false if already registered)
-
unregisterConfigObserver
Description copied from interface:ObservableConfigUnregisters an observer from this config- Specified by:
unregisterConfigObserverin interfaceObservableConfig
-
unregisterConfigObservers
public void unregisterConfigObservers()Description copied from interface:ObservableConfigUnregisters ALL observers from this config.
Intended for shutdown logic, but can be used at any time.- Specified by:
unregisterConfigObserversin 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:
reloadObservableConfigin interfaceObservableConfig
-
getSupplementalConfigResource
public @UnknownNullability InputStream getSupplementalConfigResource(@NotNull @NotNull File file) 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:
file- The yaml file of the resource to load.- Throws:
UnsupportedOperationException- Always, unless overridden with new behavior
-
getSupplementalConfigResource
public @UnknownNullability InputStream getSupplementalConfigResource(@NotNull @NotNull ConfigSource source) 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:
source- The config source of the resource to load.- Throws:
UnsupportedOperationException- Always, unless overridden with new behavior
-
buildMiniMessage(String)