Class KamiPlugin

All Implemented Interfaces:
ObservableConfig, CoreMethods, Named, CommandExecutor, TabCompleter, TabExecutor, Listener, Plugin
Direct Known Subclasses:
KamiCommon

public abstract class KamiPlugin extends JavaPlugin implements Listener, Named, CoreMethods, ObservableConfig
  • Constructor Details

    • KamiPlugin

      public KamiPlugin()
  • Method Details

    • onLoad

      public void onLoad()
      Specified by:
      onLoad in interface Plugin
      Overrides:
      onLoad in class JavaPlugin
    • onLoadPre

      public void onLoadPre()
    • onLoadInner

      public void onLoadInner()
    • onLoadPost

      public void onLoadPost()
    • onEnable

      public final void onEnable()
      Specified by:
      onEnable in interface Plugin
      Overrides:
      onEnable in class JavaPlugin
    • onEnablePre

      public boolean onEnablePre()
    • onEnableInner

      public abstract void onEnableInner()
    • isAutoLoadKamiConfig

      public boolean isAutoLoadKamiConfig()
      Should we automatically load the KamiConfig on enable?
    • onEnablePost

      public void onEnablePost()
    • getKamiConfig

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

      public void reloadKamiConfig()
    • reloadConfig

      public void reloadConfig()
      Specified by:
      reloadConfig in interface CoreMethods
      Specified by:
      reloadConfig in interface Plugin
      Overrides:
      reloadConfig in class JavaPlugin
    • saveConfig

      public void saveConfig()
      Specified by:
      saveConfig in interface CoreMethods
      Specified by:
      saveConfig in interface Plugin
      Overrides:
      saveConfig in class JavaPlugin
    • onDisable

      public final void onDisable()
      Specified by:
      onDisable in interface Plugin
      Overrides:
      onDisable in class JavaPlugin
    • onDisableInner

      public abstract void onDisableInner()
      Called First in JavaPlugin.onDisable()
    • onDisablePost

      public void onDisablePost()
      Called after both onDisableInner and listeners, tasks, and disableables are unregistered
      Also called after modules, features, and commands are unregistered
      You can use this method to cleanup databases or anything else that should come after module/features shutdowns
    • getModuleYmlPath

      public String getModuleYmlPath()
      Can override if module configs are stored in a subpackage of the jar
    • getFeatureYmlPath

      public String getFeatureYmlPath()
      Can override if feature configs are stored in a subpackage of the jar
    • registerListeners

      public final int registerListeners(Listener... listeners)
      Registers one or more listeners for this plugin.
      The listeners will be automatically unregistered when the plugin 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 plugin.
      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 plugin.
      Specified by:
      unregisterListeners in interface CoreMethods
      Returns:
      The number of listeners that were unregistered from this call
    • registerDisableables

      public final int registerDisableables(Disableable... disableables)
      Registers one or more disableable objects for this plugin.
      The disableables will be automatically disabled when the plugin 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 plugin.
      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 plugin.
      Specified by:
      unregisterDisableables in interface CoreMethods
      Returns:
      The number of disableables that were unregistered from this call
    • registerTasks

      public final int registerTasks(BukkitTask... tasks)
      Registers one or more tasks for this plugin.
      The tasks will be automatically cancelled when the plugin 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 plugin.
      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 plugin.
      Specified by:
      unregisterTasks in interface CoreMethods
      Returns:
      The number of tasks that were unregistered from this call
    • registerCommands

      public final int registerCommands(KamiCommand... commands)
      Registers the provided commands with this plugin.
      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 plugin
    • unregisterCommands

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

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

      public <M extends Module> void registerModule(Class<M> clazz)
    • registerModule

      public void registerModule(Module... modules)
    • registerFeature

      public <F extends Feature> void registerFeature(Class<F> clazz)
    • registerFeature

      public void registerFeature(Feature... features)
    • verifyPluginVersion

      public boolean verifyPluginVersion(com.google.gson.JsonObject o, String key, String pluginName, @Nullable @Nullable KamiPlugin.ErrorPropertiesCallback callback)
    • verifyPluginVersion

      public boolean verifyPluginVersion(String minVer, String pluginName, @Nullable @Nullable KamiPlugin.ErrorPropertiesCallback callback)
    • compareVersions

      public boolean compareVersions(String minVer, String currentVer)
      Requires ver format to be int.int.int... (ints separated by periods)
      Returns:
      If currentVer satisfies minVer
    • getModulesConfig

      @NotNull public @NotNull KamiConfigExt getModulesConfig()
    • getFeaturesConfig

      @NotNull public @NotNull KamiConfigExt getFeaturesConfig()
    • registerConfigObserver

      public boolean registerConfigObserver(@NotNull @NotNull ConfigObserver observer)
      Registers an observer with the default KamiPlugin config (if not already registered)
      Refer to the ConfigObserver docs for information on its lifecycle events.
      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)
      Unregisters an observer from this plugin's default KamiConfig
      Specified by:
      unregisterConfigObserver in interface ObservableConfig
    • unregisterConfigObservers

      public void unregisterConfigObservers()
      Unregisters ALL observers from this plugin's default KamiConfig.
      Intended for shutdown logic, but can be used at any time.
      Specified by:
      unregisterConfigObservers in interface ObservableConfig
    • reloadObservableConfig

      public void reloadObservableConfig()
      Reload the default KamiConfig for this plugin, notifying all registered observers of the change.

      Equivalent to reloadKamiConfig()
      Specified by:
      reloadObservableConfig in interface ObservableConfig