mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-24 11:15:19 +01:00
Create builder for command description; refactor command classes
- Create builder class for CommandDescription - Remove redundant methods in command registration classes (e.g. certain validation is superfluous because we only instantiate the classes internally) - Replace multiple occurrences where a field is directly instantiated e.g. with a list and then its value is overwritten by a constructor = redundant instantiation of objects
This commit is contained in:
parent
364583e7db
commit
faf9a2c8ac
@ -7,7 +7,7 @@ public class CommandArgumentDescription {
|
|||||||
// TODO: Allow argument to consist of infinite parts. <label ...>
|
// TODO: Allow argument to consist of infinite parts. <label ...>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Argument label.
|
* Argument label (one-word description of the argument).
|
||||||
*/
|
*/
|
||||||
private String label;
|
private String label;
|
||||||
/**
|
/**
|
||||||
@ -15,31 +15,21 @@ public class CommandArgumentDescription {
|
|||||||
*/
|
*/
|
||||||
private String description;
|
private String description;
|
||||||
/**
|
/**
|
||||||
* Defines whether the argument is optional.
|
* Defines whether the argument is isOptional.
|
||||||
*/
|
*/
|
||||||
private boolean optional = false;
|
private boolean isOptional = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param label The argument label.
|
* @param label The argument label.
|
||||||
* @param description The argument description.
|
* @param description The argument description.
|
||||||
|
* @param isOptional True if the argument is isOptional, false otherwise.
|
||||||
*/
|
*/
|
||||||
public CommandArgumentDescription(String label, String description) {
|
public CommandArgumentDescription(String label, String description, boolean isOptional) {
|
||||||
this(label, description, false);
|
this.label = label;
|
||||||
}
|
this.description = description;
|
||||||
|
this.isOptional = isOptional;
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param label The argument label.
|
|
||||||
* @param description The argument description.
|
|
||||||
* @param optional True if the argument is optional, false otherwise.
|
|
||||||
*/
|
|
||||||
public CommandArgumentDescription(String label, String description, boolean optional) {
|
|
||||||
setLabel(label);
|
|
||||||
setDescription(description);
|
|
||||||
setOptional(optional);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,15 +41,6 @@ public class CommandArgumentDescription {
|
|||||||
return this.label;
|
return this.label;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the argument label.
|
|
||||||
*
|
|
||||||
* @param label Argument label.
|
|
||||||
*/
|
|
||||||
public void setLabel(String label) {
|
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the argument description.
|
* Get the argument description.
|
||||||
*
|
*
|
||||||
@ -69,30 +50,13 @@ public class CommandArgumentDescription {
|
|||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the argument description.
|
|
||||||
*
|
|
||||||
* @param description Argument description.
|
|
||||||
*/
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the argument is optional.
|
* Check whether the argument is optional.
|
||||||
*
|
*
|
||||||
* @return True if the argument is optional, false otherwise.
|
* @return True if the argument is optional, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isOptional() {
|
public boolean isOptional() {
|
||||||
return optional;
|
return isOptional;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set whether the argument is optional.
|
|
||||||
*
|
|
||||||
* @param optional True if the argument is optional, false otherwise.
|
|
||||||
*/
|
|
||||||
public void setOptional(boolean optional) {
|
|
||||||
this.optional = optional;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,7 @@ import fr.xephi.authme.permission.PermissionNode;
|
|||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@ -16,15 +13,15 @@ public class CommandDescription {
|
|||||||
/**
|
/**
|
||||||
* Defines the acceptable labels.
|
* Defines the acceptable labels.
|
||||||
*/
|
*/
|
||||||
private List<String> labels = new ArrayList<>();
|
private List<String> labels;
|
||||||
/**
|
/**
|
||||||
* Command description.
|
* Command description.
|
||||||
*/
|
*/
|
||||||
private String description = "";
|
private String description;
|
||||||
/**
|
/**
|
||||||
* Detailed description.
|
* Detailed description.
|
||||||
*/
|
*/
|
||||||
private String detailedDescription = "";
|
private String detailedDescription;
|
||||||
/**
|
/**
|
||||||
* The executable command instance.
|
* The executable command instance.
|
||||||
*/
|
*/
|
||||||
@ -32,23 +29,24 @@ public class CommandDescription {
|
|||||||
/**
|
/**
|
||||||
* The parent command.
|
* The parent command.
|
||||||
*/
|
*/
|
||||||
private CommandDescription parent = null;
|
private CommandDescription parent;
|
||||||
/**
|
/**
|
||||||
* The child labels.
|
* The child labels.
|
||||||
*/
|
*/
|
||||||
|
// TODO: Remove list instantiation once Builder is the only way to construct objects
|
||||||
private List<CommandDescription> children = new ArrayList<>();
|
private List<CommandDescription> children = new ArrayList<>();
|
||||||
/**
|
/**
|
||||||
* The command arguments.
|
* The command arguments.
|
||||||
*/
|
*/
|
||||||
private List<CommandArgumentDescription> arguments = new ArrayList<>();
|
private List<CommandArgumentDescription> arguments;
|
||||||
/**
|
/**
|
||||||
* Defines whether there is an argument maximum or not.
|
* Defines whether there is an argument maximum or not.
|
||||||
*/
|
*/
|
||||||
private boolean noArgumentMaximum = false;
|
private boolean noArgumentMaximum;
|
||||||
/**
|
/**
|
||||||
* Defines the command permissions.
|
* Defines the command permissions.
|
||||||
*/
|
*/
|
||||||
private CommandPermissions permissions = new CommandPermissions();
|
private CommandPermissions permissions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -88,9 +86,9 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public CommandDescription(ExecutableCommand executableCommand, String label, String description, CommandDescription parent, String detailedDescription, List<CommandArgumentDescription> arguments) {
|
public CommandDescription(ExecutableCommand executableCommand, String label, String description, CommandDescription parent, String detailedDescription, List<CommandArgumentDescription> arguments) {
|
||||||
setExecutableCommand(executableCommand);
|
setExecutableCommand(executableCommand);
|
||||||
setLabel(label);
|
this.labels = Collections.singletonList(label);
|
||||||
setDescription(description);
|
this.description = description;
|
||||||
setDetailedDescription(detailedDescription);
|
this.detailedDescription = detailedDescription;
|
||||||
setParent(parent);
|
setParent(parent);
|
||||||
setArguments(arguments);
|
setArguments(arguments);
|
||||||
}
|
}
|
||||||
@ -107,38 +105,40 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent, List<CommandArgumentDescription> arguments) {
|
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent, List<CommandArgumentDescription> arguments) {
|
||||||
setExecutableCommand(executableCommand);
|
setExecutableCommand(executableCommand);
|
||||||
setLabels(labels);
|
this.labels = labels;
|
||||||
setDescription(description);
|
this.description = description;
|
||||||
setDetailedDescription(detailedDescription);
|
this.detailedDescription = detailedDescription;
|
||||||
setParent(parent);
|
setParent(parent);
|
||||||
setArguments(arguments);
|
setArguments(arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a label is valid to use.
|
* Private constructor. Use {@link CommandDescription#builder()} to create instances of this class.
|
||||||
*
|
*
|
||||||
* @param label The label to test.
|
* @param executableCommand The executable command, or null.
|
||||||
*
|
* @param labels List of command labels.
|
||||||
* @return True if the label is valid to use, false otherwise.
|
* @param description Command description.
|
||||||
|
* @param detailedDescription Detailed comment description.
|
||||||
|
* @param parent Parent command.
|
||||||
|
* @param arguments Command arguments.
|
||||||
*/
|
*/
|
||||||
public static boolean isValidLabel(String label) {
|
private CommandDescription(List<String> labels, String description, String detailedDescription,
|
||||||
// Make sure the label isn't null
|
ExecutableCommand executableCommand, CommandDescription parent,
|
||||||
if (label == null)
|
List<CommandDescription> children, List<CommandArgumentDescription> arguments,
|
||||||
return false;
|
boolean noArgumentMaximum, CommandPermissions permissions) {
|
||||||
|
this.labels = labels;
|
||||||
// Trim the label
|
this.description = description;
|
||||||
label = label.trim();
|
this.detailedDescription = detailedDescription;
|
||||||
|
this.executableCommand = executableCommand;
|
||||||
// Make sure the label is at least one character long
|
this.parent = parent;
|
||||||
if (label.length() <= 0)
|
this.children = children;
|
||||||
return false;
|
this.arguments = arguments;
|
||||||
|
this.noArgumentMaximum = noArgumentMaximum;
|
||||||
// Make sure the label doesn't contain any spaces, return the result
|
this.permissions = permissions;
|
||||||
return !label.contains(" ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether two labels equal to each other.
|
* Check whether two labels are equal to each other.
|
||||||
*
|
*
|
||||||
* @param commandLabel The first command label.
|
* @param commandLabel The first command label.
|
||||||
* @param otherCommandLabel The other command label.
|
* @param otherCommandLabel The other command label.
|
||||||
@ -154,28 +154,7 @@ public class CommandDescription {
|
|||||||
return (commandLabel.equalsIgnoreCase(otherCommandLabel));
|
return (commandLabel.equalsIgnoreCase(otherCommandLabel));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the first relative command label.
|
|
||||||
*
|
|
||||||
* @return First relative command label.
|
|
||||||
*/
|
|
||||||
public String getLabel() {
|
|
||||||
// Ensure there's any item in the command list
|
|
||||||
if (this.labels.size() == 0)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
// Return the first command on the list
|
|
||||||
return this.labels.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the command label, this will append the command label to already existing ones.
|
|
||||||
*
|
|
||||||
* @param commandLabel Command label to set or add.
|
|
||||||
*/
|
|
||||||
public void setLabel(String commandLabel) {
|
|
||||||
setLabel(commandLabel, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the label most similar to the reference. The first label will be returned if no reference was supplied.
|
* Get the label most similar to the reference. The first label will be returned if no reference was supplied.
|
||||||
@ -220,74 +199,6 @@ public class CommandDescription {
|
|||||||
return this.labels;
|
return this.labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the list of command labels.
|
|
||||||
*
|
|
||||||
* @param labels New list of command labels. Null to clear the list of labels.
|
|
||||||
*/
|
|
||||||
public void setLabels(List<String> labels) {
|
|
||||||
// Check whether the command label list should be cleared
|
|
||||||
if (labels == null) {
|
|
||||||
this.labels.clear();
|
|
||||||
} else {
|
|
||||||
this.labels = labels;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the command label.
|
|
||||||
*
|
|
||||||
* @param commandLabel Command label to set.
|
|
||||||
* @param overwrite True to replace all old command labels, false to append this command label to the currently
|
|
||||||
* existing labels.
|
|
||||||
*
|
|
||||||
* @return Trie if the command label is added, or if it was added already. False on failure.
|
|
||||||
*/
|
|
||||||
public boolean setLabel(String commandLabel, boolean overwrite) {
|
|
||||||
// Check whether this new command should overwrite the previous ones
|
|
||||||
if (!overwrite)
|
|
||||||
return addLabel(commandLabel);
|
|
||||||
|
|
||||||
// Replace all labels with this new one
|
|
||||||
this.labels.clear();
|
|
||||||
return this.labels.add(commandLabel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a command label to the list.
|
|
||||||
*
|
|
||||||
* @param commandLabel Command label to add.
|
|
||||||
*
|
|
||||||
* @return True if the label was added, or if it was added already. False on error.
|
|
||||||
*/
|
|
||||||
public boolean addLabel(String commandLabel) {
|
|
||||||
// Verify the label
|
|
||||||
if (!isValidLabel(commandLabel))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Ensure this command isn't a duplicate
|
|
||||||
if (hasLabel(commandLabel))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Add the command to the list
|
|
||||||
return this.labels.add(commandLabel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a list of command labels.
|
|
||||||
*
|
|
||||||
* @param commandLabels List of command labels to add.
|
|
||||||
*
|
|
||||||
* @return True if succeed, false on failure.
|
|
||||||
*/
|
|
||||||
public boolean addLabels(List<String> commandLabels) {
|
|
||||||
// Add each command label separately
|
|
||||||
for (String cmd : commandLabels)
|
|
||||||
if (!addLabel(cmd))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether this command description has a specific command.
|
* Check whether this command description has a specific command.
|
||||||
*
|
*
|
||||||
@ -305,23 +216,6 @@ public class CommandDescription {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether this command description has a list of labels
|
|
||||||
*
|
|
||||||
* @param commandLabels List of labels
|
|
||||||
*
|
|
||||||
* @return True if all labels match, false otherwise
|
|
||||||
*/
|
|
||||||
public boolean hasLabels(List<String> commandLabels) {
|
|
||||||
// Check if there's a match for every command
|
|
||||||
for (String cmd : commandLabels)
|
|
||||||
if (!hasLabel(cmd))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// There seems to be a match for every command, return true
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether this command label is applicable with a command reference. This doesn't check if the parent
|
* Check whether this command label is applicable with a command reference. This doesn't check if the parent
|
||||||
* are suitable too.
|
* are suitable too.
|
||||||
@ -567,8 +461,6 @@ public class CommandDescription {
|
|||||||
// Make sure the description is valid
|
// Make sure the description is valid
|
||||||
if (commandDescription == null)
|
if (commandDescription == null)
|
||||||
return false;
|
return false;
|
||||||
if (!commandDescription.isValid())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Make sure the child doesn't exist already
|
// Make sure the child doesn't exist already
|
||||||
if (isChild(commandDescription))
|
if (isChild(commandDescription))
|
||||||
@ -600,9 +492,7 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public boolean isChild(CommandDescription commandDescription) {
|
public boolean isChild(CommandDescription commandDescription) {
|
||||||
// Make sure the description is valid
|
// Make sure the description is valid
|
||||||
if (commandDescription == null)
|
if (commandDescription == null) // TODO: After builder, commandDescription == null -> never
|
||||||
return false;
|
|
||||||
if (!commandDescription.isValid())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check whether this child exists, return the result
|
// Check whether this child exists, return the result
|
||||||
@ -646,7 +536,10 @@ public class CommandDescription {
|
|||||||
public void setArguments(List<CommandArgumentDescription> arguments) {
|
public void setArguments(List<CommandArgumentDescription> arguments) {
|
||||||
// Convert null into an empty argument list
|
// Convert null into an empty argument list
|
||||||
if (arguments == null) {
|
if (arguments == null) {
|
||||||
this.arguments.clear();
|
// Note ljacqu 20151128: Temporary workaround to avoid null pointer exception. Soon we won't need setters
|
||||||
|
// on the main class (-> complete instantiation via Builder)
|
||||||
|
// TODO Remove this method once unused
|
||||||
|
this.arguments = new ArrayList<>();
|
||||||
} else {
|
} else {
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
}
|
}
|
||||||
@ -669,7 +562,7 @@ public class CommandDescription {
|
|||||||
* @return True if this command has any arguments.
|
* @return True if this command has any arguments.
|
||||||
*/
|
*/
|
||||||
public boolean hasArguments() {
|
public boolean hasArguments() {
|
||||||
return (this.arguments.size() != 0);
|
return !arguments.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -705,22 +598,13 @@ public class CommandDescription {
|
|||||||
public int getMaximumArguments() {
|
public int getMaximumArguments() {
|
||||||
// Check whether there is a maximum set
|
// Check whether there is a maximum set
|
||||||
if (this.noArgumentMaximum)
|
if (this.noArgumentMaximum)
|
||||||
|
// TODO ljacqu 20151128: Magic number
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Return the maximum based on the registered arguments
|
// Return the maximum based on the registered arguments
|
||||||
return this.arguments.size();
|
return this.arguments.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set whether there is an argument maximum.
|
|
||||||
*
|
|
||||||
* @param maximumArguments True if there is an argument maximum, based on the number of registered arguments.
|
|
||||||
*/
|
|
||||||
// TODO ljacqu 20151121: Rename the setter
|
|
||||||
public void setMaximumArguments(boolean maximumArguments) {
|
|
||||||
this.noArgumentMaximum = !maximumArguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the command description.
|
* Get the command description.
|
||||||
*
|
*
|
||||||
@ -730,26 +614,13 @@ public class CommandDescription {
|
|||||||
return hasDescription() ? this.description : this.detailedDescription;
|
return hasDescription() ? this.description : this.detailedDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the command description.
|
|
||||||
*
|
|
||||||
* @param description New command description. Null to reset the description.
|
|
||||||
*/
|
|
||||||
public void setDescription(String description) {
|
|
||||||
if (description == null)
|
|
||||||
this.description = "";
|
|
||||||
|
|
||||||
else
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether this command has any description.
|
* Check whether this command has any description.
|
||||||
*
|
*
|
||||||
* @return True if this command has any description.
|
* @return True if this command has any description.
|
||||||
*/
|
*/
|
||||||
public boolean hasDescription() {
|
public boolean hasDescription() {
|
||||||
return (this.description.trim().length() != 0);
|
return !StringUtils.isEmpty(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -758,29 +629,7 @@ public class CommandDescription {
|
|||||||
* @return Command detailed description.
|
* @return Command detailed description.
|
||||||
*/
|
*/
|
||||||
public String getDetailedDescription() {
|
public String getDetailedDescription() {
|
||||||
return hasDetailedDescription() ? this.detailedDescription : this.description;
|
return StringUtils.isEmpty(detailedDescription) ? this.detailedDescription : this.description;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the command detailed description.
|
|
||||||
*
|
|
||||||
* @param detailedDescription New command description. Null to reset the description.
|
|
||||||
*/
|
|
||||||
public void setDetailedDescription(String detailedDescription) {
|
|
||||||
if (detailedDescription == null)
|
|
||||||
this.detailedDescription = "";
|
|
||||||
|
|
||||||
else
|
|
||||||
this.detailedDescription = detailedDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether this command has any detailed description.
|
|
||||||
*
|
|
||||||
* @return True if this command has any detailed description.
|
|
||||||
*/
|
|
||||||
public boolean hasDetailedDescription() {
|
|
||||||
return (this.detailedDescription.trim().length() != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -907,15 +756,6 @@ public class CommandDescription {
|
|||||||
return this.permissions;
|
return this.permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the command permissions.
|
|
||||||
*
|
|
||||||
* @param commandPermissions The command permissions.
|
|
||||||
*/
|
|
||||||
public void setCommandPermissions(CommandPermissions commandPermissions) {
|
|
||||||
this.permissions = commandPermissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the command permissions.
|
* Set the command permissions.
|
||||||
*
|
*
|
||||||
@ -926,23 +766,112 @@ public class CommandDescription {
|
|||||||
this.permissions = new CommandPermissions(permissionNode, defaultPermission);
|
this.permissions = new CommandPermissions(permissionNode, defaultPermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static Builder builder() {
|
||||||
* Check whether the command description has been set up properly.
|
return new Builder();
|
||||||
*
|
|
||||||
* @return True if the command description is valid, false otherwise.
|
|
||||||
*/
|
|
||||||
public boolean isValid() {
|
|
||||||
// Make sure any command label is set
|
|
||||||
if (getLabels().size() == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the permissions are set up properly
|
|
||||||
if (this.permissions == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Everything seems to be correct, return the result
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class Builder {
|
||||||
|
private List<String> labels;
|
||||||
|
private String description;
|
||||||
|
private String detailedDescription;
|
||||||
|
private ExecutableCommand executableCommand;
|
||||||
|
private CommandDescription parent;
|
||||||
|
private List<CommandDescription> children;
|
||||||
|
private List<CommandArgumentDescription> arguments;
|
||||||
|
private boolean noArgumentMaximum;
|
||||||
|
private CommandPermissions permissions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a CommandDescription from the builder.
|
||||||
|
*
|
||||||
|
* @return The generated CommandDescription object
|
||||||
|
*/
|
||||||
|
public CommandDescription build() {
|
||||||
|
return new CommandDescription(
|
||||||
|
valueOrEmptyList(labels),
|
||||||
|
firstNonNull(description, ""),
|
||||||
|
firstNonNull(detailedDescription, ""),
|
||||||
|
firstNonNull(executableCommand, null), // TODO ljacqu 20151128: May `executableCommand` be null?
|
||||||
|
firstNonNull(parent, null),
|
||||||
|
valueOrEmptyList(children),
|
||||||
|
valueOrEmptyList(arguments),
|
||||||
|
noArgumentMaximum,
|
||||||
|
firstNonNull(permissions, null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder labels(List<String> labels) {
|
||||||
|
this.labels = labels;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder labels(String... labels) {
|
||||||
|
return labels(asMutableList(labels));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder description(String description) {
|
||||||
|
this.description = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder detailedDescription(String detailedDescription) {
|
||||||
|
this.detailedDescription = detailedDescription;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder executableCommand(ExecutableCommand executableCommand) {
|
||||||
|
this.executableCommand = executableCommand;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder parent(CommandDescription parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder children(List<CommandDescription> children) {
|
||||||
|
this.children = children;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder children(CommandDescription... children) {
|
||||||
|
return children(asMutableList(children));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder withArgument(String label, String description, boolean isOptional) {
|
||||||
|
if (arguments == null) {
|
||||||
|
arguments = new ArrayList<>();
|
||||||
|
}
|
||||||
|
arguments.add(new CommandArgumentDescription(label, description, isOptional));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder noArgumentMaximum(boolean noArgumentMaximum) {
|
||||||
|
this.noArgumentMaximum = noArgumentMaximum;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder permissions(CommandPermissions.DefaultPermission defaultPermission,
|
||||||
|
PermissionNode... permissionNodes) {
|
||||||
|
this.permissions = new CommandPermissions(asMutableList(permissionNodes), defaultPermission);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
private static <T> List<T> asMutableList(T... items) {
|
||||||
|
return new ArrayList<>(Arrays.asList(items));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> List<T> valueOrEmptyList(List<T> givenList) {
|
||||||
|
if (givenList != null) {
|
||||||
|
return givenList;
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> T firstNonNull(T first, T second) {
|
||||||
|
return first != null ? first : second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,11 @@ import fr.xephi.authme.permission.AdminPermission;
|
|||||||
import fr.xephi.authme.permission.UserPermission;
|
import fr.xephi.authme.permission.UserPermission;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static fr.xephi.authme.command.CommandPermissions.DefaultPermission.OP_ONLY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
@ -38,51 +41,51 @@ public class CommandManager {
|
|||||||
/**
|
/**
|
||||||
* Register all commands.
|
* Register all commands.
|
||||||
*/
|
*/
|
||||||
// TODO ljacqu 20151121: Create a builder class for CommandDescription
|
|
||||||
public void registerCommands() {
|
public void registerCommands() {
|
||||||
// Create a list of help command labels
|
// Create a list of help command labels
|
||||||
final List<String> helpCommandLabels = new ArrayList<String>() {
|
final List<String> helpCommandLabels = Arrays.asList("help", "hlp", "h", "sos", "?");
|
||||||
{
|
|
||||||
add("help");
|
|
||||||
add("hlp");
|
|
||||||
add("h");
|
|
||||||
add("sos");
|
|
||||||
add("?");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Register the base AuthMe Reloaded command
|
// Register the base AuthMe Reloaded command
|
||||||
CommandDescription authMeBaseCommand = new CommandDescription(new AuthMeCommand(), new ArrayList<String>() {
|
CommandDescription authMeBaseCommand = CommandDescription.builder()
|
||||||
|
.executableCommand(new AuthMeCommand())
|
||||||
{
|
.labels("authme")
|
||||||
add("authme");
|
.description("Main command")
|
||||||
}
|
.detailedDescription("The main AuthMeReloaded command. The root for all admin commands.")
|
||||||
}, "Main command", "The main AuthMeReloaded command. The root for all admin commands.", null);
|
.parent(null)
|
||||||
|
.build();
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription authMeHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
CommandDescription authMeHelpCommand = CommandDescription.builder()
|
||||||
"View help", "View detailed help pages about AuthMeReloaded commands.", authMeBaseCommand);
|
.executableCommand(new HelpCommand())
|
||||||
authMeHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
.labels(helpCommandLabels)
|
||||||
authMeHelpCommand.setMaximumArguments(false);
|
.description("View help")
|
||||||
|
.detailedDescription("View detailed help pages about AuthMeReloaded commands.")
|
||||||
|
.parent(authMeBaseCommand)
|
||||||
|
.withArgument("query", "The command or query to view help for.", true)
|
||||||
|
.build();
|
||||||
|
|
||||||
// Register the register command
|
// Register the register command
|
||||||
CommandDescription registerCommand = new CommandDescription(new RegisterCommand(), new ArrayList<String>() {
|
CommandDescription registerCommand = CommandDescription.builder()
|
||||||
|
.executableCommand(new RegisterCommand())
|
||||||
{
|
.labels("register", "reg", "r")
|
||||||
add("register");
|
.description("Register a player")
|
||||||
add("reg");
|
.detailedDescription("Register the specified player with the specified password.")
|
||||||
add("r");
|
.parent(authMeBaseCommand)
|
||||||
}
|
.permissions(OP_ONLY, UserPermission.REGISTER)
|
||||||
}, "Register a player", "Register the specified player with the specified password.", authMeBaseCommand);
|
.withArgument("player", "Player name", false)
|
||||||
registerCommand.setCommandPermissions(UserPermission.REGISTER, CommandPermissions.DefaultPermission.OP_ONLY);
|
.withArgument("password", "Password", false)
|
||||||
registerCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
.build();
|
||||||
registerCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
|
||||||
|
|
||||||
// Register the unregister command
|
// Register the unregister command
|
||||||
CommandDescription unregisterCommand = new CommandDescription(new UnregisterCommand(), helpCommandLabels,
|
CommandDescription unregisterCommand = CommandDescription.builder()
|
||||||
"Unregister a player", "Unregister the specified player.", authMeBaseCommand);
|
.executableCommand(new UnregisterCommand())
|
||||||
unregisterCommand.setCommandPermissions(UserPermission.UNREGISTER, CommandPermissions.DefaultPermission.OP_ONLY);
|
.labels("unregister", "unreg", "unr", "delete", "del")
|
||||||
unregisterCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
.description("Unregister a player")
|
||||||
|
.detailedDescription("Unregister the specified player.")
|
||||||
|
.parent(authMeBaseCommand)
|
||||||
|
.permissions(OP_ONLY, UserPermission.UNREGISTER)
|
||||||
|
.withArgument("player", "Player name", false)
|
||||||
|
.build();
|
||||||
|
|
||||||
// Register the forcelogin command
|
// Register the forcelogin command
|
||||||
CommandDescription forceLoginCommand = new CommandDescription(new ForceLoginCommand(), new ArrayList<String>() {
|
CommandDescription forceLoginCommand = new CommandDescription(new ForceLoginCommand(), new ArrayList<String>() {
|
||||||
@ -92,7 +95,7 @@ public class CommandManager {
|
|||||||
add("login");
|
add("login");
|
||||||
}
|
}
|
||||||
}, "Enforce login player", "Enforce the specified player to login.", authMeBaseCommand);
|
}, "Enforce login player", "Enforce the specified player to login.", authMeBaseCommand);
|
||||||
forceLoginCommand.setCommandPermissions(UserPermission.CAN_LOGIN_BE_FORCED, CommandPermissions.DefaultPermission.OP_ONLY);
|
forceLoginCommand.setCommandPermissions(UserPermission.CAN_LOGIN_BE_FORCED, OP_ONLY);
|
||||||
forceLoginCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
|
forceLoginCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
|
||||||
|
|
||||||
// Register the changepassword command
|
// Register the changepassword command
|
||||||
@ -105,7 +108,7 @@ public class CommandManager {
|
|||||||
add("cp");
|
add("cp");
|
||||||
}
|
}
|
||||||
}, "Change player's password", "Change the password of a player.", authMeBaseCommand);
|
}, "Change player's password", "Change the password of a player.", authMeBaseCommand);
|
||||||
changePasswordCommand.setCommandPermissions(AdminPermission.CHANGE_PASSWORD, CommandPermissions.DefaultPermission.OP_ONLY);
|
changePasswordCommand.setCommandPermissions(AdminPermission.CHANGE_PASSWORD, OP_ONLY);
|
||||||
changePasswordCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
changePasswordCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
||||||
changePasswordCommand.addArgument(new CommandArgumentDescription("pwd", "New password", false));
|
changePasswordCommand.addArgument(new CommandArgumentDescription("pwd", "New password", false));
|
||||||
|
|
||||||
@ -117,7 +120,7 @@ public class CommandManager {
|
|||||||
add("ll");
|
add("ll");
|
||||||
}
|
}
|
||||||
}, "Player's last login", "View the date of the specified players last login", authMeBaseCommand);
|
}, "Player's last login", "View the date of the specified players last login", authMeBaseCommand);
|
||||||
lastLoginCommand.setCommandPermissions(AdminPermission.LAST_LOGIN, CommandPermissions.DefaultPermission.OP_ONLY);
|
lastLoginCommand.setCommandPermissions(AdminPermission.LAST_LOGIN, OP_ONLY);
|
||||||
lastLoginCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
lastLoginCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
||||||
|
|
||||||
// Register the accounts command
|
// Register the accounts command
|
||||||
@ -128,7 +131,7 @@ public class CommandManager {
|
|||||||
add("account");
|
add("account");
|
||||||
}
|
}
|
||||||
}, "Display player accounts", "Display all accounts of a player by it's player name or IP.", authMeBaseCommand);
|
}, "Display player accounts", "Display all accounts of a player by it's player name or IP.", authMeBaseCommand);
|
||||||
accountsCommand.setCommandPermissions(AdminPermission.ACCOUNTS, CommandPermissions.DefaultPermission.OP_ONLY);
|
accountsCommand.setCommandPermissions(AdminPermission.ACCOUNTS, OP_ONLY);
|
||||||
accountsCommand.addArgument(new CommandArgumentDescription("player", "Player name or IP", true));
|
accountsCommand.addArgument(new CommandArgumentDescription("player", "Player name or IP", true));
|
||||||
|
|
||||||
// Register the getemail command
|
// Register the getemail command
|
||||||
@ -141,7 +144,7 @@ public class CommandManager {
|
|||||||
add("mail");
|
add("mail");
|
||||||
}
|
}
|
||||||
}, "Display player's email", "Display the email address of the specified player if set.", authMeBaseCommand);
|
}, "Display player's email", "Display the email address of the specified player if set.", authMeBaseCommand);
|
||||||
getEmailCommand.setCommandPermissions(AdminPermission.GET_EMAIL, CommandPermissions.DefaultPermission.OP_ONLY);
|
getEmailCommand.setCommandPermissions(AdminPermission.GET_EMAIL, OP_ONLY);
|
||||||
getEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
getEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
||||||
|
|
||||||
// Register the setemail command
|
// Register the setemail command
|
||||||
@ -154,7 +157,7 @@ public class CommandManager {
|
|||||||
add("setmail");
|
add("setmail");
|
||||||
}
|
}
|
||||||
}, "Change player's email", "Change the email address of the specified player.", authMeBaseCommand);
|
}, "Change player's email", "Change the email address of the specified player.", authMeBaseCommand);
|
||||||
setEmailCommand.setCommandPermissions(AdminPermission.CHANGE_EMAIL, CommandPermissions.DefaultPermission.OP_ONLY);
|
setEmailCommand.setCommandPermissions(AdminPermission.CHANGE_EMAIL, OP_ONLY);
|
||||||
setEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
setEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
||||||
setEmailCommand.addArgument(new CommandArgumentDescription("email", "Player email", false));
|
setEmailCommand.addArgument(new CommandArgumentDescription("email", "Player email", false));
|
||||||
|
|
||||||
@ -166,7 +169,7 @@ public class CommandManager {
|
|||||||
add("ip");
|
add("ip");
|
||||||
}
|
}
|
||||||
}, "Get player's IP", "Get the IP address of the specified online player.", authMeBaseCommand);
|
}, "Get player's IP", "Get the IP address of the specified online player.", authMeBaseCommand);
|
||||||
getIpCommand.setCommandPermissions(AdminPermission.GET_IP, CommandPermissions.DefaultPermission.OP_ONLY);
|
getIpCommand.setCommandPermissions(AdminPermission.GET_IP, OP_ONLY);
|
||||||
getIpCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
|
getIpCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
|
||||||
|
|
||||||
// Register the spawn command
|
// Register the spawn command
|
||||||
@ -177,7 +180,7 @@ public class CommandManager {
|
|||||||
add("home");
|
add("home");
|
||||||
}
|
}
|
||||||
}, "Teleport to spawn", "Teleport to the spawn.", authMeBaseCommand);
|
}, "Teleport to spawn", "Teleport to the spawn.", authMeBaseCommand);
|
||||||
spawnCommand.setCommandPermissions(AdminPermission.SPAWN, CommandPermissions.DefaultPermission.OP_ONLY);
|
spawnCommand.setCommandPermissions(AdminPermission.SPAWN, OP_ONLY);
|
||||||
|
|
||||||
// Register the setspawn command
|
// Register the setspawn command
|
||||||
CommandDescription setSpawnCommand = new CommandDescription(new SetSpawnCommand(), new ArrayList<String>() {
|
CommandDescription setSpawnCommand = new CommandDescription(new SetSpawnCommand(), new ArrayList<String>() {
|
||||||
@ -187,7 +190,7 @@ public class CommandManager {
|
|||||||
add("chgspawn");
|
add("chgspawn");
|
||||||
}
|
}
|
||||||
}, "Change the spawn", "Change the player's spawn to your current position.", authMeBaseCommand);
|
}, "Change the spawn", "Change the player's spawn to your current position.", authMeBaseCommand);
|
||||||
setSpawnCommand.setCommandPermissions(AdminPermission.SET_SPAWN, CommandPermissions.DefaultPermission.OP_ONLY);
|
setSpawnCommand.setCommandPermissions(AdminPermission.SET_SPAWN, OP_ONLY);
|
||||||
|
|
||||||
// Register the firstspawn command
|
// Register the firstspawn command
|
||||||
CommandDescription firstSpawnCommand = new CommandDescription(new FirstSpawnCommand(), new ArrayList<String>() {
|
CommandDescription firstSpawnCommand = new CommandDescription(new FirstSpawnCommand(), new ArrayList<String>() {
|
||||||
@ -197,7 +200,7 @@ public class CommandManager {
|
|||||||
add("firsthome");
|
add("firsthome");
|
||||||
}
|
}
|
||||||
}, "Teleport to first spawn", "Teleport to the first spawn.", authMeBaseCommand);
|
}, "Teleport to first spawn", "Teleport to the first spawn.", authMeBaseCommand);
|
||||||
firstSpawnCommand.setCommandPermissions(AdminPermission.FIRST_SPAWN, CommandPermissions.DefaultPermission.OP_ONLY);
|
firstSpawnCommand.setCommandPermissions(AdminPermission.FIRST_SPAWN, OP_ONLY);
|
||||||
|
|
||||||
// Register the setfirstspawn command
|
// Register the setfirstspawn command
|
||||||
CommandDescription setFirstSpawnCommand = new CommandDescription(new SetFirstSpawnCommand(), new ArrayList<String>() {
|
CommandDescription setFirstSpawnCommand = new CommandDescription(new SetFirstSpawnCommand(), new ArrayList<String>() {
|
||||||
@ -207,7 +210,7 @@ public class CommandManager {
|
|||||||
add("chgfirstspawn");
|
add("chgfirstspawn");
|
||||||
}
|
}
|
||||||
}, "Change the first spawn", "Change the first player's spawn to your current position.", authMeBaseCommand);
|
}, "Change the first spawn", "Change the first player's spawn to your current position.", authMeBaseCommand);
|
||||||
setFirstSpawnCommand.setCommandPermissions(AdminPermission.SET_FIRST_SPAWN, CommandPermissions.DefaultPermission.OP_ONLY);
|
setFirstSpawnCommand.setCommandPermissions(AdminPermission.SET_FIRST_SPAWN, OP_ONLY);
|
||||||
|
|
||||||
// Register the purge command
|
// Register the purge command
|
||||||
CommandDescription purgeCommand = new CommandDescription(new PurgeCommand(), new ArrayList<String>() {
|
CommandDescription purgeCommand = new CommandDescription(new PurgeCommand(), new ArrayList<String>() {
|
||||||
@ -217,7 +220,7 @@ public class CommandManager {
|
|||||||
add("delete");
|
add("delete");
|
||||||
}
|
}
|
||||||
}, "Purge old data", "Purge old AuthMeReloaded data longer than the specified amount of days ago.", authMeBaseCommand);
|
}, "Purge old data", "Purge old AuthMeReloaded data longer than the specified amount of days ago.", authMeBaseCommand);
|
||||||
purgeCommand.setCommandPermissions(AdminPermission.PURGE, CommandPermissions.DefaultPermission.OP_ONLY);
|
purgeCommand.setCommandPermissions(AdminPermission.PURGE, OP_ONLY);
|
||||||
purgeCommand.addArgument(new CommandArgumentDescription("days", "Number of days", false));
|
purgeCommand.addArgument(new CommandArgumentDescription("days", "Number of days", false));
|
||||||
|
|
||||||
// Register the purgelastposition command
|
// Register the purgelastposition command
|
||||||
@ -232,7 +235,7 @@ public class CommandManager {
|
|||||||
add("resetlastpos");
|
add("resetlastpos");
|
||||||
}
|
}
|
||||||
}, "Purge player's last position", "Purge the last know position of the specified player.", authMeBaseCommand);
|
}, "Purge player's last position", "Purge the last know position of the specified player.", authMeBaseCommand);
|
||||||
purgeLastPositionCommand.setCommandPermissions(AdminPermission.PURGE_LAST_POSITION, CommandPermissions.DefaultPermission.OP_ONLY);
|
purgeLastPositionCommand.setCommandPermissions(AdminPermission.PURGE_LAST_POSITION, OP_ONLY);
|
||||||
purgeLastPositionCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
purgeLastPositionCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
||||||
|
|
||||||
// Register the purgebannedplayers command
|
// Register the purgebannedplayers command
|
||||||
@ -245,7 +248,7 @@ public class CommandManager {
|
|||||||
add("deletebannedplayer");
|
add("deletebannedplayer");
|
||||||
}
|
}
|
||||||
}, "Purge banned palyers data", "Purge all AuthMeReloaded data for banned players.", authMeBaseCommand);
|
}, "Purge banned palyers data", "Purge all AuthMeReloaded data for banned players.", authMeBaseCommand);
|
||||||
purgeBannedPlayersCommand.setCommandPermissions(AdminPermission.PURGE_BANNED_PLAYERS, CommandPermissions.DefaultPermission.OP_ONLY);
|
purgeBannedPlayersCommand.setCommandPermissions(AdminPermission.PURGE_BANNED_PLAYERS, OP_ONLY);
|
||||||
|
|
||||||
// Register the switchantibot command
|
// Register the switchantibot command
|
||||||
CommandDescription switchAntiBotCommand = new CommandDescription(new SwitchAntiBotCommand(), new ArrayList<String>() {
|
CommandDescription switchAntiBotCommand = new CommandDescription(new SwitchAntiBotCommand(), new ArrayList<String>() {
|
||||||
@ -256,7 +259,7 @@ public class CommandManager {
|
|||||||
add("antibot");
|
add("antibot");
|
||||||
}
|
}
|
||||||
}, "Switch AntiBot mode", "Switch or toggle the AntiBot mode to the specified state.", authMeBaseCommand);
|
}, "Switch AntiBot mode", "Switch or toggle the AntiBot mode to the specified state.", authMeBaseCommand);
|
||||||
switchAntiBotCommand.setCommandPermissions(AdminPermission.SWITCH_ANTIBOT, CommandPermissions.DefaultPermission.OP_ONLY);
|
switchAntiBotCommand.setCommandPermissions(AdminPermission.SWITCH_ANTIBOT, OP_ONLY);
|
||||||
switchAntiBotCommand.addArgument(new CommandArgumentDescription("mode", "ON / OFF", true));
|
switchAntiBotCommand.addArgument(new CommandArgumentDescription("mode", "ON / OFF", true));
|
||||||
|
|
||||||
// // Register the resetname command
|
// // Register the resetname command
|
||||||
@ -280,12 +283,17 @@ public class CommandManager {
|
|||||||
add("rld");
|
add("rld");
|
||||||
}
|
}
|
||||||
}, "Reload plugin", "Reload the AuthMeReloaded plugin.", authMeBaseCommand);
|
}, "Reload plugin", "Reload the AuthMeReloaded plugin.", authMeBaseCommand);
|
||||||
reloadCommand.setCommandPermissions(AdminPermission.RELOAD, CommandPermissions.DefaultPermission.OP_ONLY);
|
reloadCommand.setCommandPermissions(AdminPermission.RELOAD, OP_ONLY);
|
||||||
|
|
||||||
// Register the version command
|
// Register the version command
|
||||||
|
/* TODO ljacqu 20151128: labels should not be helpCommandLabels! Previously it was:
|
||||||
|
add("version");
|
||||||
|
add("ver");
|
||||||
|
add("v");
|
||||||
|
add("about");
|
||||||
|
add("info");*/
|
||||||
CommandDescription versionCommand = new CommandDescription(new VersionCommand(), helpCommandLabels,
|
CommandDescription versionCommand = new CommandDescription(new VersionCommand(), helpCommandLabels,
|
||||||
"Version info", "Show detailed information about the installed AuthMeReloaded version, and shows the developers, contributors, license and other information.", authMeBaseCommand);
|
"Version info", "Show detailed information about the installed AuthMeReloaded version, and shows the developers, contributors, license and other information.", authMeBaseCommand);
|
||||||
versionCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base login command
|
// Register the base login command
|
||||||
CommandDescription loginBaseCommand = new CommandDescription(new LoginCommand(), new ArrayList<String>() {
|
CommandDescription loginBaseCommand = new CommandDescription(new LoginCommand(), new ArrayList<String>() {
|
||||||
@ -302,7 +310,6 @@ public class CommandManager {
|
|||||||
CommandDescription loginHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
CommandDescription loginHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
||||||
"View help", "View detailed help pages about AuthMeReloaded login commands.", loginBaseCommand);
|
"View help", "View detailed help pages about AuthMeReloaded login commands.", loginBaseCommand);
|
||||||
loginHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
loginHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
loginHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base logout command
|
// Register the base logout command
|
||||||
CommandDescription logoutBaseCommand = new CommandDescription(new LogoutCommand(), new ArrayList<String>() {
|
CommandDescription logoutBaseCommand = new CommandDescription(new LogoutCommand(), new ArrayList<String>() {
|
||||||
@ -317,7 +324,6 @@ public class CommandManager {
|
|||||||
CommandDescription logoutHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
CommandDescription logoutHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
||||||
"View help", "View detailed help pages about AuthMeReloaded logout commands.", logoutBaseCommand);
|
"View help", "View detailed help pages about AuthMeReloaded logout commands.", logoutBaseCommand);
|
||||||
logoutHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
logoutHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
logoutHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base register command
|
// Register the base register command
|
||||||
CommandDescription registerBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.register.RegisterCommand(), new ArrayList<String>() {
|
CommandDescription registerBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.register.RegisterCommand(), new ArrayList<String>() {
|
||||||
@ -330,13 +336,11 @@ public class CommandManager {
|
|||||||
registerBaseCommand.setCommandPermissions(UserPermission.REGISTER, CommandPermissions.DefaultPermission.ALLOWED);
|
registerBaseCommand.setCommandPermissions(UserPermission.REGISTER, CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
registerBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
registerBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
||||||
registerBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
|
registerBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
|
||||||
registerBaseCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription registerHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
CommandDescription registerHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
||||||
"View help", "View detailed help pages about AuthMeReloaded register commands.", registerBaseCommand);
|
"View help", "View detailed help pages about AuthMeReloaded register commands.", registerBaseCommand);
|
||||||
registerHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
registerHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
registerHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base unregister command
|
// Register the base unregister command
|
||||||
CommandDescription unregisterBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.unregister.UnregisterCommand(), new ArrayList<String>() {
|
CommandDescription unregisterBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.unregister.UnregisterCommand(), new ArrayList<String>() {
|
||||||
@ -352,7 +356,6 @@ public class CommandManager {
|
|||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription unregisterHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels, "View help", "View detailed help pages about AuthMeReloaded unregister commands.", unregisterBaseCommand);
|
CommandDescription unregisterHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels, "View help", "View detailed help pages about AuthMeReloaded unregister commands.", unregisterBaseCommand);
|
||||||
unregisterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
unregisterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
unregisterHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base changepassword command
|
// Register the base changepassword command
|
||||||
CommandDescription changePasswordBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.changepassword.ChangePasswordCommand(), new ArrayList<String>() {
|
CommandDescription changePasswordBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.changepassword.ChangePasswordCommand(), new ArrayList<String>() {
|
||||||
@ -365,13 +368,11 @@ public class CommandManager {
|
|||||||
changePasswordBaseCommand.setCommandPermissions(UserPermission.CHANGE_PASSWORD, CommandPermissions.DefaultPermission.ALLOWED);
|
changePasswordBaseCommand.setCommandPermissions(UserPermission.CHANGE_PASSWORD, CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
||||||
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
|
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
|
||||||
changePasswordBaseCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription changePasswordHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
CommandDescription changePasswordHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
||||||
"View help", "View detailed help pages about AuthMeReloaded change password commands.", changePasswordBaseCommand);
|
"View help", "View detailed help pages about AuthMeReloaded change password commands.", changePasswordBaseCommand);
|
||||||
changePasswordHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
changePasswordHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
changePasswordHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base Dungeon Maze command
|
// Register the base Dungeon Maze command
|
||||||
CommandDescription emailBaseCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
CommandDescription emailBaseCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
||||||
@ -386,7 +387,6 @@ public class CommandManager {
|
|||||||
CommandDescription emailHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
CommandDescription emailHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
||||||
"View help", "View detailed help pages about AuthMeReloaded help commands.", emailBaseCommand);
|
"View help", "View detailed help pages about AuthMeReloaded help commands.", emailBaseCommand);
|
||||||
emailHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
emailHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
emailHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the add command
|
// Register the add command
|
||||||
CommandDescription addEmailCommand = new CommandDescription(new AddEmailCommand(), new ArrayList<String>() {
|
CommandDescription addEmailCommand = new CommandDescription(new AddEmailCommand(), new ArrayList<String>() {
|
||||||
@ -437,13 +437,11 @@ public class CommandManager {
|
|||||||
}, "Captcha command", "Captcha command for AuthMeReloaded.", null);
|
}, "Captcha command", "Captcha command for AuthMeReloaded.", null);
|
||||||
captchaBaseCommand.setCommandPermissions(UserPermission.CAPTCHA, CommandPermissions.DefaultPermission.ALLOWED);
|
captchaBaseCommand.setCommandPermissions(UserPermission.CAPTCHA, CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
captchaBaseCommand.addArgument(new CommandArgumentDescription("captcha", "The captcha", false));
|
captchaBaseCommand.addArgument(new CommandArgumentDescription("captcha", "The captcha", false));
|
||||||
captchaBaseCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription captchaHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
CommandDescription captchaHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
||||||
"View help", "View detailed help pages about AuthMeReloaded change captcha commands.", captchaBaseCommand);
|
"View help", "View detailed help pages about AuthMeReloaded change captcha commands.", captchaBaseCommand);
|
||||||
captchaHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
captchaHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
captchaHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base converter command
|
// Register the base converter command
|
||||||
CommandDescription converterBaseCommand = new CommandDescription(new ConverterCommand(), new ArrayList<String>() {
|
CommandDescription converterBaseCommand = new CommandDescription(new ConverterCommand(), new ArrayList<String>() {
|
||||||
@ -454,15 +452,13 @@ public class CommandManager {
|
|||||||
add("conv");
|
add("conv");
|
||||||
}
|
}
|
||||||
}, "Convert command", "Convert command for AuthMeReloaded.", null);
|
}, "Convert command", "Convert command for AuthMeReloaded.", null);
|
||||||
converterBaseCommand.setCommandPermissions(UserPermission.CONVERTER, CommandPermissions.DefaultPermission.OP_ONLY);
|
converterBaseCommand.setCommandPermissions(UserPermission.CONVERTER, OP_ONLY);
|
||||||
converterBaseCommand.addArgument(new CommandArgumentDescription("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false));
|
converterBaseCommand.addArgument(new CommandArgumentDescription("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false));
|
||||||
converterBaseCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription converterHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
CommandDescription converterHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
|
||||||
"View help", "View detailed help pages about AuthMeReloaded change captcha commands.", converterBaseCommand);
|
"View help", "View detailed help pages about AuthMeReloaded change captcha commands.", converterBaseCommand);
|
||||||
converterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
converterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
converterHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Add the base commands to the commands array
|
// Add the base commands to the commands array
|
||||||
this.commandDescriptions.add(authMeBaseCommand);
|
this.commandDescriptions.add(authMeBaseCommand);
|
||||||
|
@ -9,9 +9,6 @@ import org.bukkit.entity.Player;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
//import com.timvisee.dungeonmaze.Core;
|
|
||||||
//import com.timvisee.dungeonmaze.permission.PermissionsManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class CommandPermissions {
|
public class CommandPermissions {
|
||||||
@ -19,17 +16,11 @@ public class CommandPermissions {
|
|||||||
/**
|
/**
|
||||||
* Defines the permission nodes required to have permission to execute this command.
|
* Defines the permission nodes required to have permission to execute this command.
|
||||||
*/
|
*/
|
||||||
private List<PermissionNode> permissionNodes = new ArrayList<>();
|
private List<PermissionNode> permissionNodes;
|
||||||
/**
|
/**
|
||||||
* Defines the default permission if the permission nodes couldn't be used.
|
* Defines the default permission if the permission nodes couldn't be used.
|
||||||
*/
|
*/
|
||||||
private DefaultPermission defaultPermission = DefaultPermission.NOT_ALLOWED;
|
private DefaultPermission defaultPermission;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*/
|
|
||||||
public CommandPermissions() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -38,6 +29,7 @@ public class CommandPermissions {
|
|||||||
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
||||||
*/
|
*/
|
||||||
public CommandPermissions(PermissionNode permissionNode, DefaultPermission defaultPermission) {
|
public CommandPermissions(PermissionNode permissionNode, DefaultPermission defaultPermission) {
|
||||||
|
this.permissionNodes = new ArrayList<>();
|
||||||
this.permissionNodes.add(permissionNode);
|
this.permissionNodes.add(permissionNode);
|
||||||
this.defaultPermission = defaultPermission;
|
this.defaultPermission = defaultPermission;
|
||||||
}
|
}
|
||||||
@ -49,34 +41,8 @@ public class CommandPermissions {
|
|||||||
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
||||||
*/
|
*/
|
||||||
public CommandPermissions(List<PermissionNode> permissionNodes, DefaultPermission defaultPermission) {
|
public CommandPermissions(List<PermissionNode> permissionNodes, DefaultPermission defaultPermission) {
|
||||||
this.permissionNodes.addAll(permissionNodes);
|
this.permissionNodes = permissionNodes;
|
||||||
}
|
this.defaultPermission = defaultPermission;
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a permission node required to execute this command.
|
|
||||||
*
|
|
||||||
* @param permissionNode The permission node to add.
|
|
||||||
*
|
|
||||||
* @return True on success, false on failure.
|
|
||||||
*/
|
|
||||||
public boolean addPermissionNode(PermissionNode permissionNode) {
|
|
||||||
// Make sure this permission node hasn't been added already
|
|
||||||
if (hasPermissionNode(permissionNode))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Add the permission node, return the result
|
|
||||||
return this.permissionNodes.add(permissionNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether this command requires a specified permission node to execute.
|
|
||||||
*
|
|
||||||
* @param permissionNode The permission node to check for.
|
|
||||||
*
|
|
||||||
* @return True if this permission node is required, false if not.
|
|
||||||
*/
|
|
||||||
public boolean hasPermissionNode(PermissionNode permissionNode) {
|
|
||||||
return this.permissionNodes.contains(permissionNode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,14 +54,6 @@ public class CommandPermissions {
|
|||||||
return this.permissionNodes;
|
return this.permissionNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the permission nodes required to execute this command.
|
|
||||||
*
|
|
||||||
* @param permissionNodes The permission nodes required to execute this command.
|
|
||||||
*/
|
|
||||||
public void setPermissionNodes(List<PermissionNode> permissionNodes) {
|
|
||||||
this.permissionNodes = permissionNodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of permission nodes set.
|
* Get the number of permission nodes set.
|
||||||
|
@ -44,7 +44,7 @@ public class HelpPrinter {
|
|||||||
sender.sendMessage(ChatColor.GOLD + "Short Description: " + ChatColor.WHITE + command.getDescription());
|
sender.sendMessage(ChatColor.GOLD + "Short Description: " + ChatColor.WHITE + command.getDescription());
|
||||||
|
|
||||||
// Print the detailed description, if available
|
// Print the detailed description, if available
|
||||||
if (command.hasDetailedDescription()) {
|
if (!StringUtils.isEmpty(command.getDetailedDescription())) {
|
||||||
sender.sendMessage(ChatColor.GOLD + "Detailed Description:");
|
sender.sendMessage(ChatColor.GOLD + "Detailed Description:");
|
||||||
sender.sendMessage(ChatColor.WHITE + " " + command.getDetailedDescription());
|
sender.sendMessage(ChatColor.WHITE + " " + command.getDetailedDescription());
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import fr.xephi.authme.command.CommandParts;
|
|||||||
import fr.xephi.authme.command.executable.authme.AuthMeCommand;
|
import fr.xephi.authme.command.executable.authme.AuthMeCommand;
|
||||||
import fr.xephi.authme.command.executable.authme.RegisterCommand;
|
import fr.xephi.authme.command.executable.authme.RegisterCommand;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -26,7 +27,9 @@ public class HelpSyntaxHelperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldFormatSimpleCommand() {
|
public void shouldFormatSimpleCommand() {
|
||||||
// given
|
// given
|
||||||
CommandDescription description = getDescription();
|
CommandDescription description = getDescriptionBuilder()
|
||||||
|
.withArgument("name", "The name", true)
|
||||||
|
.build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String result = HelpSyntaxHelper.getCommandSyntax(
|
String result = HelpSyntaxHelper.getCommandSyntax(
|
||||||
@ -39,9 +42,9 @@ public class HelpSyntaxHelperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldFormatSimpleCommandWithOptionalParam() {
|
public void shouldFormatSimpleCommandWithOptionalParam() {
|
||||||
// given
|
// given
|
||||||
CommandDescription description = getDescription();
|
CommandDescription description = getDescriptionBuilder()
|
||||||
description.setArguments(singletonList(
|
.withArgument("test", "", false)
|
||||||
new CommandArgumentDescription("test", "", false)));
|
.build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String result = HelpSyntaxHelper.getCommandSyntax(
|
String result = HelpSyntaxHelper.getCommandSyntax(
|
||||||
@ -54,10 +57,10 @@ public class HelpSyntaxHelperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldFormatCommandWithMultipleParams() {
|
public void shouldFormatCommandWithMultipleParams() {
|
||||||
// given
|
// given
|
||||||
CommandDescription description = getDescription();
|
CommandDescription description = getDescriptionBuilder()
|
||||||
description.setArguments(Arrays.asList(
|
.withArgument("name", "", true)
|
||||||
new CommandArgumentDescription("name", "", true),
|
.withArgument("test", "", false)
|
||||||
new CommandArgumentDescription("test", "", false)));
|
.build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String result = HelpSyntaxHelper.getCommandSyntax(
|
String result = HelpSyntaxHelper.getCommandSyntax(
|
||||||
@ -70,10 +73,10 @@ public class HelpSyntaxHelperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldHighlightCommandWithMultipleParams() {
|
public void shouldHighlightCommandWithMultipleParams() {
|
||||||
// given
|
// given
|
||||||
CommandDescription description = getDescription();
|
CommandDescription description = getDescriptionBuilder()
|
||||||
description.setArguments(Arrays.asList(
|
.withArgument("name", "", true)
|
||||||
new CommandArgumentDescription("name", "", true),
|
.withArgument("test", "", false)
|
||||||
new CommandArgumentDescription("test", "", false)));
|
.build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String result = HelpSyntaxHelper.getCommandSyntax(
|
String result = HelpSyntaxHelper.getCommandSyntax(
|
||||||
@ -88,8 +91,7 @@ public class HelpSyntaxHelperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldHighlightCommandWithNoParams() {
|
public void shouldHighlightCommandWithNoParams() {
|
||||||
// given
|
// given
|
||||||
CommandDescription description = getDescription();
|
CommandDescription description = getDescriptionBuilder().build();
|
||||||
description.setArguments(new ArrayList<CommandArgumentDescription>());
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String result = HelpSyntaxHelper.getCommandSyntax(
|
String result = HelpSyntaxHelper.getCommandSyntax(
|
||||||
@ -102,7 +104,9 @@ public class HelpSyntaxHelperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldFormatSimpleCommandWithAlternativeLabel() {
|
public void shouldFormatSimpleCommandWithAlternativeLabel() {
|
||||||
// given
|
// given
|
||||||
CommandDescription description = getDescription();
|
CommandDescription description = getDescriptionBuilder()
|
||||||
|
.withArgument("name", "The name", true)
|
||||||
|
.build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String result = HelpSyntaxHelper.getCommandSyntax(
|
String result = HelpSyntaxHelper.getCommandSyntax(
|
||||||
@ -115,11 +119,11 @@ public class HelpSyntaxHelperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldHighlightCommandWithAltLabelAndUnlimitedArguments() {
|
public void shouldHighlightCommandWithAltLabelAndUnlimitedArguments() {
|
||||||
// given
|
// given
|
||||||
CommandDescription description = getDescription();
|
CommandDescription description = getDescriptionBuilder()
|
||||||
description.setArguments(Arrays.asList(
|
.withArgument("name", "", true)
|
||||||
new CommandArgumentDescription("name", "", true),
|
.withArgument("test", "", false)
|
||||||
new CommandArgumentDescription("test", "", false)));
|
.noArgumentMaximum(true)
|
||||||
description.setMaximumArguments(false);
|
.build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String result = HelpSyntaxHelper.getCommandSyntax(
|
String result = HelpSyntaxHelper.getCommandSyntax(
|
||||||
@ -132,21 +136,19 @@ public class HelpSyntaxHelperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static CommandDescription getDescription() {
|
private static CommandDescription.Builder getDescriptionBuilder() {
|
||||||
CommandDescription base = new CommandDescription(new AuthMeCommand(),
|
CommandDescription base = CommandDescription.builder()
|
||||||
singletonList("authme"),
|
.labels("authme")
|
||||||
"Base command",
|
.description("Base command")
|
||||||
"AuthMe base command",
|
.detailedDescription("AuthMe base command")
|
||||||
null);
|
.parent(null)
|
||||||
CommandArgumentDescription userArg = new CommandArgumentDescription(
|
.build();
|
||||||
"name", "", true);
|
|
||||||
|
|
||||||
return new CommandDescription(
|
return CommandDescription.builder()
|
||||||
new RegisterCommand(),
|
.executableCommand(Mockito.mock(RegisterCommand.class))
|
||||||
Arrays.asList("register", "r"),
|
.labels("register", "r")
|
||||||
"Register a player",
|
.description("Register a player")
|
||||||
"Register the specified player with the specified password.",
|
.detailedDescription("Register the specified player with the specified password.")
|
||||||
base,
|
.parent(base);
|
||||||
singletonList(userArg));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user