Class ZentrixAddon

java.lang.Object
org.bukkit.plugin.PluginBase
org.bukkit.plugin.java.JavaPlugin
dev.itsharshxd.zentrix.api.addon.ZentrixAddon
All Implemented Interfaces:
io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner, net.kyori.adventure.key.Namespaced, org.bukkit.command.CommandExecutor, org.bukkit.command.TabCompleter, org.bukkit.command.TabExecutor, org.bukkit.plugin.Plugin

public abstract class ZentrixAddon extends org.bukkit.plugin.java.JavaPlugin
Base class for Zentrix addons.

Extend this class in your addon's main class for automatic lifecycle management and seamless integration with the ZentrixAPI. This class handles API availability checks, version compatibility, and addon registration automatically.

Example Usage


 public class MyAddon extends ZentrixAddon {

     @Override
     protected void onAddonEnable() {
         // Your addon initialization code
         getLogger().info("MyAddon enabled!");

         // Access the API (within addon class)
         ZentrixAPI api = ZentrixAPI.get();
         api.getGameService().getActiveGames();
     }

     @Override
     protected void onAddonDisable() {
         // Your addon cleanup code
         getLogger().info("MyAddon disabled!");
     }

     @Override
     protected String getRequiredAPIVersion() {
         return "1.0.0"; // Minimum API version required
     }
 }
 

API Access

Use ZentrixAPI.get() to access the API from anywhere in your addon. This is the single recommended way to obtain the API instance.

plugin.yml Configuration

Your addon's plugin.yml should declare Zentrix as a dependency:

 name: MyAddon
 version: 1.0.0
 main: com.example.myaddon.MyAddon
 depend: [Zentrix]
 api-version: '1.21'
 
Since:
1.0.0
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull String
    Gets the addon's unique identifier.
    protected final @NotNull ZentrixAPI
    Gets the ZentrixAPI instance.
    protected @NotNull String
    Gets the minimum required ZentrixAPI version.
    protected final boolean
    Checks if the ZentrixAPI is currently available.
    final boolean
    Checks if this addon has been successfully registered with Zentrix.
    protected void
    Called when the addon is disabled.
    protected abstract void
    Called when the addon is enabled.
    final void
    Final implementation of onDisable.
    final void
    Final implementation of onEnable.

    Methods inherited from class org.bukkit.plugin.java.JavaPlugin

    getClassLoader, getCommand, getConfig, getDataFolder, getDefaultBiomeProvider, getDefaultWorldGenerator, getDescription, getFile, getLifecycleManager, getLogger, getPlugin, getPluginLoader, getPluginMeta, getProvidingPlugin, getResource, getServer, getTextResource, init, init, isEnabled, isNaggable, onCommand, onLoad, onTabComplete, registerCommand, registerCommand, registerCommand, registerCommand, reloadConfig, saveConfig, saveDefaultConfig, saveResource, setEnabled, setNaggable, toString

    Methods inherited from class org.bukkit.plugin.PluginBase

    equals, getName, hashCode, namespace

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.bukkit.plugin.Plugin

    getComponentLogger, getDataPath, getLog4JLogger, getSLF4JLogger
  • Constructor Details

    • ZentrixAddon

      public ZentrixAddon()
  • Method Details

    • onEnable

      public final void onEnable()
      Final implementation of onEnable.

      This method handles ZentrixAPI availability checks, version compatibility, and addon registration. Override onAddonEnable() instead to add your addon's initialization logic.

      Specified by:
      onEnable in interface org.bukkit.plugin.Plugin
      Overrides:
      onEnable in class org.bukkit.plugin.java.JavaPlugin
    • onDisable

      public final void onDisable()
      Final implementation of onDisable.

      This method handles addon unregistration and cleanup. Override onAddonDisable() instead to add your addon's cleanup logic.

      Specified by:
      onDisable in interface org.bukkit.plugin.Plugin
      Overrides:
      onDisable in class org.bukkit.plugin.java.JavaPlugin
    • onAddonEnable

      protected abstract void onAddonEnable()
      Called when the addon is enabled.

      Override this method to add your addon's initialization logic. This is called after ZentrixAPI availability and version checks pass, and after the addon has been registered with Zentrix.

      At this point, you can safely use ZentrixAPI.get() to access the API.

    • onAddonDisable

      protected void onAddonDisable()
      Called when the addon is disabled.

      Override this method to add your addon's cleanup logic. This is called before the addon is unregistered from Zentrix.

      The default implementation does nothing.

    • getAddonId

      @NotNull public @NotNull String getAddonId()
      Gets the addon's unique identifier.

      By default, this returns the plugin name in lowercase. Override this method to provide a custom identifier.

      Returns:
      The addon ID (never null)
    • getRequiredAPIVersion

      @NotNull protected @NotNull String getRequiredAPIVersion()
      Gets the minimum required ZentrixAPI version.

      Override this method to specify the minimum API version your addon requires. The default is "1.0.0".

      Version format follows semantic versioning: MAJOR.MINOR.PATCH Compatibility is determined by the major version number.

      Returns:
      The minimum required API version (e.g., "1.0.0")
    • getAPI

      @NotNull protected final @NotNull ZentrixAPI getAPI()
      Gets the ZentrixAPI instance.

      Prefer using ZentrixAPI.get() instead. This method is kept for backwards compatibility but using the static method on ZentrixAPI directly is the recommended approach.

      Returns:
      The ZentrixAPI instance (never null)
      Throws:
      IllegalStateException - if called before the addon is enabled or if Zentrix is not available
      See Also:
    • isAPIAvailable

      protected final boolean isAPIAvailable()
      Checks if the ZentrixAPI is currently available.

      Prefer using ZentrixAPI.isAvailable() instead. This is useful for checking API availability outside of the enable phase.

      Returns:
      true if the API is available
      See Also:
    • isZentrixEnabled

      public final boolean isZentrixEnabled()
      Checks if this addon has been successfully registered with Zentrix.
      Returns:
      true if the addon is registered and enabled