E
- The type of the Plugin
associated with this
CommandNode
public abstract class CommandNode<E extends Plugin> extends Object implements CommandExecutor, TabCompleter, Comparable<CommandNode<?>>
Modifier and Type | Field and Description |
---|---|
protected E |
plugin
The
Plugin relevant to this CommandNode |
Constructor and Description |
---|
CommandNode(E plugin)
Initializes a new
CommandNode with no parent object |
CommandNode(E plugin,
CommandNode<?> parent)
Initializes a new
CommandNode with the passed parent object. |
Modifier and Type | Method and Description |
---|---|
void |
addChild(CommandNode<? extends Plugin>... children)
Adds new child subcommands to this
CommandNode |
void |
addChild(Function<E,CommandNode<? extends Plugin>>... children)
Adds new child subcommands to this
CommandNode |
<T extends Plugin> |
alias(CommandNode<T> toAlias,
String... args)
Aliases a passed
CommandNode . |
protected void |
aliasAsBukkitCommand(String cmd)
Allows this
CommandNode to be executed from Bukkit directly |
protected void |
attachReloadCommand()
Attaches a
ReloadCommand to this command object, to allow
reloading of the Plugin relevant to this node |
int |
compareTo(CommandNode<?> o)
|
void |
disallowProxiedSenders()
Disallows execution of this
CommandNode by a ProxiedCommandSender |
abstract CommandStatus |
execute(CommandSender sender,
String... args)
Represents the code at the end of a
CommandNode chain |
static String |
filterUsage(String usageRaw)
Filters out "usage tags" such as
[tag] or <tag> |
Map<String,CommandNode<? extends Plugin>> |
getAliases()
Returns all
CommandNode objects held by this node that are
aliases of other CommandNodes |
CommandNode<? extends Plugin> |
getChild(String... args)
Iteratively retrieves the child
CommandNode down the command
tree. |
CommandNode<? extends Plugin> |
getChild(String name)
Returns a subcommand, or
null if none exists. |
Collection<CommandNode<? extends Plugin>> |
getChildren()
Returns all subcommands as a
Collection |
CommandNode<? extends Plugin> |
getClosestChild(String... args)
Returns the closest possible approximation of where the supplied argument
ladder will stop.
|
HelpCommand<E> |
getHelpOutput()
Retrieves the help output for this
CommandNode , in the form of
a HelpCommand class |
static <T extends Plugin> |
getLinkingNode(String command,
T plugin,
Consumer<CommandNode<T>> onConstruct)
Returns an anonymous
CommandNode instance which is defined as
non-executable CommandNode used for chaining together other
CommandNode objects. |
abstract String |
getName()
Returns the name of the command, used for storing a
HashMap of
the commands as well as the subcommand argument |
CommandNode<? extends Plugin> |
getParent()
Returns the direct parent
CommandNode for this node |
String |
getUsage()
Returns the command usage
|
boolean |
hasRestriction()
Returns
true if there is a restriction imposed upon this
CommandNode |
abstract Lang |
info()
Information about this specific command.
|
boolean |
isExecutable()
Returns whether or not this node can be directly executed
|
void |
minimumArguments(int minimum)
Sets the minimum number of arguments for this command
|
boolean |
onCommand(CommandSender sender,
Command command,
String label,
String[] args)
Called from Bukkit to indicate an executed command
|
List<String> |
onTabComplete(CommandSender sender,
Command command,
String alias,
String[] args)
Called from Bukkit to indicate a call for tab completing
|
protected void |
registerAsBukkitCommand()
Registers this
CommandNode as a bukkit-executable command, and
places this CommandNode as the command name |
protected void |
registerAsListener()
|
protected void |
removeChild(String name)
Removes a child subcommand that is active under this
CommandNode |
protected void |
removeHelpCommand()
Removes the
HelpCommand associated with this CommandNode |
protected void |
requirePermission(Permissions perm)
Adds a
Permissions requirement for any executors of this node |
protected void |
setExecutable(boolean executable)
Sets whether or not this
CommandNode can be executed. |
void |
setRestriction(CommandStatus restriction)
Sets a restriction on this
CommandNode so that it may only
be executed by a particular type of CommandSender . |
protected abstract List<String> |
tabComplete(CommandSender sender,
String... args)
Returns a
List of possible strings that could be supplied for the
next argument |
String |
toString() |
Collection<CommandNode<? extends Plugin>> |
traverse()
Traverses the command tree with no restrictions (shows all commands)
|
Collection<CommandNode<? extends Plugin>> |
traverse(CommandSender sender,
boolean restrictions)
Traverses the
CommandNode tree and returns all child objects
found that satisfy the following:
The child's parent is the class that maps to it (aliases will be mapped to, but will not have the mapping parent class as an actual parent). |
protected String |
usage()
Describes the usage in the context of this specific
CommandNode |
protected final E extends Plugin plugin
Plugin
relevant to this CommandNode
public CommandNode(E plugin)
CommandNode
with no parent objectplugin
- The Plugin
relevant to this nodeCommandNode(Plugin, CommandNode)
public CommandNode(E plugin, CommandNode<?> parent)
CommandNode
with the passed parent object. This
also attaches a HelpCommand
as a sub-command in order to automate
help outputplugin
- The Plugin
relevant to this nodeparent
- The parent CommandNode
, or null
for nonepublic final boolean onCommand(CommandSender sender, Command command, String label, String[] args)
onCommand
in interface CommandExecutor
sender
- command
- label
- args
- true
if the returned CommandStatus
was not a
CommandStatus.FAILED
public abstract CommandStatus execute(CommandSender sender, String... args)
CommandNode
chainsender
- The command executorargs
- The command arguments, starting after the subcommand nameCommandStatus
representing the result of the command.
This will throw an NPE if null
is returnedpublic final List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args)
onTabComplete
in interface TabCompleter
sender
- command
- alias
- args
- protected abstract List<String> tabComplete(CommandSender sender, String... args)
List
of possible strings that could be supplied for the
next argumentsender
- The command "tabber"args
- The command arguments, starting after the subcommand name and
contains potentially unfinished argumentsList
of strings that can be supplied for the next argpublic abstract String getName()
HashMap
of
the commands as well as the subcommand argumentpublic final String getUsage()
CommandNode
protected String usage()
CommandNode
getName()
public abstract Lang info()
public final CommandNode<? extends Plugin> getParent()
CommandNode
for this nodepublic final void addChild(CommandNode<? extends Plugin>... children)
CommandNode
children
- Any CommandNodes
to addprotected final void removeChild(String name)
CommandNode
name
- The command label of the CommandNode
to removeprotected final void removeHelpCommand()
HelpCommand
associated with this CommandNode
@SafeVarargs public final void addChild(Function<E,CommandNode<? extends Plugin>>... children)
CommandNode
children
- Any CommandNodes
to addpublic final CommandNode<? extends Plugin> getChild(String name)
null
if none exists.name
- The name of the subcommandCommandNode
, or null if it does not existpublic CommandNode<? extends Plugin> getChild(String... args)
CommandNode
down the command
tree. If at any point in the depth search a node does not exist, this
will return null
args
- The different CommandNode
names to search throughnull
if not foundpublic CommandNode<? extends Plugin> getClosestChild(String... args)
args
- The argument ladder to climb throughCommandNode
approximation foundpublic final Collection<CommandNode<? extends Plugin>> getChildren()
Collection
Collection
of all registered CommandNode
public final int compareTo(CommandNode<?> o)
compareTo
in interface Comparable<CommandNode<?>>
o
- The CommandNode
to compare topublic Collection<CommandNode<? extends Plugin>> traverse()
traverse(CommandSender, boolean)
public Collection<CommandNode<? extends Plugin>> traverse(CommandSender sender, boolean restrictions)
CommandNode
tree and returns all child objects
found that satisfy the following:
HelpCommand
isExecutable()
is
true
CommandNode
children for this nodepublic final Map<String,CommandNode<? extends Plugin>> getAliases()
CommandNode
objects held by this node that are
aliases of other CommandNodes
CommandNode
objectsprotected final void attachReloadCommand()
ReloadCommand
to this command object, to allow
reloading of the Plugin
relevant to this nodeprotected final void setExecutable(boolean executable)
CommandNode
can be executed. If this is
set to false
, then the returned value of
execute(CommandSender, String...)
should be
CommandStatus.NOT_EXECUTABLE
. Normally a call to this method can
easily be supplemented by using
getLinkingNode(String, Plugin, Consumer)
instead.executable
- true
if this node can be directly executedgetLinkingNode(String, Plugin, Consumer)
protected final void requirePermission(Permissions perm)
Permissions
requirement for any executors of this nodeperm
- The Permissions
requirement to add to this nodepublic final boolean isExecutable()
true
if this node can be directly executedpublic final void minimumArguments(int minimum)
minimum
- The minimum number of arguments for this commandpublic final void disallowProxiedSenders()
CommandNode
by a ProxiedCommandSenderpublic final void setRestriction(CommandStatus restriction)
CommandNode
so that it may only
be executed by a particular type of CommandSender
. This method
only allows the following types:
restriction
- The CommandStatus
type to restrict withpublic boolean hasRestriction()
true
if there is a restriction imposed upon this
CommandNode
true
if this CommandNode
can only be executed by
one type of senderpublic final <T extends Plugin> void alias(CommandNode<T> toAlias, String... args)
CommandNode
. If no string arguments are
supplied, the passed child node will be aliased under this parent node
using the child's returned value from getName()
getLinkingNode(String, Plugin, Consumer)
T
- The type of the passed CommandNode
alias's plugintoAlias
- The CommandNode
to aliasargs
- The arguments chaining from this node to the aliasprotected final void aliasAsBukkitCommand(String cmd)
CommandNode
to be executed from Bukkit directlycmd
- The command to register as under Bukkitprotected final void registerAsBukkitCommand()
CommandNode
as a bukkit-executable command, and
places this CommandNode
as the command nameprotected final void registerAsListener()
Listener
to Bukkit, providing that this
command node implements the Listener
classpublic static <T extends Plugin> CommandNode<T> getLinkingNode(String command, T plugin, Consumer<CommandNode<T>> onConstruct)
CommandNode
instance which is defined as
non-executable CommandNode
used for chaining together other
CommandNode
objects.T
- The type of the Plugin
relevant to the new nodecommand
- The value for getName()
plugin
- The relevant Plugin
to this new nodeonConstruct
- Code to execute upon construction of the object, can
be null
CommandNode
objectpublic static String filterUsage(String usageRaw)
[tag]
or <tag>
usageRaw
- The raw usage string to modifypublic HelpCommand<E> getHelpOutput()
CommandNode
, in the form of
a HelpCommand
classHelpCommand
attached to this nodeCopyright © 2017. All rights reserved.