Class Addon

java.lang.Object
de.craftsblock.craftsnet.addon.Addon
Direct Known Subclasses:
HollowAddon

public abstract class Addon extends Object
Abstract class representing an addon that extends the functionality of the application without modifying its core. Addons can be loaded, enabled, and disabled to provide additional features or customizations to the application.

The Addon class serves as a base for creating custom addons. Subclasses of Addon must implement the onEnable() and onDisable() methods to define the behavior when the addon is enabled or disabled, respectively. The onLoad() method can be optionally overridden to perform actions during addon loading.

Each addon has access to a RouteRegistry instance for handling routes and a ListenerRegistry instance for registering listeners within the addon. It also has a Logger instance for logging messages specific to the addon and a ServiceManager for registering service loaders.

The Addon class provides a convenient way to extend the application's capabilities through custom functionality, making it easy to add new features or modify existing ones without directly altering the application's core code.

Since:
1.0.0-SNAPSHOT
See Also:
  • Constructor Details

    • Addon

      public Addon()
  • Method Details

    • onLoad

      public void onLoad()
      Called when the addon is being loaded. This method can be overridden to perform any setup or initialization tasks.
    • onEnable

      public void onEnable()
      Called when the addon is being enabled. This method must be implemented by subclasses to define the addon's functionality.
    • onDisable

      public void onDisable()
      Called when the addon is being disabled. This method must be implemented by subclasses to clean up any resources or perform any necessary shutdown tasks.
    • craftsNet

      @Deprecated(since="3.5.0", forRemoval=true) @ScheduledForRemoval(inVersion="3.6.0") public final CraftsNet craftsNet()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getCraftsNet() instead. This will be removed in the future.
      Get the CraftsNet instance on which the addon was registered. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The CraftsNet instance on which the addon was registered.
      Since:
      3.1.0-SNAPSHOT
    • getCraftsNet

      public CraftsNet getCraftsNet()
      Get the CraftsNet instance on which the addon was registered. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The CraftsNet instance on which the addon was registered.
      Since:
      3.1.0-SNAPSHOT
    • getName

      public final String getName()
      Get the name of the addon.
      Returns:
      The name of the addon.
    • getMeta

      public AddonMeta getMeta()
      Get the metadata of the addon.
      Returns:
      The metadata of the addon.
      Since:
      3.1.0-SNAPSHOT
    • getAddonManager

      public final AddonManager getAddonManager()
      Retrieves the AddonManager instance used by the addon. This method is marked as final to prevent subclasses from modifying it directly.
      Returns:
      The AddonManager instance used by the addon.
      Since:
      3.1.0-SNAPSHOT
    • autoRegisterRegistry

      @Deprecated(since="3.5.0", forRemoval=true) @ScheduledForRemoval(inVersion="3.6.0") public final AutoRegisterRegistry autoRegisterRegistry()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getAutoRegisterRegistry() instead. This will be removed in the future.
      Retrieves the AutoRegisterRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The AutoRegisterRegistry instance used by the addon.
      Since:
      3.2.0-SNAPSHOT
    • getAutoRegisterRegistry

      public final AutoRegisterRegistry getAutoRegisterRegistry()
      Retrieves the AutoRegisterRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The AutoRegisterRegistry instance used by the addon.
      Since:
      3.2.0-SNAPSHOT
    • bodyRegistry

      @Deprecated(since="3.5.0", forRemoval=true) @ScheduledForRemoval(inVersion="3.6.0") public final BodyRegistry bodyRegistry()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getBodyRegistry() instead. This will be removed in the future.
      Get the BodyRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The BodyRegistry instance used by the addon.
      Since:
      3.0.4-SNAPSHOT
    • getBodyRegistry

      public final BodyRegistry getBodyRegistry()
      Get the BodyRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The BodyRegistry instance used by the addon.
      Since:
      3.0.4-SNAPSHOT
    • commandRegistry

      @Deprecated(since="3.5.0", forRemoval=true) @ScheduledForRemoval(inVersion="3.6.0") public final CommandRegistry commandRegistry()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getCommandRegistry() instead. This will be removed in the future.
      Get the CommandRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The CommandRegistry instance used by the addon.
    • getCommandRegistry

      public final CommandRegistry getCommandRegistry()
      Get the CommandRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The CommandRegistry instance used by the addon.
    • getFileHelper

      public final FileHelper getFileHelper()
      Get the FileHelper instance used by the addon. This method is marked as final to prevent subclasses from modifying it directly.
      Returns:
      The FileHelper instance used by the addon.
    • listenerRegistry

      @Deprecated(since="3.5.0", forRemoval=true) @ScheduledForRemoval(inVersion="3.6.0") public final de.craftsblock.craftscore.event.ListenerRegistry listenerRegistry()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getListenerRegistry() instead. This will be removed in the future.
      Get the ListenerRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The ListenerRegistry instance used by the addon.
    • getListenerRegistry

      public final de.craftsblock.craftscore.event.ListenerRegistry getListenerRegistry()
      Get the ListenerRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The ListenerRegistry instance used by the addon.
    • getLogStream

      public final LogStream getLogStream()
      Get the LogStream instance used by the addon. This method is marked as final to prevent subclasses from modifying it directly.
      Returns:
      The LogStream instance used by the addon.
    • middlewareRegistry

      @Deprecated(since="3.5.0", forRemoval=true) @ScheduledForRemoval(inVersion="3.6.0") public final MiddlewareRegistry middlewareRegistry()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getMiddlewareRegistry() instead. This will be removed in the future.
      Get the MiddlewareRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The MiddlewareRegistry instance used by the addon.
      Since:
      3.4.0-SNAPSHOT
    • getMiddlewareRegistry

      public final MiddlewareRegistry getMiddlewareRegistry()
      Get the MiddlewareRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The MiddlewareRegistry instance used by the addon.
      Since:
      3.4.0-SNAPSHOT
    • requirementRegistry

      @Deprecated(since="3.5.0", forRemoval=true) @ScheduledForRemoval(inVersion="3.6.0") public final RequirementRegistry requirementRegistry()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getRequirementRegistry() instead. This will be removed in the future.
      Get the RequirementRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The RequirementRegistry instance used by the addon.
      Since:
      3.2.1-SNAPSHOT
    • getRequirementRegistry

      public final RequirementRegistry getRequirementRegistry()
      Get the RequirementRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the registry directly.
      Returns:
      The RequirementRegistry instance used by the addon.
      Since:
      3.2.1-SNAPSHOT
    • routeRegistry

      @Deprecated(since="3.5.0", forRemoval=true) @ScheduledForRemoval(inVersion="3.6.0") public final RouteRegistry routeRegistry()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getRouteRegistry() instead. This will be removed in the future.
      Get the RouteRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the handler directly.
      Returns:
      The RouteRegistry instance used by the addon.
    • getRouteRegistry

      public final RouteRegistry getRouteRegistry()
      Get the RouteRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the handler directly.
      Returns:
      The RouteRegistry instance used by the addon.
    • serviceManager

      @Deprecated(since="3.5.0", forRemoval=true) @ScheduledForRemoval(inVersion="3.6.0") public final ServiceManager serviceManager()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getServiceManager() instead. This will be removed in the future.
      Get the ServiceManager instance used by the addon. This method is marked as final to prevent subclasses from modifying the handler directly.
      Returns:
      The ServiceManager instance used by the addon.
    • getServiceManager

      public final ServiceManager getServiceManager()
      Get the ServiceManager instance used by the addon. This method is marked as final to prevent subclasses from modifying the handler directly.
      Returns:
      The ServiceManager instance used by the addon.
    • streamEncoderRegistry

      @Deprecated(since="3.5.0", forRemoval=true) @ScheduledForRemoval(inVersion="3.6.0") public final StreamEncoderRegistry streamEncoderRegistry()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getStreamEncoderRegistry() instead. This will be removed in the future.
      Get the StreamEncoderRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the handler directly.
      Returns:
      The StreamEncoderRegistry instance used by the addon.
      Since:
      3.3.3-SNAPSHOT
    • getStreamEncoderRegistry

      public final StreamEncoderRegistry getStreamEncoderRegistry()
      Get the StreamEncoderRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying the handler directly.
      Returns:
      The StreamEncoderRegistry instance used by the addon.
      Since:
      3.3.3-SNAPSHOT
    • getWebSocketEncoderRegistry

      public final TypeEncoderRegistry<WebSocketSafeTypeEncoder<?,?>> getWebSocketEncoderRegistry()
      Retrieves the TypeEncoderRegistry dedicated to managing WebSocketSafeTypeEncoder instances used by the WebSocketServer.
      Returns:
      the TypeEncoderRegistry for WebSocketSafeTypeEncoder codecs
    • getWebsocketExtensionRegistry

      public final WebSocketExtensionRegistry getWebsocketExtensionRegistry()
      Retrieves the WebSocketExtensionRegistry instance used by the addon. This method is marked as final to prevent subclasses from modifying it directly.
      Returns:
      The WebSocketExtensionRegistry instance used by the addon.
      Since:
      3.5.0
    • getClassLoader

      public final ClassLoader getClassLoader()
      Get the class loader instance used by the addon. This method is marked as final to prevent subclasses from modifying the handler directly.
      Returns:
      The class loader used by this addon.
    • logger

      @Deprecated(since="3.5.0", forRemoval=true) @ScheduledForRemoval(inVersion="3.6.0") public final Logger logger()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getLogger() instead. This will be removed in the future.
      Get the logger instance used by the addon. This method is marked as final to prevent subclasses from modifying the logger directly.
      Returns:
      The logger instance used by the addon.
    • getLogger

      public Logger getLogger()
      Get the logger instance used by the addon. This method is marked as final to prevent subclasses from modifying the logger directly.
      Returns:
      The logger instance used by the addon.
    • getDataFolder

      public final File getDataFolder()
      Retrieves the data folder for this addon as a File object.

      The folder location is determined by getDataPath(), which ensures the directory exists before returning it. This method is a convenience wrapper to convert the Path into a File.

      Returns:
      The data folder for this addon as a File
    • getDataPath

      public final Path getDataPath()
      Retrieves the data directory for this addon as a Path.

      The path is resolved relative to the addons directory, using the addon's name as the subdirectory name. If the directory does not exist, it will be created. If the resolved path exists but is not a directory, an IllegalStateException will be thrown.

      Returns:
      The data path for this add-on
      Throws:
      RuntimeException - If the data path cannot be created or accessed
      IllegalStateException - If the resolved path exists but is not a directory
      Since:
      3.5.2
    • getAddon

      public <T extends Addon> T getAddon(Class<T> addon)
      Retrieves an addon of the specified type from the loaded addons.
      Type Parameters:
      T - The type of the addon to retrieve, extending the Addon class.
      Parameters:
      addon - The class object representing the type of the addon to be retrieved.
      Returns:
      An instance of the specified addon type if found, or null if not present.
    • getAddon

      public <T extends Addon> T getAddon(String name)
      Retrieves an addon by its name from the loaded addons.
      Type Parameters:
      T - The type of the addon to retrieve, extending the Addon class.
      Parameters:
      name - The name of the addon to be retrieved.
      Returns:
      An instance of the specified addon type if found, or null if not present.
      Since:
      3.3.5-SNAPSHOT