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 from an addon's main class. It checks API availability, verifies the required version, and registers the addon during startup.
Example
public class MyAddon extends ZentrixAddon {
@Override
protected void onAddonEnable() {
// Initialize the addon
getLogger().info("MyAddon enabled!");
// Access the API
ZentrixAPI api = ZentrixAPI.get();
api.getGameService().getActiveGames();
}
@Override
protected void onAddonDisable() {
// Clean up addon state
getLogger().info("MyAddon disabled!");
}
@Override
protected String getRequiredAPIVersion() {
return "1.0.0"; // Minimum required API version
}
}
API access
Use ZentrixAPI.get() to access the API from anywhere in the addon.
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 StringReturns the addon's unique identifier.protected final @NotNull ZentrixAPIgetAPI()Returns the ZentrixAPI instance.protected @NotNull StringReturns the minimum required ZentrixAPI version.protected final booleanReturns whether the ZentrixAPI is currently available.final booleanReturns whether this addon is registered with Zentrix.protected voidCalled while the addon is being disabled.protected abstract voidCalled after the addon passes the startup checks.final voidFinal implementation ofonDisable().final voidonEnable()Final implementation ofonEnable().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 ofonEnable().It checks API availability and version compatibility, registers the addon, and then calls
onAddonEnable()for addon-specific initialization.- Specified by:
onEnablein interfaceorg.bukkit.plugin.Plugin- Overrides:
onEnablein classorg.bukkit.plugin.java.JavaPlugin
-
onDisable
public final void onDisable()Final implementation ofonDisable().It calls
onAddonDisable()and then unregisters the addon.- Specified by:
onDisablein interfaceorg.bukkit.plugin.Plugin- Overrides:
onDisablein classorg.bukkit.plugin.java.JavaPlugin
-
onAddonEnable
protected abstract void onAddonEnable()Called after the addon passes the startup checks.Override this method to initialize the addon. The API is available and the addon has already been registered with Zentrix.
Use
ZentrixAPI.get()to access the API here. -
onAddonDisable
protected void onAddonDisable()Called while the addon is being disabled.Override this method to clean up addon state. It runs before the addon is unregistered from Zentrix.
The default implementation is empty.
-
getAddonId
Returns the addon's unique identifier.The default is the plugin name in lowercase. Override this method to use a different identifier.
- Returns:
- The addon ID (never null)
-
getRequiredAPIVersion
Returns the minimum required ZentrixAPI version.Override this method to specify the minimum API version the addon needs. 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
Returns the ZentrixAPI instance.Use
ZentrixAPI.get()instead. This method remains for backwards compatibility.- 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()Returns whether the ZentrixAPI is currently available.Use
ZentrixAPI.isAvailable()when checking availability outside the enable phase.- Returns:
trueif the API is available- See Also:
-
isZentrixEnabled
public final boolean isZentrixEnabled()Returns whether this addon is registered with Zentrix.- Returns:
trueif the addon is registered and enabled
-