Class 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
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 -
Method Summary
Modifier and TypeMethodDescription@NotNull StringGets the addon's unique identifier.protected final @NotNull ZentrixAPIgetAPI()Gets the ZentrixAPI instance.protected @NotNull StringGets the minimum required ZentrixAPI version.protected final booleanChecks if the ZentrixAPI is currently available.final booleanChecks if this addon has been successfully registered with Zentrix.protected voidCalled when the addon is disabled.protected abstract voidCalled when the addon is enabled.final voidFinal implementation of onDisable.final voidonEnable()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, toStringMethods inherited from class org.bukkit.plugin.PluginBase
equals, getName, hashCode, namespaceMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:
onEnablein interfaceorg.bukkit.plugin.Plugin- Overrides:
onEnablein classorg.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:
onDisablein interfaceorg.bukkit.plugin.Plugin- Overrides:
onDisablein classorg.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
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
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
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:
trueif the API is available- See Also:
-
isZentrixEnabled
public final boolean isZentrixEnabled()Checks if this addon has been successfully registered with Zentrix.- Returns:
trueif the addon is registered and enabled
-