Class SubCommandBuilder

java.lang.Object
me.tayebyassine.homestead.commands.SubCommandBuilder
Direct Known Subclasses:
AcceptInviteSubCmd, AutoSubCmd, BalanceSubCmd, BanlistSubCmd, BanPlayerSubCmd, BordersSubCmd, ChatSubCmd, CheckUpdatesSubCmd, ClaimlistSubCmd, ClaimSubCmd, CreateRegionSubCmd, DeleteRegionSubCmd, DenyInviteSubCmd, DepositBankSubCmd, ExportSubCmd, FlagsSubCmd, FlySubCmd, HelpSubCmd, HomeSubCmd, ImportSubCmd, KickPlayerSubCmd, LeaveRegionSubCmd, LevelsSubCmd, LogsSubCmd, MailSubCmd, MembersSubCmd, MenuSubCmd, MergeAcceptRegionSubCmd, MergeRegionSubCmd, OverrideFlagSubCmd, PlayerInfoSubCmd, PluginSubCmd, ProtectionModeSubCmd, RateRegionSubCmd, RegionInfoSubCmd, ReloadSubCmd, RenameRegionSubCmd, RentSubCmd, RewardsSubCmd, SetDescriptionSubCmd, SetDisplayNameSubCmd, SetMapColorSubCmd, SetMapIconSubCmd, SetMemberTaxSubCmd, SetRegionSubCmd, SetSpawnSubCmd, SetTimeSubCmd, SetWeatherSubCmd, StorageSubCmd, SubAreasSubCmd, TopRegionsSubCmd, TransferOwnershipSubCmd, TrustPlayerSubCmd, UnbanPlayerSubCmd, UnclaimSubCmd, UntrustPlayerSubCmd, VisitRegionSubCmd, WarSubCmd, WithdrawBankSubCmd

public abstract class SubCommandBuilder extends Object
Base class for every sub-command registered on a CommandBuilder.

Sub-commands are looked up by name or alias (case-insensitive). A sub-command may declare its own permissions, execution context (player only / console only) and usage string.

  • Field Details

  • Constructor Details

    • SubCommandBuilder

      public SubCommandBuilder(String name)
      Creates a sub-command without aliases.
      Parameters:
      name - the sub-command name
    • SubCommandBuilder

      public SubCommandBuilder(String name, String... aliases)
      Creates a sub-command with the given aliases.
      Parameters:
      name - the sub-command name
      aliases - additional names this sub-command responds to
  • Method Details

    • onExecution

      public abstract boolean onExecution(org.bukkit.command.CommandSender sender, String[] args)
      Executes this sub-command.
      Parameters:
      sender - the command sender
      args - the arguments following the sub-command name
      Returns:
      true to signal that the command was handled
    • onTabComplete

      public List<String> onTabComplete(org.bukkit.command.CommandSender sender, String[] args)
      Provides tab-completion suggestions for this sub-command.
      Parameters:
      sender - the command sender
      args - the arguments following the sub-command name
      Returns:
      the list of suggestions
    • setPermission

      public SubCommandBuilder setPermission(String permission)
      Replaces the permission list with a single permission.
      Parameters:
      permission - the required permission
      Returns:
      this sub-command, for chaining
    • setPermission

      public SubCommandBuilder setPermission(List<String> permissions)
      Replaces the permission list. All permissions must be held by the sender.
      Parameters:
      permissions - the required permissions
      Returns:
      this sub-command, for chaining
    • setRegionPermission

      protected SubCommandBuilder setRegionPermission(String... extraPermissions)
      Convenience helper that builds the standard region permission set: homestead.commands.region and homestead.commands.region.<name>, followed by any extra permissions.
      Parameters:
      extraPermissions - additional permissions, may be empty
      Returns:
      this sub-command, for chaining
    • setAdminPermission

      protected SubCommandBuilder setAdminPermission(String... extraPermissions)
      Convenience helper that builds the standard admin permission set: homestead.commands.homesteadadmin and homestead.commands.homesteadadmin.<name>, followed by any extra permissions.
      Parameters:
      extraPermissions - additional permissions, may be empty
      Returns:
      this sub-command, for chaining
    • setAllowedCommandSenders

      public SubCommandBuilder setAllowedCommandSenders(CommandSenderType... types)
      Sets the allowed executor types for this sub-command.
      Parameters:
      types - the allowed executor types
      Returns:
      this sub-command, for chaining
    • setPlayerOnly

      public SubCommandBuilder setPlayerOnly()
      Restricts this sub-command to players only.
      Returns:
      this sub-command, for chaining
    • setConsoleOnly

      public SubCommandBuilder setConsoleOnly()
      Restricts this sub-command to the console only.
      Returns:
      this sub-command, for chaining
    • hasPermission

      public boolean hasPermission(org.bukkit.command.CommandSender sender)
      Checks whether the sender holds every required permission.
      Parameters:
      sender - the command sender
      Returns:
      true if no permissions are required or the sender holds all of them
    • matches

      public boolean matches(String input)
      Checks whether this sub-command matches the given input (name or alias).
      Parameters:
      input - the raw input
      Returns:
      true if the input matches the name or any alias
    • getName

      public String getName()
      Returns:
      the sub-command name
    • getAliases

      public String[] getAliases()
      Returns:
      the sub-command aliases
    • getUsage

      public String getUsage()
      Returns:
      the sub-command usage string
    • setUsage

      public SubCommandBuilder setUsage(String usage)
      Sets the usage string shown to the player.
      Parameters:
      usage - the usage string
      Returns:
      this sub-command, for chaining
    • getPermissions

      public List<String> getPermissions()
      Returns:
      an unmodifiable view of the required permissions
    • isPlayerOnly

      public boolean isPlayerOnly()
      Returns:
      true if this sub-command is restricted to players only
    • setPlayerOnly

      public SubCommandBuilder setPlayerOnly(boolean playerOnly)
      Sets whether this sub-command is restricted to players.
      Parameters:
      playerOnly - true to restrict to players
      Returns:
      this sub-command, for chaining
    • isConsoleOnly

      public boolean isConsoleOnly()
      Returns:
      true if this sub-command is restricted to the console only
    • isAllowedCommandSender

      public boolean isAllowedCommandSender(org.bukkit.command.CommandSender sender)
      Checks if the given sender is allowed to execute this sub-command.
      Parameters:
      sender - the command sender
      Returns:
      true if the sender type is allowed
    • getAllowedCommandSenderDescription

      public String getAllowedCommandSenderDescription()
      Gets a human-readable description of allowed executors.
      Returns:
      description string
    • getallowedCommandSenders

      public Set<CommandSenderType> getallowedCommandSenders()
      Returns:
      an unmodifiable view of the allowed executor types
    • asPlayer

      protected org.bukkit.entity.Player asPlayer(org.bukkit.command.CommandSender sender)
      Casts the sender to a Player when possible.
      Parameters:
      sender - the command sender
      Returns:
      the player, or null if the sender is not a player