Class BaseCommand

java.lang.Object
org.bukkit.command.Command
me.efekos.simpler.commands.BaseCommand
Direct Known Subclasses:
SubCommand

public abstract class BaseCommand extends org.bukkit.command.Command
Used for base commands like /feed, /god etc. Requires Command to be used in CommandManager
  • Field Summary

    Fields inherited from class org.bukkit.command.Command

    description, timings, usageMessage
  • Constructor Summary

    Constructors
    Constructor
    Description
    BaseCommand(@NotNull String name)
    Creates an instance of this command.
    BaseCommand(@NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List<String> aliases)
    Creates an instance of this command.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    execute(@NotNull org.bukkit.command.CommandSender sender, @NotNull String commandLabel, @NotNull String[] args)
    Executes the command, returning its success
    @NotNull String
    Grabs the value of Command.description() and returns it.
    @NotNull String
    Grabs the value of Command.name() and returns it.
    Grabs the value of Command.permission() and returns it.
    abstract @NotNull Syntax
    Used for handling tab completion, making examples and providing valid usages for this command.
    @NotNull String
    Gets an example usage of this command
    boolean
    Returns whether this command has a permission.
    boolean
    Grabs the value of Command.playerOnly() and returns it.
    abstract void
    onConsoleUse(org.bukkit.command.ConsoleCommandSender sender, String[] args)
    Fires when the console executes this command
    abstract void
    onPlayerUse(org.bukkit.entity.Player player, String[] args)
    Fires when a player executes this command.
    @NotNull List<String>
    tabComplete(@NotNull org.bukkit.command.CommandSender sender, @NotNull String alias, @NotNull String[] args)
    Executed on tab completion for this command, returning a list of options the player can tab through.
    @NotNull List<String>
    tabComplete(@NotNull org.bukkit.command.CommandSender sender, @NotNull String alias, @NotNull String[] args, org.bukkit.Location location)
    Executed on tab completion for this command, returning a list of options the player can tab through.

    Methods inherited from class org.bukkit.command.Command

    broadcastCommandMessage, broadcastCommandMessage, getAliases, getLabel, getPermissionMessage, isRegistered, register, setAliases, setDescription, setLabel, setName, setPermission, setPermissionMessage, setUsage, testPermission, testPermissionSilent, toString, unregister

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BaseCommand

      public BaseCommand(@NotNull @NotNull String name)
      Creates an instance of this command.
      Parameters:
      name - Name of the command.
    • BaseCommand

      public BaseCommand(@NotNull @NotNull String name, @NotNull @NotNull String description, @NotNull @NotNull String usageMessage, @NotNull @NotNull List<String> aliases)
      Creates an instance of this command.
      Parameters:
      name - Name of the command.
      description - Description of the command.
      usageMessage - Usage message of the command.
      aliases - Aliases for the command.
  • Method Details

    • getName

      @NotNull public @NotNull String getName()
      Grabs the value of Command.name() and returns it.
      Overrides:
      getName in class org.bukkit.command.Command
      Returns:
      Command name as a String.
    • getPermission

      @Nullable public String getPermission()
      Grabs the value of Command.permission() and returns it.
      Overrides:
      getPermission in class org.bukkit.command.Command
      Returns:
      Permission this command needs to be executed as String, null if this command does not need any permission.
    • hasPermission

      public boolean hasPermission()
      Returns whether this command has a permission.
      Returns:
      Whether this command has a permission.
    • getDescription

      @NotNull public @NotNull String getDescription()
      Grabs the value of Command.description() and returns it.
      Overrides:
      getDescription in class org.bukkit.command.Command
      Returns:
      A brief description of this command
    • getSyntax

      @NotNull public abstract @NotNull Syntax getSyntax()
      Used for handling tab completion, making examples and providing valid usages for this command. You can create your own arguments with a class extends Argument. This is really helpful at making sure your arguments are good.
      Returns:
      A Syntax class for this command.
    • getUsage

      @NotNull public @NotNull String getUsage()
      Gets an example usage of this command
      Overrides:
      getUsage in class org.bukkit.command.Command
      Returns:
      One or more example usages
    • isPlayerOnly

      public boolean isPlayerOnly()
      Grabs the value of Command.playerOnly() and returns it.
      Returns:
      Is this command can be used by something that is not player?
    • onPlayerUse

      public abstract void onPlayerUse(org.bukkit.entity.Player player, String[] args)
      Fires when a player executes this command.
      Parameters:
      player - Player that sent the command.
      args - The args given by sender.
    • onConsoleUse

      public abstract void onConsoleUse(org.bukkit.command.ConsoleCommandSender sender, String[] args)
      Fires when the console executes this command
      Parameters:
      sender - The console
      args - Args given by sender
    • execute

      public boolean execute(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String commandLabel, @NotNull @NotNull String[] args)
      Executes the command, returning its success
      Specified by:
      execute in class org.bukkit.command.Command
      Parameters:
      sender - Source object which is executing this command
      commandLabel - The alias of the command used
      args - All arguments passed to the command, split via ' '
      Returns:
      true if the command was successful, otherwise false
    • tabComplete

      @NotNull public @NotNull List<String> tabComplete(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String alias, @NotNull @NotNull String[] args) throws IllegalArgumentException
      Executed on tab completion for this command, returning a list of options the player can tab through.
      Overrides:
      tabComplete in class org.bukkit.command.Command
      Parameters:
      sender - Source object which is executing this command
      alias - the alias being used
      args - All arguments passed to the command, split via ' '
      Returns:
      a list of tab-completions for the specified arguments. This will never be null. List may be immutable.
      Throws:
      IllegalArgumentException - if sender, alias, or args is null
    • tabComplete

      @NotNull public @NotNull List<String> tabComplete(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String alias, @NotNull @NotNull String[] args, @Nullable org.bukkit.Location location) throws IllegalArgumentException
      Executed on tab completion for this command, returning a list of options the player can tab through.
      Overrides:
      tabComplete in class org.bukkit.command.Command
      Parameters:
      sender - Source object which is executing this command
      alias - the alias being used
      args - All arguments passed to the command, split via ' '
      location - The position looked at by the sender, or null if none
      Returns:
      a list of tab-completions for the specified arguments. This will never be null. List may be immutable.
      Throws:
      IllegalArgumentException - if sender, alias, or args is null