Class TopCommand<T extends SubCommand>

java.lang.Object
net.md_5.bungee.api.plugin.Command
de.simonsator.partyandfriends.api.TopCommand<T>
Type Parameters:
T - The type of subcommands this class should use SubCommand
All Implemented Interfaces:
net.md_5.bungee.api.plugin.TabExecutor
Direct Known Subclasses:
Friends, OnlyTopCommand, PartyCommand

public abstract class TopCommand<T extends SubCommand> extends net.md_5.bungee.api.plugin.Command implements net.md_5.bungee.api.plugin.TabExecutor
Represents a TopCommand like /friend, /party or /command. The top command decides if and which subcommand should be executed. Also if no subcommand should be executed it outputs the help of the subcommands.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final ArrayList<T>
    Contains all subcommands of the TopCommand
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    TopCommand(String[] pCommandNames, String pPermission, String pPrefix)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addCommand(T pCommand)
    Adds a subcommand to the subCommands list and after the subcommand was added it sorts the list again.
    void
    execute(net.md_5.bungee.api.CommandSender pCommandSender, String[] args)
    Checks if the sender is a player with the method isPlayer(CommandSender).
     
    getSubCommand(Class<? extends SubCommand> pClass)
     
    static boolean
    isPlayer(net.md_5.bungee.api.CommandSender pCommandSender)
     
    protected abstract void
    onCommand(OnlinePAFPlayer pPlayer, String[] args)
    Decides if a subcommand should be called and if which one.
    onTabComplete(net.md_5.bungee.api.CommandSender commandSender, String[] strings)
     
    protected List<String>
     
    protected void
    Sorts the subcommands by there priority.
    void
    tabComplete(net.md_5.bungee.api.event.TabCompleteEvent pEvent)
    Deprecated.

    Methods inherited from class net.md_5.bungee.api.plugin.Command

    canEqual, equals, getAliases, getName, getPermission, getPermissionMessage, hashCode, hasPermission, setPermissionMessage, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • subCommands

      protected final ArrayList<T extends SubCommand> subCommands
      Contains all subcommands of the TopCommand
  • Constructor Details

    • TopCommand

      protected TopCommand(String[] pCommandNames, String pPermission, String pPrefix)
      Parameters:
      pCommandNames - The command name and the different aliases of this command. By these names the method can be called.
      pPermission - The permission which is needed to execute this command. If it is blank no permission is needed to execute this command.
      pPrefix - The prefix which should be used by all subcommands. The prefix gets returned by the method getPrefix().
  • Method Details

    • isPlayer

      public static boolean isPlayer(net.md_5.bungee.api.CommandSender pCommandSender)
      Parameters:
      pCommandSender - The sender of the command.
      Returns:
      Returns true if the sender of the command is a player. If not it returns false and reloads the plugin.
    • execute

      public void execute(net.md_5.bungee.api.CommandSender pCommandSender, String[] args)
      Checks if the sender is a player with the method isPlayer(CommandSender). If so it executes the method onCommand(OnlinePAFPlayer, String[]). If not it reloads the plugin.
      Specified by:
      execute in class net.md_5.bungee.api.plugin.Command
      Parameters:
      pCommandSender - The sender of the command.
      args - The arguments which are given by the player.
    • onCommand

      protected abstract void onCommand(OnlinePAFPlayer pPlayer, String[] args)
      Decides if a subcommand should be called and if which one. If no subcommand should be called it shows the help of the commands.
      Parameters:
      pPlayer - The player who executed the command.
      args - The arguments which were given by the player.
    • addCommand

      public void addCommand(T pCommand)
      Adds a subcommand to the subCommands list and after the subcommand was added it sorts the list again.
      Parameters:
      pCommand - The subcommand which should be added.
    • sort

      protected void sort()
      Sorts the subcommands by there priority. The subcommand with the lowest priority will be the first one in the list and the one with the highest priority the last one after the list was sorted.
    • getSubCommand

      public T getSubCommand(Class<? extends SubCommand> pClass)
      Parameters:
      pClass - The type of the subcommand object which is searched
      Returns:
      Returns a subcommand of the subCommands list, which has an equal type.
    • getPrefix

      public String getPrefix()
      Returns:
      Returns the prefix which should be used by all subcommands.
    • tabComplete

      @Deprecated public void tabComplete(net.md_5.bungee.api.event.TabCompleteEvent pEvent)
      Deprecated.
    • playerComplete

      protected List<String> playerComplete(String[] input)
    • onTabComplete

      public List<String> onTabComplete(net.md_5.bungee.api.CommandSender commandSender, String[] strings)
      Specified by:
      onTabComplete in interface net.md_5.bungee.api.plugin.TabExecutor