Class CommandBridgeProvider

java.lang.Object
dev.objz.commandbridge.api.CommandBridgeProvider

public final class CommandBridgeProvider extends Object
Static provider for obtaining the CommandBridgeAPI singleton instance.

CommandBridge registers its implementation when the plugin enables. Third-party plugins retrieve the instance by calling get() or get(Class) for platform-specific subtypes. The provider holds a single volatile reference accessible across threads.

This class cannot be instantiated. All access is through static methods.

To obtain the API instance:


 CommandBridgeAPI api = CommandBridgeProvider.get();
 

To access a platform-specific subtype, pass the expected class to get(Class).

See Also:
  • Method Details

    • get

      public static CommandBridgeAPI get()
      Returns the registered CommandBridgeAPI instance.

      This method is safe to call from any thread after CommandBridge has enabled.

      Returns:
      the registered CommandBridgeAPI instance; never null
      Throws:
      IllegalStateException - if CommandBridge is not installed, not yet enabled, or the API has not been registered
      See Also:
    • get

      public static <T extends CommandBridgeAPI> T get(Class<T> type)
      Returns the registered CommandBridgeAPI instance cast to the specified subtype.

      Use this method when accessing a platform-specific extension of the API. The cast is validated at runtime; if the registered instance does not implement the requested type, an IllegalStateException is thrown.

      Type Parameters:
      T - the expected API subtype; must extend CommandBridgeAPI
      Parameters:
      type - the Class token of the expected subtype; must not be null
      Returns:
      the API instance cast to T; never null
      Throws:
      IllegalStateException - if the API is not registered, or if the registered instance is not an instance of type
      See Also:
    • register

      public static void register(CommandBridgeAPI impl)
      Registers the CommandBridgeAPI implementation.

      This method is called internally by the CommandBridge plugin during startup and is not intended for use by third-party plugins.

      Parameters:
      impl - the implementation to register; must not be null
      Throws:
      IllegalStateException - if an implementation is already registered
      NullPointerException - if impl is null
    • unregister

      public static void unregister()
      Clears the registered CommandBridgeAPI implementation.

      Called internally by the CommandBridge plugin during shutdown. After this method returns, calls to get() will throw IllegalStateException until a new implementation is registered.