Class AllianceCommandManager

java.lang.Object
net.joseplay.allianceutils.api.extensions.AllianceCommandManager

public class AllianceCommandManager extends Object
Manages the lifecycle, storage, and lookup of custom commands registered through the Alliance API.

This manager maintains a mapping between AlliancePlugin instances and their associated AllianceCommandExecutors, allowing isolation per extension and centralized command resolution.

  • Field Details

    • commands

      Stores commands grouped by their owning plugin.

      Uses ConcurrentHashMap to allow thread-safe access in environments where commands may be registered dynamically at runtime.

    • fakeCommandRegister

      public FakeCommandRegister fakeCommandRegister
      Responsible for injecting commands into Bukkit's command map without requiring plugin.yml declarations.

      This enables dynamic command registration at runtime.

  • Constructor Details

    • AllianceCommandManager

      public AllianceCommandManager()
  • Method Details

    • registerCommand

      public void registerCommand(AlliancePlugin plugin, AllianceCommandExecutor command)
      Registers a command under a specific plugin.

      The command is stored internally and also registered into Bukkit's command system via FakeCommandRegister.

      Parameters:
      plugin - the owning plugin
      command - the command executor instance
    • getCommand

      public Optional<AllianceCommandExecutor> getCommand(String name)
      Retrieves a command by its primary name or any of its aliases.

      The lookup is case-insensitive and searches across all registered plugins.

      Parameters:
      name - the command name or alias
      Returns:
      an Optional containing the command if found
    • getAllCommands

      public List<AllianceCommandExecutor> getAllCommands()
      Retrieves an immutable list of all registered command executors.

      This method aggregates commands from all plugins into a single collection.

      Returns:
      unmodifiable list of all commands
    • getAllCommandNames

      public List<String> getAllCommandNames()
      Retrieves all registered command names, including aliases, formatted with a leading '/'.

      Useful for command parsing or intercepting raw command input.

      Returns:
      list of all command names with prefix
    • getAllCommandNames

      public List<String> getAllCommandNames(AlliancePlugin plugin)
      Retrieves all command names (including aliases) for a specific plugin.

      Unlike getAllCommandNames(), this method does not include the '/' prefix.

      Parameters:
      plugin - the plugin whose commands should be retrieved
      Returns:
      list of command names, or empty list if none are registered
    • unregisterCommands

      public void unregisterCommands(AlliancePlugin extension)
      Unregisters all commands associated with a specific plugin.

      This removes the commands from the internal registry, but does not explicitly remove them from Bukkit's command map unless handled separately by FakeCommandRegister.

      Parameters:
      extension - the plugin whose commands should be removed