Class CommandFramework

java.lang.Object
me.despical.commandframework.CommandFramework
All Implemented Interfaces:
org.bukkit.command.CommandExecutor, org.bukkit.command.TabCompleter

@NonExtendable public class CommandFramework extends Object
Main class of the framework to register commands, add tab completions and implement a function to run if there is no matched commands related this framework.
Since:
1.0.0
Author:
Despical
  • Field Details

    • instance

      protected static CommandFramework instance
    • plugin

      protected final org.bukkit.plugin.Plugin plugin
    • parameterHandler

      protected ParameterHandler parameterHandler
  • Constructor Details

    • CommandFramework

      public CommandFramework(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
  • Method Details

    • registerCommands

      public final void registerCommands(@NotNull @NotNull Object instance)
      Registers commands in given object's class.
      Parameters:
      instance - the class instance of given object.
    • unregisterCommand

      public final void unregisterCommand(@NotNull @NotNull String commandName)
      Unregisters command and tab completer if there is with the given name.
      Parameters:
      commandName - name of the command that's going to be removed
    • unregisterCommands

      public final void unregisterCommands()
      Unregisters all of registered commands and tab completers using that instance.
    • addCustomParameter

      public final <A, B extends A> void addCustomParameter(@NotNull @NotNull String value, @NotNull @NotNull Function<CommandArguments,B> function)
      Adds a custom parameter to the parameter handler.

      This method allows the addition of a custom parameter to the parameter handler by specifying a value and a function that converts CommandArguments to an instance of a type that extends CommandFramework.

      Type Parameters:
      A - the type of the parent class that the custom parameter's type extends
      B - the type of the custom parameter, which extends CommandFramework
      Parameters:
      value - the value to call custom parameter using @Param, must not be null, can be a class name
      function - a function that takes CommandArguments and returns an instance of CommandFramework, must not be null
      Throws:
      NullPointerException - if value is already added as a custom parameter
    • getLogger

      @NotNull public final @NotNull Logger getLogger()
      Returns the logger instance of Command Framework. By default, logger is plugin 's logger.
      Returns:
      the current logger instance.
      Since:
      1.4.8
    • setLogger

      public final void setLogger(@NotNull @NotNull Logger logger)
      Changes default logger
      Parameters:
      logger - the non-null new logger instance
      Since:
      1.4.8
    • options

      public final OptionManager options()
      Returns the option manager.
      Returns:
      the option manager.
      Since:
      1.4.8
    • setCommandMap

      protected final void setCommandMap(org.bukkit.command.CommandMap commandMap)
    • getCommands

      @NotNull public final @NotNull List<Command> getCommands()
      Get a copy of registered commands.
      Returns:
      list of the commands.
    • getSubCommands

      @NotNull public final @NotNull List<Command> getSubCommands()
      Get a copy of registered sub-commands-.
      Returns:
      list of the sub-commands.
    • getAllCommands

      @NotNull public final @NotNull List<Command> getAllCommands()
      Get a copy of registered commands and sub-commands.
      Returns:
      list of the commands and sub-commands.
    • getInstance

      public static CommandFramework getInstance()
    • onCommand

      public boolean onCommand(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull org.bukkit.command.Command cmd, @NotNull @NotNull String label, String[] args)
      Specified by:
      onCommand in interface org.bukkit.command.CommandExecutor
    • onTabComplete

      public List<String> onTabComplete(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull org.bukkit.command.Command cmd, @NotNull @NotNull String label, String[] args)
      Specified by:
      onTabComplete in interface org.bukkit.command.TabCompleter