Merge origin/enum into local branch
This commit is contained in:
@@ -6,17 +6,23 @@ public class CommandArgumentDescription {
|
||||
|
||||
// TODO: Allow argument to consist of infinite parts. <label ...>
|
||||
|
||||
/** Argument label. */
|
||||
/**
|
||||
* Argument label.
|
||||
*/
|
||||
private String label;
|
||||
/** Argument description. */
|
||||
/**
|
||||
* Argument description.
|
||||
*/
|
||||
private String description;
|
||||
/** Defines whether the argument is optional. */
|
||||
/**
|
||||
* Defines whether the argument is optional.
|
||||
*/
|
||||
private boolean optional = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param label The argument label.
|
||||
* @param label The argument label.
|
||||
* @param description The argument description.
|
||||
*/
|
||||
public CommandArgumentDescription(String label, String description) {
|
||||
@@ -26,9 +32,9 @@ public class CommandArgumentDescription {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param label The argument label.
|
||||
* @param label The argument label.
|
||||
* @param description The argument description.
|
||||
* @param optional True if the argument is optional, false otherwise.
|
||||
* @param optional True if the argument is optional, false otherwise.
|
||||
*/
|
||||
public CommandArgumentDescription(String label, String description, boolean optional) {
|
||||
setLabel(label);
|
||||
|
||||
@@ -1,45 +1,62 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class CommandDescription {
|
||||
|
||||
/** Defines the acceptable labels. */
|
||||
/**
|
||||
* Defines the acceptable labels.
|
||||
*/
|
||||
private List<String> labels = new ArrayList<>();
|
||||
/** Command description. */
|
||||
/**
|
||||
* Command description.
|
||||
*/
|
||||
private String description = "";
|
||||
/** Detailed description. */
|
||||
/**
|
||||
* Detailed description.
|
||||
*/
|
||||
private String detailedDescription = "";
|
||||
/** The executable command instance. */
|
||||
/**
|
||||
* The executable command instance.
|
||||
*/
|
||||
private ExecutableCommand executableCommand;
|
||||
/** The parent command. */
|
||||
/**
|
||||
* The parent command.
|
||||
*/
|
||||
private CommandDescription parent = null;
|
||||
/** The child labels. */
|
||||
/**
|
||||
* The child labels.
|
||||
*/
|
||||
private List<CommandDescription> children = new ArrayList<>();
|
||||
/** The command arguments. */
|
||||
/**
|
||||
* The command arguments.
|
||||
*/
|
||||
private List<CommandArgumentDescription> arguments = new ArrayList<>();
|
||||
/** Defines whether there is an argument maximum or not. */
|
||||
/**
|
||||
* Defines whether there is an argument maximum or not.
|
||||
*/
|
||||
private boolean noArgumentMaximum = false;
|
||||
/** Defines the command permissions. */
|
||||
/**
|
||||
* Defines the command permissions.
|
||||
*/
|
||||
private CommandPermissions permissions = new CommandPermissions();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param executableCommand The executable command, or null.
|
||||
* @param label Command label.
|
||||
* @param description Command description.
|
||||
* @param executableCommand The executable command, or null.
|
||||
* @param label Command label.
|
||||
* @param description Command description.
|
||||
* @param detailedDescription Detailed comment description.
|
||||
* @param parent Parent command.
|
||||
* @param parent Parent command.
|
||||
*/
|
||||
public CommandDescription(ExecutableCommand executableCommand, String label, String description, String detailedDescription, CommandDescription parent) {
|
||||
this(executableCommand, label, description, parent, detailedDescription, null);
|
||||
@@ -48,11 +65,11 @@ public class CommandDescription {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param executableCommand The executable command, or null.
|
||||
* @param labels List of command labels.
|
||||
* @param description Command description.
|
||||
* @param executableCommand The executable command, or null.
|
||||
* @param labels List of command labels.
|
||||
* @param description Command description.
|
||||
* @param detailedDescription Detailed comment description.
|
||||
* @param parent Parent command.
|
||||
* @param parent Parent command.
|
||||
*/
|
||||
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent) {
|
||||
this(executableCommand, labels, description, detailedDescription, parent, null);
|
||||
@@ -61,12 +78,12 @@ public class CommandDescription {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param executableCommand The executable command, or null.
|
||||
* @param label Command label.
|
||||
* @param description Command description.
|
||||
* @param parent Parent command.
|
||||
* @param executableCommand The executable command, or null.
|
||||
* @param label Command label.
|
||||
* @param description Command description.
|
||||
* @param parent Parent command.
|
||||
* @param detailedDescription Detailed comment description.
|
||||
* @param arguments Command arguments.
|
||||
* @param arguments Command arguments.
|
||||
*/
|
||||
public CommandDescription(ExecutableCommand executableCommand, String label, String description, CommandDescription parent, String detailedDescription, List<CommandArgumentDescription> arguments) {
|
||||
setExecutableCommand(executableCommand);
|
||||
@@ -80,12 +97,12 @@ public class CommandDescription {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param executableCommand The executable command, or null.
|
||||
* @param labels List of command labels.
|
||||
* @param description Command description.
|
||||
* @param executableCommand The executable command, or null.
|
||||
* @param labels List of command labels.
|
||||
* @param description Command description.
|
||||
* @param detailedDescription Detailed comment description.
|
||||
* @param parent Parent command.
|
||||
* @param arguments Command arguments.
|
||||
* @param parent Parent command.
|
||||
* @param arguments Command arguments.
|
||||
*/
|
||||
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent, List<CommandArgumentDescription> arguments) {
|
||||
setExecutableCommand(executableCommand);
|
||||
@@ -96,6 +113,69 @@ public class CommandDescription {
|
||||
setArguments(arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a label is valid to use.
|
||||
*
|
||||
* @param label The label to test.
|
||||
*
|
||||
* @return True if the label is valid to use, false otherwise.
|
||||
*/
|
||||
public static boolean isValidLabel(String label) {
|
||||
// Make sure the label isn't null
|
||||
if (label == null)
|
||||
return false;
|
||||
|
||||
// Trim the label
|
||||
label = label.trim();
|
||||
|
||||
// Make sure the label is at least one character long
|
||||
if (label.length() <= 0)
|
||||
return false;
|
||||
|
||||
// Make sure the label doesn't contain any spaces, return the result
|
||||
return !label.contains(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether two labels equal to each other.
|
||||
*
|
||||
* @param commandLabel The first command label.
|
||||
* @param otherCommandLabel The other command label.
|
||||
*
|
||||
* @return True if the labels are equal to each other.
|
||||
*/
|
||||
private static boolean commandLabelEquals(String commandLabel, String otherCommandLabel) {
|
||||
// Trim the command labels from unwanted whitespaces
|
||||
commandLabel = commandLabel.trim();
|
||||
otherCommandLabel = otherCommandLabel.trim();
|
||||
|
||||
// Check whether the the two command labels are equal (case insensitive)
|
||||
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.
|
||||
*
|
||||
@@ -105,11 +185,11 @@ public class CommandDescription {
|
||||
*/
|
||||
public String getLabel(CommandParts reference) {
|
||||
// Ensure there's any item in the command list
|
||||
if(this.labels.size() == 0)
|
||||
if (this.labels.size() == 0)
|
||||
return "";
|
||||
|
||||
// Return the first label if we can't use the reference
|
||||
if(reference == null)
|
||||
if (reference == null)
|
||||
return this.labels.get(0);
|
||||
|
||||
// Get the correct label from the reference
|
||||
@@ -118,9 +198,9 @@ public class CommandDescription {
|
||||
// Check whether the preferred label is in the label list
|
||||
double currentDifference = -1;
|
||||
String currentLabel = this.labels.get(0);
|
||||
for(String entry : this.labels) {
|
||||
for (String entry : this.labels) {
|
||||
double entryDifference = StringUtils.getDifference(entry, preferred);
|
||||
if(entryDifference < currentDifference || currentDifference < 0) {
|
||||
if (entryDifference < currentDifference || currentDifference < 0) {
|
||||
currentDifference = entryDifference;
|
||||
currentLabel = entry;
|
||||
}
|
||||
@@ -153,27 +233,18 @@ public class CommandDescription {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @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. */
|
||||
* @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)
|
||||
if (!overwrite)
|
||||
return addLabel(commandLabel);
|
||||
|
||||
// Replace all labels with this new one
|
||||
@@ -186,15 +257,15 @@ public class CommandDescription {
|
||||
*
|
||||
* @param commandLabel Command label to add.
|
||||
*
|
||||
|
||||
* @return True if the label was added, or if it was added already. False on error. */
|
||||
* @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))
|
||||
if (!isValidLabel(commandLabel))
|
||||
return false;
|
||||
|
||||
// Ensure this command isn't a duplicate
|
||||
if(hasLabel(commandLabel))
|
||||
if (hasLabel(commandLabel))
|
||||
return true;
|
||||
|
||||
// Add the command to the list
|
||||
@@ -206,12 +277,12 @@ public class CommandDescription {
|
||||
*
|
||||
* @param commandLabels List of command labels to add.
|
||||
*
|
||||
|
||||
* @return True if succeed, false on failure. */
|
||||
* @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))
|
||||
for (String cmd : commandLabels)
|
||||
if (!addLabel(cmd))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -221,12 +292,12 @@ public class CommandDescription {
|
||||
*
|
||||
* @param commandLabel Command to check for.
|
||||
*
|
||||
|
||||
* @return True if this command label equals to the param command. */
|
||||
* @return True if this command label equals to the param command.
|
||||
*/
|
||||
public boolean hasLabel(String commandLabel) {
|
||||
// Check whether any command matches with the argument
|
||||
for(String entry : this.labels)
|
||||
if(commandLabelEquals(entry, commandLabel))
|
||||
for (String entry : this.labels)
|
||||
if (commandLabelEquals(entry, commandLabel))
|
||||
return true;
|
||||
|
||||
// No match found, return false
|
||||
@@ -235,13 +306,15 @@ public class CommandDescription {
|
||||
|
||||
/**
|
||||
* Check whether this command description has a list of labels
|
||||
*
|
||||
* @param commandLabels List of labels
|
||||
|
||||
* @return True if all labels match, false otherwise */
|
||||
*
|
||||
* @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))
|
||||
for (String cmd : commandLabels)
|
||||
if (!hasLabel(cmd))
|
||||
return false;
|
||||
|
||||
// There seems to be a match for every command, return true
|
||||
@@ -254,11 +327,11 @@ public class CommandDescription {
|
||||
*
|
||||
* @param commandReference The command reference.
|
||||
*
|
||||
|
||||
* @return True if the command reference is suitable to this command label, false otherwise. */
|
||||
* @return True if the command reference is suitable to this command label, false otherwise.
|
||||
*/
|
||||
public boolean isSuitableLabel(CommandParts commandReference) {
|
||||
// Make sure the command reference is valid
|
||||
if(commandReference.getCount() <= 0)
|
||||
if (commandReference.getCount() <= 0)
|
||||
return false;
|
||||
|
||||
// Get the parent count
|
||||
@@ -268,29 +341,6 @@ public class CommandDescription {
|
||||
return hasLabel(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a label is valid to use.
|
||||
*
|
||||
* @param label The label to test.
|
||||
*
|
||||
|
||||
* @return True if the label is valid to use, false otherwise. */
|
||||
public static boolean isValidLabel(String label) {
|
||||
// Make sure the label isn't null
|
||||
if(label == null)
|
||||
return false;
|
||||
|
||||
// Trim the label
|
||||
label = label.trim();
|
||||
|
||||
// Make sure the label is at least one character long
|
||||
if(label.length() <= 0)
|
||||
return false;
|
||||
|
||||
// Make sure the label doesn't contain any spaces, return the result
|
||||
return !label.contains(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the absolute command label, without a slash.
|
||||
*
|
||||
@@ -304,6 +354,7 @@ public class CommandDescription {
|
||||
* Get the absolute command label.
|
||||
*
|
||||
* @param includeSlash boolean
|
||||
*
|
||||
* @return Absolute command label.
|
||||
*/
|
||||
public String getAbsoluteLabel(boolean includeSlash) {
|
||||
@@ -313,14 +364,15 @@ public class CommandDescription {
|
||||
/**
|
||||
* Get the absolute command label.
|
||||
*
|
||||
* @param includeSlash boolean
|
||||
* @param reference CommandParts
|
||||
* @param includeSlash
|
||||
* @param reference
|
||||
*
|
||||
* @return Absolute command label.
|
||||
*/
|
||||
public String getAbsoluteLabel(boolean includeSlash, CommandParts reference) {
|
||||
// Get the command reference, and make sure it is valid
|
||||
CommandParts out = getCommandReference(reference);
|
||||
if(out == null)
|
||||
if (out == null)
|
||||
return "";
|
||||
|
||||
// Return the result
|
||||
@@ -339,7 +391,7 @@ public class CommandDescription {
|
||||
List<String> referenceList = new ArrayList<>();
|
||||
|
||||
// Check whether this command has a parent, if so, add the absolute parent command
|
||||
if(getParent() != null)
|
||||
if (getParent() != null)
|
||||
referenceList.addAll(getParent().getCommandReference(reference).getList());
|
||||
|
||||
// Get the current label
|
||||
@@ -363,14 +415,14 @@ public class CommandDescription {
|
||||
/**
|
||||
* Get the difference between this command and another command reference.
|
||||
*
|
||||
* @param other The other command reference.
|
||||
* @param other The other command reference.
|
||||
* @param fullCompare True to fully compare both command references.
|
||||
*
|
||||
* @return The command difference. Zero if there's no difference. A negative number on error.
|
||||
*/
|
||||
public double getCommandDifference(CommandParts other, boolean fullCompare) {
|
||||
// Make sure the reference is valid
|
||||
if(other == null)
|
||||
if (other == null)
|
||||
return -1;
|
||||
|
||||
// Get the command reference
|
||||
@@ -410,7 +462,7 @@ public class CommandDescription {
|
||||
/**
|
||||
* Execute the command, if possible.
|
||||
*
|
||||
* @param sender The command sender that triggered the execution of this command.
|
||||
* @param sender The command sender that triggered the execution of this command.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
@@ -418,7 +470,7 @@ public class CommandDescription {
|
||||
*/
|
||||
public boolean execute(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the command is executable
|
||||
if(!isExecutable())
|
||||
if (!isExecutable())
|
||||
return false;
|
||||
|
||||
// Execute the command, return the result
|
||||
@@ -428,8 +480,8 @@ public class CommandDescription {
|
||||
/**
|
||||
* Get the parent command if this command description has a parent.
|
||||
*
|
||||
|
||||
* @return Parent command, or null */
|
||||
* @return Parent command, or null
|
||||
*/
|
||||
public CommandDescription getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
@@ -437,11 +489,11 @@ public class CommandDescription {
|
||||
/**
|
||||
* Get the number of parent this description has.
|
||||
*
|
||||
|
||||
* @return The number of parents. */
|
||||
* @return The number of parents.
|
||||
*/
|
||||
public int getParentCount() {
|
||||
// Check whether the this description has a parent
|
||||
if(!hasParent())
|
||||
if (!hasParent())
|
||||
return 0;
|
||||
|
||||
// Get the parent count of the parent, return the result
|
||||
@@ -453,18 +505,18 @@ public class CommandDescription {
|
||||
*
|
||||
* @param parent Parent command.
|
||||
*
|
||||
|
||||
* @return True on success, false on failure. */
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
public boolean setParent(CommandDescription parent) {
|
||||
// Make sure the parent is different
|
||||
if(this.parent == parent)
|
||||
if (this.parent == parent)
|
||||
return true;
|
||||
|
||||
// Set the parent
|
||||
this.parent = parent;
|
||||
|
||||
// Make sure the parent isn't null
|
||||
if(parent == null)
|
||||
if (parent == null)
|
||||
return true;
|
||||
|
||||
// Add this description as a child to the parent
|
||||
@@ -474,8 +526,8 @@ public class CommandDescription {
|
||||
/**
|
||||
* Check whether the plugin description has a parent command.
|
||||
*
|
||||
|
||||
* @return True if the description has a parent command, false otherwise. */
|
||||
* @return True if the description has a parent command, false otherwise.
|
||||
*/
|
||||
public boolean hasParent() {
|
||||
return this.parent != null;
|
||||
}
|
||||
@@ -483,38 +535,12 @@ public class CommandDescription {
|
||||
/**
|
||||
* Get all command children.
|
||||
*
|
||||
|
||||
* @return Command children. */
|
||||
* @return Command children.
|
||||
*/
|
||||
public List<CommandDescription> getChildren() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a child to the command description.
|
||||
*
|
||||
* @param commandDescription The child to add.
|
||||
*
|
||||
|
||||
* @return True on success, false on failure. */
|
||||
public boolean addChild(CommandDescription commandDescription) {
|
||||
// Make sure the description is valid
|
||||
if(commandDescription == null)
|
||||
return false;
|
||||
if(!commandDescription.isValid())
|
||||
return false;
|
||||
|
||||
// Make sure the child doesn't exist already
|
||||
if(isChild(commandDescription))
|
||||
return true;
|
||||
|
||||
// The command description to add as a child
|
||||
if(!this.children.add(commandDescription))
|
||||
return false;
|
||||
|
||||
// Set this description as parent on the child
|
||||
return commandDescription.setParent(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the children of this command.
|
||||
*
|
||||
@@ -522,19 +548,45 @@ public class CommandDescription {
|
||||
*/
|
||||
public void setChildren(List<CommandDescription> children) {
|
||||
// Check whether the children list should be cleared
|
||||
if(children == null)
|
||||
if (children == null)
|
||||
this.children.clear();
|
||||
|
||||
else
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a child to the command description.
|
||||
*
|
||||
* @param commandDescription The child to add.
|
||||
*
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
public boolean addChild(CommandDescription commandDescription) {
|
||||
// Make sure the description is valid
|
||||
if (commandDescription == null)
|
||||
return false;
|
||||
if (!commandDescription.isValid())
|
||||
return false;
|
||||
|
||||
// Make sure the child doesn't exist already
|
||||
if (isChild(commandDescription))
|
||||
return true;
|
||||
|
||||
// The command description to add as a child
|
||||
if (!this.children.add(commandDescription))
|
||||
return false;
|
||||
|
||||
// Set this description as parent on the child
|
||||
return commandDescription.setParent(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this command has any child labels.
|
||||
*
|
||||
|
||||
* @return True if this command has any child labels. */
|
||||
public boolean hasChilds() {
|
||||
* @return True if this command has any child labels.
|
||||
*/
|
||||
public boolean hasChildren() {
|
||||
return (this.children.size() != 0);
|
||||
}
|
||||
|
||||
@@ -543,13 +595,13 @@ public class CommandDescription {
|
||||
*
|
||||
* @param commandDescription The command description to check for.
|
||||
*
|
||||
|
||||
* @return True if this command description has the specific child, false otherwise. */
|
||||
* @return True if this command description has the specific child, false otherwise.
|
||||
*/
|
||||
public boolean isChild(CommandDescription commandDescription) {
|
||||
// Make sure the description is valid
|
||||
if(commandDescription == null)
|
||||
if (commandDescription == null)
|
||||
return false;
|
||||
if(!commandDescription.isValid())
|
||||
if (!commandDescription.isValid())
|
||||
return false;
|
||||
|
||||
// Check whether this child exists, return the result
|
||||
@@ -561,15 +613,15 @@ public class CommandDescription {
|
||||
*
|
||||
* @param argument The argument to add.
|
||||
*
|
||||
|
||||
* @return True if succeed, false if failed. */
|
||||
* @return True if succeed, false if failed.
|
||||
*/
|
||||
public boolean addArgument(CommandArgumentDescription argument) {
|
||||
// Make sure the argument is valid
|
||||
if(argument == null)
|
||||
if (argument == null)
|
||||
return false;
|
||||
|
||||
// Make sure the argument isn't added already
|
||||
if(hasArgument(argument))
|
||||
if (hasArgument(argument))
|
||||
return true;
|
||||
|
||||
// Add the argument, return the result
|
||||
@@ -630,9 +682,9 @@ public class CommandDescription {
|
||||
int optionalArgument = 0;
|
||||
|
||||
// Loop through each argument
|
||||
for(CommandArgumentDescription argument : this.arguments) {
|
||||
for (CommandArgumentDescription argument : this.arguments) {
|
||||
// Check whether the command is optional
|
||||
if(!argument.isOptional()) {
|
||||
if (!argument.isOptional()) {
|
||||
requiredArguments += optionalArgument + 1;
|
||||
optionalArgument = 0;
|
||||
|
||||
@@ -647,11 +699,11 @@ public class CommandDescription {
|
||||
/**
|
||||
* Get the maximum number of arguments.
|
||||
*
|
||||
|
||||
* @return The maximum number of arguments. A negative number will be returned if there's no maximum. */
|
||||
* @return The maximum number of arguments. A negative number will be returned if there's no maximum.
|
||||
*/
|
||||
public int getMaximumArguments() {
|
||||
// Check whether there is a maximum set
|
||||
if(this.noArgumentMaximum)
|
||||
if (this.noArgumentMaximum)
|
||||
return -1;
|
||||
|
||||
// Return the maximum based on the registered arguments
|
||||
@@ -671,8 +723,8 @@ public class CommandDescription {
|
||||
/**
|
||||
* Get the command description.
|
||||
*
|
||||
|
||||
* @return Command description. */
|
||||
* @return Command description.
|
||||
*/
|
||||
public String getDescription() {
|
||||
return hasDescription() ? this.description : this.detailedDescription;
|
||||
}
|
||||
@@ -683,7 +735,7 @@ public class CommandDescription {
|
||||
* @param description New command description. Null to reset the description.
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
if(description == null)
|
||||
if (description == null)
|
||||
this.description = "";
|
||||
|
||||
else
|
||||
@@ -693,8 +745,8 @@ public class CommandDescription {
|
||||
/**
|
||||
* 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() {
|
||||
return (this.description.trim().length() != 0);
|
||||
}
|
||||
@@ -702,8 +754,8 @@ public class CommandDescription {
|
||||
/**
|
||||
* Get the command detailed description.
|
||||
*
|
||||
|
||||
* @return Command detailed description. */
|
||||
* @return Command detailed description.
|
||||
*/
|
||||
public String getDetailedDescription() {
|
||||
return hasDetailedDescription() ? this.detailedDescription : this.description;
|
||||
}
|
||||
@@ -714,7 +766,7 @@ public class CommandDescription {
|
||||
* @param detailedDescription New command description. Null to reset the description.
|
||||
*/
|
||||
public void setDetailedDescription(String detailedDescription) {
|
||||
if(detailedDescription == null)
|
||||
if (detailedDescription == null)
|
||||
this.detailedDescription = "";
|
||||
|
||||
else
|
||||
@@ -724,8 +776,8 @@ public class CommandDescription {
|
||||
/**
|
||||
* Check whether this command has any detailed description.
|
||||
*
|
||||
|
||||
* @return True if this command has any detailed description. */
|
||||
* @return True if this command has any detailed description.
|
||||
*/
|
||||
public boolean hasDetailedDescription() {
|
||||
return (this.detailedDescription.trim().length() != 0);
|
||||
}
|
||||
@@ -735,35 +787,35 @@ public class CommandDescription {
|
||||
*
|
||||
* @param queryReference The query reference to find a command for.
|
||||
*
|
||||
|
||||
* @return The command found, or null. */
|
||||
* @return The command found, or null.
|
||||
*/
|
||||
public FoundCommandResult findCommand(final CommandParts queryReference) {
|
||||
// Make sure the command reference is valid
|
||||
if(queryReference.getCount() <= 0)
|
||||
if (queryReference.getCount() <= 0)
|
||||
return null;
|
||||
|
||||
// Check whether this description is for the last element in the command reference, if so return the current command
|
||||
if(queryReference.getCount() <= getParentCount() + 1)
|
||||
if (queryReference.getCount() <= getParentCount() + 1)
|
||||
return new FoundCommandResult(
|
||||
this,
|
||||
getCommandReference(queryReference),
|
||||
new CommandParts(),
|
||||
queryReference);
|
||||
this,
|
||||
getCommandReference(queryReference),
|
||||
new CommandParts(),
|
||||
queryReference);
|
||||
|
||||
// Get the new command reference and arguments
|
||||
CommandParts newReference = new CommandParts(queryReference.getRange(0, getParentCount() + 1));
|
||||
CommandParts newArguments = new CommandParts(queryReference.getRange(getParentCount() + 1));
|
||||
|
||||
// Handle the child's, if this command has any
|
||||
if(getChildren().size() > 0) {
|
||||
if (getChildren().size() > 0) {
|
||||
// Get a new instance of the child's list, and sort them by their difference in comparison to the query reference
|
||||
List<CommandDescription> commandChildren = new ArrayList<>(getChildren());
|
||||
Collections.sort(commandChildren, new Comparator<CommandDescription>() {
|
||||
@Override
|
||||
public int compare(CommandDescription o1, CommandDescription o2) {
|
||||
return Double.compare(
|
||||
o1.getCommandDifference(queryReference),
|
||||
o2.getCommandDifference(queryReference));
|
||||
o1.getCommandDifference(queryReference),
|
||||
o2.getCommandDifference(queryReference));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -771,21 +823,21 @@ public class CommandDescription {
|
||||
double firstChildDifference = commandChildren.get(0).getCommandDifference(queryReference, true);
|
||||
|
||||
// Check if the reference perfectly suits the arguments of the current command if it doesn't perfectly suits a child command
|
||||
if(firstChildDifference > 0.0)
|
||||
if(getSuitableArgumentsDifference(queryReference) == 0)
|
||||
if (firstChildDifference > 0.0)
|
||||
if (getSuitableArgumentsDifference(queryReference) == 0)
|
||||
return new FoundCommandResult(this, newReference, newArguments, queryReference);
|
||||
|
||||
// Loop through each child
|
||||
for(CommandDescription child : commandChildren) {
|
||||
for (CommandDescription child : commandChildren) {
|
||||
// Get the best suitable command
|
||||
FoundCommandResult result = child.findCommand(queryReference);
|
||||
if(result != null)
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the remaining command reference elements fit the arguments for this command
|
||||
if(getSuitableArgumentsDifference(queryReference) >= 0)
|
||||
if (getSuitableArgumentsDifference(queryReference) >= 0)
|
||||
return new FoundCommandResult(this, newReference, newArguments, queryReference);
|
||||
|
||||
// No command found, return null
|
||||
@@ -797,8 +849,8 @@ public class CommandDescription {
|
||||
*
|
||||
* @param commandReference The command reference.
|
||||
*
|
||||
|
||||
* @return True if so, false otherwise. */
|
||||
* @return True if so, false otherwise.
|
||||
*/
|
||||
public boolean hasSuitableCommand(CommandParts commandReference) {
|
||||
return findCommand(commandReference) != null;
|
||||
}
|
||||
@@ -808,8 +860,8 @@ public class CommandDescription {
|
||||
*
|
||||
* @param commandReference The command reference.
|
||||
*
|
||||
|
||||
* @return True if the arguments are suitable, false otherwise. */
|
||||
* @return True if the arguments are suitable, false otherwise.
|
||||
*/
|
||||
public boolean hasSuitableArguments(CommandParts commandReference) {
|
||||
return getSuitableArgumentsDifference(commandReference) == 0;
|
||||
}
|
||||
@@ -866,27 +918,13 @@ public class CommandDescription {
|
||||
/**
|
||||
* Set the command permissions.
|
||||
*
|
||||
* @param permissionNode The permission node required.
|
||||
* @param permissionNode The permission node required.
|
||||
* @param defaultPermission The default permission.
|
||||
*/
|
||||
public void setCommandPermissions(String permissionNode, CommandPermissions.DefaultPermission defaultPermission) {
|
||||
this.permissions = new CommandPermissions(permissionNode, defaultPermission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether two labels equal to each other.
|
||||
*
|
||||
* @param commandLabel The first command label.
|
||||
* @param otherCommandLabel The other command label.
|
||||
*
|
||||
* @return True if the labels are equal to each other.
|
||||
*/
|
||||
private static boolean commandLabelEquals(String commandLabel, String otherCommandLabel) {
|
||||
commandLabel = commandLabel.trim();
|
||||
otherCommandLabel = otherCommandLabel.trim();
|
||||
return commandLabel.equalsIgnoreCase(otherCommandLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the command description has been set up properly.
|
||||
*
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class CommandHandler {
|
||||
|
||||
/** The command manager instance. */
|
||||
/**
|
||||
* The command manager instance.
|
||||
*/
|
||||
private CommandManager commandManager;
|
||||
|
||||
/**
|
||||
@@ -24,19 +25,19 @@ public class CommandHandler {
|
||||
*/
|
||||
public CommandHandler(boolean init) {
|
||||
// Initialize
|
||||
if(init)
|
||||
if (init)
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the command handler.
|
||||
*
|
||||
|
||||
* @return True if succeed, false on failure. True will also be returned if the command handler was already
|
||||
* initialized. */
|
||||
* initialized.
|
||||
*/
|
||||
public boolean init() {
|
||||
// Make sure the handler isn't initialized already
|
||||
if(isInit())
|
||||
if (isInit())
|
||||
return true;
|
||||
|
||||
// Initialize the command manager
|
||||
@@ -50,8 +51,8 @@ public class CommandHandler {
|
||||
/**
|
||||
* Check whether the command handler is initialized.
|
||||
*
|
||||
|
||||
* @return True if the command handler is initialized. */
|
||||
* @return True if the command handler is initialized.
|
||||
*/
|
||||
public boolean isInit() {
|
||||
return this.commandManager != null;
|
||||
}
|
||||
@@ -59,12 +60,12 @@ public class CommandHandler {
|
||||
/**
|
||||
* Destroy the command handler.
|
||||
*
|
||||
|
||||
* @return True if the command handler was destroyed successfully, false otherwise. True will also be returned if
|
||||
* the command handler wasn't initialized. */
|
||||
* the command handler wasn't initialized.
|
||||
*/
|
||||
public boolean destroy() {
|
||||
// Make sure the command handler is initialized
|
||||
if(!isInit())
|
||||
if (!isInit())
|
||||
return true;
|
||||
|
||||
// Unset the command manager
|
||||
@@ -75,8 +76,8 @@ public class CommandHandler {
|
||||
/**
|
||||
* Get the command manager.
|
||||
*
|
||||
|
||||
* @return Command manager instance. */
|
||||
* @return Command manager instance.
|
||||
*/
|
||||
public CommandManager getCommandManager() {
|
||||
return this.commandManager;
|
||||
}
|
||||
@@ -84,26 +85,26 @@ public class CommandHandler {
|
||||
/**
|
||||
* Process a command.
|
||||
*
|
||||
* @param sender The command sender (Bukkit).
|
||||
* @param bukkitCommand The command (Bukkit).
|
||||
* @param sender The command sender (Bukkit).
|
||||
* @param bukkitCommand The command (Bukkit).
|
||||
* @param bukkitCommandLabel The command label (Bukkit).
|
||||
* @param bukkitArgs The command arguments (Bukkit).
|
||||
* @param bukkitArgs The command arguments (Bukkit).
|
||||
*
|
||||
|
||||
* @return True if the command was executed, false otherwise. */
|
||||
* @return True if the command was executed, false otherwise.
|
||||
*/
|
||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command bukkitCommand, String bukkitCommandLabel, String[] bukkitArgs) {
|
||||
// Process the arguments
|
||||
List<String> args = processArguments(bukkitArgs);
|
||||
|
||||
// Create a command reference, and make sure at least one command part is available
|
||||
CommandParts commandReference = new CommandParts(bukkitCommandLabel, args);
|
||||
if(commandReference.getCount() == 0)
|
||||
if (commandReference.getCount() == 0)
|
||||
return false;
|
||||
|
||||
// Get a suitable command for this reference, and make sure it isn't null
|
||||
FoundCommandResult result = this.commandManager.findCommand(commandReference);
|
||||
if(result == null) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Failed to parse " + AuthMe.PLUGIN_NAME + " command!");
|
||||
if (result == null) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Failed to parse " + AuthMe.getPluginName() + " command!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -112,13 +113,13 @@ public class CommandHandler {
|
||||
|
||||
// Make sure the difference between the command reference and the actual command isn't too big
|
||||
final double commandDifference = result.getDifference();
|
||||
if(commandDifference > 0.12) {
|
||||
if (commandDifference > 0.12) {
|
||||
// Show the unknown command warning
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Unknown command!");
|
||||
|
||||
// Show a command suggestion if available and the difference isn't too big
|
||||
if(commandDifference < 0.75)
|
||||
if(result.getCommandDescription() != null)
|
||||
if (commandDifference < 0.75)
|
||||
if (result.getCommandDescription() != null)
|
||||
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + result.getCommandDescription().getCommandReference(commandReference) + ChatColor.YELLOW + "?");
|
||||
|
||||
// Show the help command
|
||||
@@ -127,17 +128,17 @@ public class CommandHandler {
|
||||
}
|
||||
|
||||
// Show a message when the command handler is assuming a command
|
||||
if(commandDifference > 0) {
|
||||
if (commandDifference > 0) {
|
||||
// Get the suggested command
|
||||
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference));
|
||||
|
||||
// Show the suggested command
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Unknown command, assuming " + ChatColor.GOLD + "/" + suggestedCommandParts +
|
||||
ChatColor.DARK_RED + "!");
|
||||
ChatColor.DARK_RED + "!");
|
||||
}
|
||||
|
||||
// Make sure the command is executable
|
||||
if(!result.isExecutable()) {
|
||||
if (!result.isExecutable()) {
|
||||
// Get the command reference
|
||||
CommandParts helpCommandReference = new CommandParts(result.getCommandReference().getRange(1));
|
||||
|
||||
@@ -150,14 +151,14 @@ public class CommandHandler {
|
||||
}
|
||||
|
||||
// Make sure the command sender has permission
|
||||
if(!result.hasPermission(sender)) {
|
||||
if (!result.hasPermission(sender)) {
|
||||
// Show the no permissions warning
|
||||
sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to use this command!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Make sure the command sender has permission
|
||||
if(!result.hasProperArguments()) {
|
||||
if (!result.hasProperArguments()) {
|
||||
// Get the command and the suggested command reference
|
||||
CommandParts suggestedCommandReference = new CommandParts(result.getCommandDescription().getCommandReference(commandReference));
|
||||
CommandParts helpCommandReference = new CommandParts(suggestedCommandReference.getRange(1));
|
||||
@@ -182,19 +183,19 @@ public class CommandHandler {
|
||||
*
|
||||
* @param args The command arguments to process.
|
||||
*
|
||||
|
||||
* @return The processed command arguments. */
|
||||
* @return The processed command arguments.
|
||||
*/
|
||||
private List<String> processArguments(String[] args) {
|
||||
// Convert the array into a list of arguments
|
||||
List<String> arguments = new ArrayList<>(Arrays.asList(args));
|
||||
|
||||
/// Remove all empty arguments
|
||||
for(int i = 0; i < arguments.size(); i++) {
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
// Get the argument value
|
||||
final String arg = arguments.get(i);
|
||||
|
||||
// Check whether the argument value is empty
|
||||
if(arg.trim().length() == 0) {
|
||||
if (arg.trim().length() == 0) {
|
||||
// Remove the current argument
|
||||
arguments.remove(i);
|
||||
|
||||
|
||||
@@ -1,29 +1,7 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.xephi.authme.command.executable.HelpCommand;
|
||||
import fr.xephi.authme.command.executable.authme.AccountsCommand;
|
||||
import fr.xephi.authme.command.executable.authme.AuthMeCommand;
|
||||
import fr.xephi.authme.command.executable.authme.ChangePasswordCommand;
|
||||
import fr.xephi.authme.command.executable.authme.FirstSpawnCommand;
|
||||
import fr.xephi.authme.command.executable.authme.ForceLoginCommand;
|
||||
import fr.xephi.authme.command.executable.authme.GetEmailCommand;
|
||||
import fr.xephi.authme.command.executable.authme.GetIpCommand;
|
||||
import fr.xephi.authme.command.executable.authme.LastLoginCommand;
|
||||
import fr.xephi.authme.command.executable.authme.PurgeBannedPlayersCommand;
|
||||
import fr.xephi.authme.command.executable.authme.PurgeCommand;
|
||||
import fr.xephi.authme.command.executable.authme.PurgeLastPositionCommand;
|
||||
import fr.xephi.authme.command.executable.authme.RegisterCommand;
|
||||
import fr.xephi.authme.command.executable.authme.ReloadCommand;
|
||||
import fr.xephi.authme.command.executable.authme.SetEmailCommand;
|
||||
import fr.xephi.authme.command.executable.authme.SetFirstSpawnCommand;
|
||||
import fr.xephi.authme.command.executable.authme.SetSpawnCommand;
|
||||
import fr.xephi.authme.command.executable.authme.SpawnCommand;
|
||||
import fr.xephi.authme.command.executable.authme.SwitchAntiBotCommand;
|
||||
import fr.xephi.authme.command.executable.authme.UnregisterCommand;
|
||||
import fr.xephi.authme.command.executable.authme.VersionCommand;
|
||||
import fr.xephi.authme.command.executable.authme.*;
|
||||
import fr.xephi.authme.command.executable.captcha.CaptchaCommand;
|
||||
import fr.xephi.authme.command.executable.converter.ConverterCommand;
|
||||
import fr.xephi.authme.command.executable.email.AddEmailCommand;
|
||||
@@ -32,18 +10,22 @@ import fr.xephi.authme.command.executable.email.RecoverEmailCommand;
|
||||
import fr.xephi.authme.command.executable.login.LoginCommand;
|
||||
import fr.xephi.authme.command.executable.logout.LogoutCommand;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class CommandManager {
|
||||
|
||||
/** The list of commandDescriptions. */
|
||||
private List<CommandDescription> commandDescriptions = new ArrayList<>();
|
||||
/**
|
||||
* The list of commandDescriptions.
|
||||
*/
|
||||
private final List<CommandDescription> commandDescriptions = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param registerCommands
|
||||
* True to register the commands, false otherwise.
|
||||
* @param registerCommands True to register the commands, false otherwise.
|
||||
*/
|
||||
public CommandManager(boolean registerCommands) {
|
||||
// Register the commands
|
||||
@@ -55,7 +37,7 @@ public class CommandManager {
|
||||
* Register all commands.
|
||||
*/
|
||||
// TODO ljacqu 20151121: Create a builder class for CommandDescription
|
||||
@SuppressWarnings({ "serial" })
|
||||
@SuppressWarnings({"serial"})
|
||||
public void registerCommands() {
|
||||
// Register the base AuthMe Reloaded command
|
||||
CommandDescription authMeBaseCommand = new CommandDescription(new AuthMeCommand(), new ArrayList<String>() {
|
||||
@@ -574,8 +556,8 @@ public class CommandManager {
|
||||
/**
|
||||
* Get the list of command descriptions
|
||||
*
|
||||
|
||||
* @return List of command descriptions. */
|
||||
* @return List of command descriptions.
|
||||
*/
|
||||
public List<CommandDescription> getCommandDescriptions() {
|
||||
return this.commandDescriptions;
|
||||
}
|
||||
@@ -583,8 +565,8 @@ public class CommandManager {
|
||||
/**
|
||||
* Get the number of command description count.
|
||||
*
|
||||
|
||||
* @return Command description count. */
|
||||
* @return Command description count.
|
||||
*/
|
||||
public int getCommandDescriptionCount() {
|
||||
return this.getCommandDescriptions().size();
|
||||
}
|
||||
@@ -592,11 +574,10 @@ public class CommandManager {
|
||||
/**
|
||||
* Find the best suitable command for the specified reference.
|
||||
*
|
||||
* @param queryReference
|
||||
* The query reference to find a command for.
|
||||
* @param queryReference The query reference to find a command for.
|
||||
*
|
||||
|
||||
* @return The command found, or null. */
|
||||
* @return The command found, or null.
|
||||
*/
|
||||
public FoundCommandResult findCommand(CommandParts queryReference) {
|
||||
// Make sure the command reference is valid
|
||||
if (queryReference.getCount() <= 0)
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class CommandParts {
|
||||
|
||||
/** The list of parts for this command. */
|
||||
private List<String> parts = new ArrayList<>();
|
||||
/**
|
||||
* The list of parts for this command.
|
||||
*/
|
||||
private final List<String> parts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public CommandParts() { }
|
||||
public CommandParts() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -47,7 +50,7 @@ public class CommandParts {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param base The base part.
|
||||
* @param base The base part.
|
||||
* @param parts The list of additional parts.
|
||||
*/
|
||||
public CommandParts(String base, List<String> parts) {
|
||||
@@ -58,8 +61,8 @@ public class CommandParts {
|
||||
/**
|
||||
* Get the command parts.
|
||||
*
|
||||
|
||||
* @return Command parts. */
|
||||
* @return Command parts.
|
||||
*/
|
||||
public List<String> getList() {
|
||||
return this.parts;
|
||||
}
|
||||
@@ -69,8 +72,8 @@ public class CommandParts {
|
||||
*
|
||||
* @param part The part to add.
|
||||
*
|
||||
|
||||
* @return The result. */
|
||||
* @return The result.
|
||||
*/
|
||||
public boolean add(String part) {
|
||||
return this.parts.add(part);
|
||||
}
|
||||
@@ -80,8 +83,8 @@ public class CommandParts {
|
||||
*
|
||||
* @param parts The parts to add.
|
||||
*
|
||||
|
||||
* @return The result. */
|
||||
* @return The result.
|
||||
*/
|
||||
public boolean add(List<String> parts) {
|
||||
return this.parts.addAll(parts);
|
||||
}
|
||||
@@ -91,10 +94,10 @@ public class CommandParts {
|
||||
*
|
||||
* @param parts The parts to add.
|
||||
*
|
||||
|
||||
* @return The result. */
|
||||
* @return The result.
|
||||
*/
|
||||
public boolean add(String[] parts) {
|
||||
for(String entry : parts)
|
||||
for (String entry : parts)
|
||||
add(entry);
|
||||
return true;
|
||||
}
|
||||
@@ -102,8 +105,8 @@ public class CommandParts {
|
||||
/**
|
||||
* Get the number of parts.
|
||||
*
|
||||
|
||||
* @return Part count. */
|
||||
* @return Part count.
|
||||
*/
|
||||
public int getCount() {
|
||||
return this.parts.size();
|
||||
}
|
||||
@@ -113,11 +116,11 @@ public class CommandParts {
|
||||
*
|
||||
* @param i Part index.
|
||||
*
|
||||
|
||||
* @return The part. */
|
||||
* @return The part.
|
||||
*/
|
||||
public String get(int i) {
|
||||
// Make sure the index is in-bound
|
||||
if(i < 0 || i >= getCount())
|
||||
if (i < 0 || i >= getCount())
|
||||
return null;
|
||||
|
||||
// Get and return the argument
|
||||
@@ -129,8 +132,8 @@ public class CommandParts {
|
||||
*
|
||||
* @param start The starting index.
|
||||
*
|
||||
|
||||
* @return The parts range. Arguments that were out of bound are not included. */
|
||||
* @return The parts range. Arguments that were out of bound are not included.
|
||||
*/
|
||||
public List<String> getRange(int start) {
|
||||
return getRange(start, getCount() - start);
|
||||
}
|
||||
@@ -141,17 +144,17 @@ public class CommandParts {
|
||||
* @param start The starting index.
|
||||
* @param count The number of parts to get.
|
||||
*
|
||||
|
||||
* @return The parts range. Parts that were out of bound are not included. */
|
||||
* @return The parts range. Parts that were out of bound are not included.
|
||||
*/
|
||||
public List<String> getRange(int start, int count) {
|
||||
// Create a new list to put the range into
|
||||
List<String> elements = new ArrayList<>();
|
||||
|
||||
// Get the range
|
||||
for(int i = start; i < start + count; i++) {
|
||||
for (int i = start; i < start + count; i++) {
|
||||
// Get the part and add it if it's valid
|
||||
String element = get(i);
|
||||
if(element != null)
|
||||
if (element != null)
|
||||
elements.add(element);
|
||||
}
|
||||
|
||||
@@ -173,21 +176,21 @@ public class CommandParts {
|
||||
/**
|
||||
* Get the difference value between two references.
|
||||
*
|
||||
* @param other The other reference.
|
||||
* @param other The other reference.
|
||||
* @param fullCompare True to compare the full references as far as the range reaches.
|
||||
*
|
||||
* @return The result from zero to above. A negative number will be returned on error.
|
||||
*/
|
||||
public double getDifference(CommandParts other, boolean fullCompare) {
|
||||
// Make sure the other reference is correct
|
||||
if(other == null)
|
||||
if (other == null)
|
||||
return -1;
|
||||
|
||||
// Get the range to use
|
||||
int range = Math.min(this.getCount(), other.getCount());
|
||||
|
||||
// Get and the difference
|
||||
if(fullCompare)
|
||||
if (fullCompare)
|
||||
return StringUtils.getDifference(this.toString(), other.toString());
|
||||
return StringUtils.getDifference(this.getRange(range - 1, 1).toString(), other.getRange(range - 1, 1).toString());
|
||||
}
|
||||
|
||||
@@ -1,34 +1,39 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//import com.timvisee.dungeonmaze.Core;
|
||||
//import com.timvisee.dungeonmaze.permission.PermissionsManager;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
|
||||
/**
|
||||
*/
|
||||
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<String> permissionNodes = new ArrayList<>();
|
||||
/** 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;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public CommandPermissions() { }
|
||||
public CommandPermissions() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param permissionNode The permission node required to execute a command.
|
||||
* @param permissionNode The permission node required to execute a command.
|
||||
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
||||
*/
|
||||
public CommandPermissions(String permissionNode, DefaultPermission defaultPermission) {
|
||||
@@ -39,7 +44,7 @@ public class CommandPermissions {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param permissionNodes The permission nodes required to execute a command.
|
||||
* @param permissionNodes The permission nodes required to execute a command.
|
||||
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
||||
*/
|
||||
public CommandPermissions(List<String> permissionNodes, DefaultPermission defaultPermission) {
|
||||
@@ -51,18 +56,18 @@ public class CommandPermissions {
|
||||
*
|
||||
* @param permissionNode The permission node to add.
|
||||
*
|
||||
|
||||
* @return True on success, false on failure. */
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
public boolean addPermissionNode(String permissionNode) {
|
||||
// Trim the permission node
|
||||
permissionNode = permissionNode.trim();
|
||||
|
||||
// Make sure the permission node is valid
|
||||
if(permissionNode.length() == 0)
|
||||
if (permissionNode.length() == 0)
|
||||
return false;
|
||||
|
||||
// Make sure this permission node hasn't been added already
|
||||
if(hasPermissionNode(permissionNode))
|
||||
if (hasPermissionNode(permissionNode))
|
||||
return true;
|
||||
|
||||
// Add the permission node, return the result
|
||||
@@ -74,8 +79,8 @@ public class CommandPermissions {
|
||||
*
|
||||
* @param permissionNode The permission node to check for.
|
||||
*
|
||||
|
||||
* @return True if this permission node is required, false if not. */
|
||||
* @return True if this permission node is required, false if not.
|
||||
*/
|
||||
public boolean hasPermissionNode(String permissionNode) {
|
||||
return this.permissionNodes.contains(permissionNode);
|
||||
}
|
||||
@@ -83,21 +88,12 @@ public class CommandPermissions {
|
||||
/**
|
||||
* Get the permission nodes required to execute this command.
|
||||
*
|
||||
|
||||
* @return The permission nodes required to execute this command. */
|
||||
* @return The permission nodes required to execute this command.
|
||||
*/
|
||||
public List<String> getPermissionNodes() {
|
||||
return this.permissionNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of permission nodes set.
|
||||
*
|
||||
|
||||
* @return Permission node count. */
|
||||
public int getPermissionNodeCount() {
|
||||
return this.permissionNodes.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the permission nodes required to execute this command.
|
||||
*
|
||||
@@ -107,22 +103,32 @@ public class CommandPermissions {
|
||||
this.permissionNodes = permissionNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of permission nodes set.
|
||||
*
|
||||
* @return Permission node count.
|
||||
*/
|
||||
public int getPermissionNodeCount() {
|
||||
return this.permissionNodes.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this command requires any permission to be executed. This is based on the getPermission() method.
|
||||
*
|
||||
|
||||
* @param sender CommandSender
|
||||
* @return True if this command requires any permission to be executed by a player. */
|
||||
*
|
||||
* @return True if this command requires any permission to be executed by a player.
|
||||
*/
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
// Make sure any permission node is set
|
||||
if(getPermissionNodeCount() == 0)
|
||||
if (getPermissionNodeCount() == 0)
|
||||
return true;
|
||||
|
||||
// Get the default permission
|
||||
final boolean defaultPermission = getDefaultPermissionCommandSender(sender);
|
||||
|
||||
// Make sure the command sender is a player, if not use the default
|
||||
if(!(sender instanceof Player))
|
||||
if (!(sender instanceof Player))
|
||||
return defaultPermission;
|
||||
|
||||
// Get the player instance
|
||||
@@ -130,12 +136,12 @@ public class CommandPermissions {
|
||||
|
||||
// Get the permissions manager, and make sure it's instance is valid
|
||||
PermissionsManager permissionsManager = AuthMe.getInstance().getPermissionsManager();
|
||||
if(permissionsManager == null)
|
||||
if (permissionsManager == null)
|
||||
return false;
|
||||
|
||||
// Check whether the player has permission, return the result
|
||||
for(String node : this.permissionNodes)
|
||||
if(!permissionsManager.hasPermission(player, node, defaultPermission))
|
||||
for (String node : this.permissionNodes)
|
||||
if (!permissionsManager.hasPermission(player, node, defaultPermission))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -143,8 +149,8 @@ public class CommandPermissions {
|
||||
/**
|
||||
* Get the default permission if the permission nodes couldn't be used.
|
||||
*
|
||||
|
||||
* @return The default permission. */
|
||||
* @return The default permission.
|
||||
*/
|
||||
public DefaultPermission getDefaultPermission() {
|
||||
return this.defaultPermission;
|
||||
}
|
||||
@@ -163,19 +169,19 @@ public class CommandPermissions {
|
||||
*
|
||||
* @param sender The command sender to get the default permission for.
|
||||
*
|
||||
|
||||
* @return True if the command sender has permission by default, false otherwise. */
|
||||
* @return True if the command sender has permission by default, false otherwise.
|
||||
*/
|
||||
public boolean getDefaultPermissionCommandSender(CommandSender sender) {
|
||||
switch(getDefaultPermission()) {
|
||||
case ALLOWED:
|
||||
return true;
|
||||
switch (getDefaultPermission()) {
|
||||
case ALLOWED:
|
||||
return true;
|
||||
|
||||
case OP_ONLY:
|
||||
return sender.isOp();
|
||||
case OP_ONLY:
|
||||
return sender.isOp();
|
||||
|
||||
case NOT_ALLOWED:
|
||||
default:
|
||||
return false;
|
||||
case NOT_ALLOWED:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ public abstract class ExecutableCommand {
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
@@ -6,22 +6,30 @@ import org.bukkit.command.CommandSender;
|
||||
*/
|
||||
public class FoundCommandResult {
|
||||
|
||||
/** The command description instance. */
|
||||
/**
|
||||
* The command description instance.
|
||||
*/
|
||||
private CommandDescription commandDescription;
|
||||
/** The command reference. */
|
||||
private CommandParts commandReference;
|
||||
/** The command arguments. */
|
||||
private CommandParts commandArguments;
|
||||
/** The original search query reference. */
|
||||
private CommandParts queryReference;
|
||||
/**
|
||||
* The command reference.
|
||||
*/
|
||||
private final CommandParts commandReference;
|
||||
/**
|
||||
* The command arguments.
|
||||
*/
|
||||
private final CommandParts commandArguments;
|
||||
/**
|
||||
* The original search query reference.
|
||||
*/
|
||||
private final CommandParts queryReference;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param commandDescription The command description.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
* @param queryReference The original query reference.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
* @param queryReference The original query reference.
|
||||
*/
|
||||
public FoundCommandResult(CommandDescription commandDescription, CommandParts commandReference, CommandParts commandArguments, CommandParts queryReference) {
|
||||
this.commandDescription = commandDescription;
|
||||
@@ -33,11 +41,11 @@ public class FoundCommandResult {
|
||||
/**
|
||||
* Check whether the command was suitable.
|
||||
*
|
||||
|
||||
* @return True if the command was suitable, false otherwise. */
|
||||
* @return True if the command was suitable, false otherwise.
|
||||
*/
|
||||
public boolean hasProperArguments() {
|
||||
// Make sure the command description is set
|
||||
if(this.commandDescription == null)
|
||||
if (this.commandDescription == null)
|
||||
return false;
|
||||
|
||||
// Get and return the result
|
||||
@@ -47,8 +55,8 @@ public class FoundCommandResult {
|
||||
/**
|
||||
* Get the command description.
|
||||
*
|
||||
|
||||
* @return Command description. */
|
||||
* @return Command description.
|
||||
*/
|
||||
public CommandDescription getCommandDescription() {
|
||||
return this.commandDescription;
|
||||
}
|
||||
@@ -57,7 +65,6 @@ public class FoundCommandResult {
|
||||
* Set the command description.
|
||||
*
|
||||
* @param commandDescription The command description.
|
||||
*
|
||||
*/
|
||||
public void setCommandDescription(CommandDescription commandDescription) {
|
||||
this.commandDescription = commandDescription;
|
||||
@@ -66,11 +73,11 @@ public class FoundCommandResult {
|
||||
/**
|
||||
* Check whether the command is executable.
|
||||
*
|
||||
|
||||
* @return True if the command is executable, false otherwise. */
|
||||
* @return True if the command is executable, false otherwise.
|
||||
*/
|
||||
public boolean isExecutable() {
|
||||
// Make sure the command description is valid
|
||||
if(this.commandDescription == null)
|
||||
if (this.commandDescription == null)
|
||||
return false;
|
||||
|
||||
// Check whether the command is executable, return the result
|
||||
@@ -82,11 +89,11 @@ public class FoundCommandResult {
|
||||
*
|
||||
* @param sender The command sender that executed the command.
|
||||
*
|
||||
|
||||
* @return True on success, false on failure. */
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
public boolean executeCommand(CommandSender sender) {
|
||||
// Make sure the command description is valid
|
||||
if(this.commandDescription == null)
|
||||
if (this.commandDescription == null)
|
||||
return false;
|
||||
|
||||
// Execute the command
|
||||
@@ -98,11 +105,11 @@ public class FoundCommandResult {
|
||||
*
|
||||
* @param sender The command sender.
|
||||
*
|
||||
|
||||
* @return True if the command sender has permission, false otherwise. */
|
||||
* @return True if the command sender has permission, false otherwise.
|
||||
*/
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
// Make sure the command description is valid
|
||||
if(this.commandDescription == null)
|
||||
if (this.commandDescription == null)
|
||||
return false;
|
||||
|
||||
// Get and return the permission
|
||||
@@ -112,8 +119,8 @@ public class FoundCommandResult {
|
||||
/**
|
||||
* Get the command reference.
|
||||
*
|
||||
|
||||
* @return The command reference. */
|
||||
* @return The command reference.
|
||||
*/
|
||||
public CommandParts getCommandReference() {
|
||||
return this.commandReference;
|
||||
}
|
||||
@@ -121,8 +128,8 @@ public class FoundCommandResult {
|
||||
/**
|
||||
* Get the command arguments.
|
||||
*
|
||||
|
||||
* @return The command arguments. */
|
||||
* @return The command arguments.
|
||||
*/
|
||||
public CommandParts getCommandArguments() {
|
||||
return this.commandArguments;
|
||||
}
|
||||
@@ -130,8 +137,8 @@ public class FoundCommandResult {
|
||||
/**
|
||||
* Get the original query reference.
|
||||
*
|
||||
|
||||
* @return Original query reference. */
|
||||
* @return Original query reference.
|
||||
*/
|
||||
public CommandParts getQueryReference() {
|
||||
return this.queryReference;
|
||||
}
|
||||
@@ -139,11 +146,11 @@ public class FoundCommandResult {
|
||||
/**
|
||||
* Get the difference value between the original query and the result reference.
|
||||
*
|
||||
|
||||
* @return The difference value. */
|
||||
* @return The difference value.
|
||||
*/
|
||||
public double getDifference() {
|
||||
// Get the difference through the command found
|
||||
if(this.commandDescription != null)
|
||||
if (this.commandDescription != null)
|
||||
return this.commandDescription.getCommandDifference(this.queryReference);
|
||||
|
||||
// Get the difference from the query reference
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package fr.xephi.authme.command.executable;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -26,7 +25,7 @@ public class AccountsCommand extends ExecutableCommand {
|
||||
|
||||
// Get the player query
|
||||
String playerQuery = sender.getName();
|
||||
if(commandArguments.getCount() >= 1)
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerQuery = commandArguments.get(0);
|
||||
final String playerQueryFinal = playerQuery;
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -14,7 +13,7 @@ public class AuthMeCommand extends ExecutableCommand {
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Show some version info
|
||||
sender.sendMessage(ChatColor.GREEN + "This server is running " + AuthMe.PLUGIN_NAME + " v" + AuthMe.getVersionName() + "! " + ChatColor.RED + "<3");
|
||||
sender.sendMessage(ChatColor.GREEN + "This server is running " + AuthMe.getPluginName() + " v" + AuthMe.getVersionName() + "! " + ChatColor.RED + "<3");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " help" + ChatColor.YELLOW + " to view help.");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " about" + ChatColor.YELLOW + " to view about.");
|
||||
return true;
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
@@ -14,6 +9,10 @@ import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -19,11 +18,12 @@ public class ForceLoginCommand extends ExecutableCommand {
|
||||
|
||||
// Get the player query
|
||||
String playerName = sender.getName();
|
||||
if(commandArguments.getCount() >= 1)
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerName = commandArguments.get(0);
|
||||
|
||||
// Command logic
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
if (player == null || !player.isOnline()) {
|
||||
sender.sendMessage("Player needs to be online!");
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -19,13 +18,13 @@ public class GetEmailCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Get the player name
|
||||
String playerName = sender.getName();
|
||||
if(commandArguments.getCount() >= 1)
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerName = commandArguments.get(0);
|
||||
|
||||
// Get the authenticated user
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -19,9 +18,10 @@ public class GetIpCommand extends ExecutableCommand {
|
||||
|
||||
// Get the player query
|
||||
String playerName = sender.getName();
|
||||
if(commandArguments.getCount() >= 1)
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerName = commandArguments.get(0);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
if (player == null) {
|
||||
sender.sendMessage("This player is not actually online");
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -18,7 +17,7 @@ public class LastLoginCommand extends ExecutableCommand {
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Get the player
|
||||
String playerName = sender.getName();
|
||||
if(commandArguments.getCount() >= 1)
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerName = commandArguments.get(0);
|
||||
|
||||
// Validate the player
|
||||
|
||||
+7
-8
@@ -1,15 +1,14 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -22,8 +21,8 @@ public class PurgeBannedPlayersCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -22,8 +21,8 @@ public class PurgeCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
@@ -36,13 +35,13 @@ public class PurgeCommand extends ExecutableCommand {
|
||||
int days;
|
||||
try {
|
||||
days = Integer.valueOf(daysStr);
|
||||
} catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
sender.sendMessage(ChatColor.RED + "The value you've entered is invalid!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Validate the value
|
||||
if(days < 30) {
|
||||
if (days < 30) {
|
||||
sender.sendMessage(ChatColor.RED + "You can only purge data older than 30 days");
|
||||
return true;
|
||||
}
|
||||
@@ -59,13 +58,13 @@ public class PurgeCommand extends ExecutableCommand {
|
||||
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");
|
||||
|
||||
// Purge other data
|
||||
if(Settings.purgeEssentialsFile && plugin.ess != null)
|
||||
if (Settings.purgeEssentialsFile && plugin.ess != null)
|
||||
plugin.dataManager.purgeEssentials(purged);
|
||||
if(Settings.purgePlayerDat)
|
||||
if (Settings.purgePlayerDat)
|
||||
plugin.dataManager.purgeDat(purged);
|
||||
if(Settings.purgeLimitedCreative)
|
||||
if (Settings.purgeLimitedCreative)
|
||||
plugin.dataManager.purgeLimitedCreative(purged);
|
||||
if(Settings.purgeAntiXray)
|
||||
if (Settings.purgeAntiXray)
|
||||
plugin.dataManager.purgeAntiXray(purged);
|
||||
|
||||
// Show a status message
|
||||
|
||||
+5
-6
@@ -1,14 +1,13 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -21,8 +20,8 @@ public class PurgeLastPositionCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
@@ -33,7 +32,7 @@ public class PurgeLastPositionCommand extends ExecutableCommand {
|
||||
|
||||
// Get the player
|
||||
String playerName = sender.getName();
|
||||
if(commandArguments.getCount() >= 1)
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerName = commandArguments.get(0);
|
||||
String playerNameLowerCase = playerName.toLowerCase();
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
@@ -13,6 +8,10 @@ import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -25,8 +24,8 @@ public class RegisterCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
//import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
@@ -10,6 +9,7 @@ import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Profiler;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -22,8 +22,8 @@ public class ReloadCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Profile the reload process
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -21,8 +20,8 @@ public class ResetNameCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
@@ -33,7 +32,7 @@ public class ResetNameCommand extends ExecutableCommand {
|
||||
@Override
|
||||
public void run() {
|
||||
List<PlayerAuth> authentications = plugin.database.getAllAuths();
|
||||
for(PlayerAuth auth : authentications) {
|
||||
for (PlayerAuth auth : authentications) {
|
||||
auth.setRealName("Player");
|
||||
plugin.database.updateSession(auth);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
@@ -9,6 +7,7 @@ import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -21,8 +20,8 @@ public class SetEmailCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -19,8 +18,8 @@ public class SetFirstSpawnCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
try {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -19,8 +18,8 @@ public class SetSpawnCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the command executor is a player
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -19,8 +18,8 @@ public class SpawnCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the command executor is a player
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.AntiBot;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -19,29 +18,30 @@ public class SwitchAntiBotCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Get the new state
|
||||
String newState = plugin.getAntiBotModMode() ? "OFF" : "ON";
|
||||
if(commandArguments.getCount() >= 1)
|
||||
String newState = null;
|
||||
if (commandArguments.getCount() == 1) {
|
||||
newState = commandArguments.get(0);
|
||||
} else if(commandArguments.getCount() == 0) {
|
||||
sender.sendMessage("[AuthMe] AntiBot status: " + AntiBot.getAntiBotStatus().name());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Enable the mod
|
||||
if(newState.equalsIgnoreCase("ON")) {
|
||||
plugin.switchAntiBotMod(true);
|
||||
sender.sendMessage("[AuthMe] AntiBotMod enabled");
|
||||
if (newState.equalsIgnoreCase("ON")) {
|
||||
AntiBot.overrideAntiBotStatus(true);
|
||||
sender.sendMessage("[AuthMe] AntiBot Manual Ovverride: enabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Disable the mod
|
||||
if(newState.equalsIgnoreCase("OFF")) {
|
||||
plugin.switchAntiBotMod(false);
|
||||
sender.sendMessage("[AuthMe] AntiBotMod disabled");
|
||||
if (newState.equalsIgnoreCase("OFF")) {
|
||||
AntiBot.overrideAntiBotStatus(false);
|
||||
sender.sendMessage("[AuthMe] AntiBotMod Manual Ovverride: disabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.MessageKey;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -30,8 +30,9 @@ public class UnregisterCommand extends ExecutableCommand {
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
@@ -46,18 +47,17 @@ public class UnregisterCommand extends ExecutableCommand {
|
||||
|
||||
// Make sure the user is valid
|
||||
if (!plugin.database.isAuthAvailable(playerNameLowerCase)) {
|
||||
m.send(sender, "user_unknown");
|
||||
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove the player
|
||||
if (!plugin.database.removeAuth(playerNameLowerCase)) {
|
||||
m.send(sender, "error");
|
||||
m.send(sender, MessageKey.ERROR);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Unregister the player
|
||||
@SuppressWarnings("deprecation")
|
||||
Player target = Bukkit.getPlayer(playerNameLowerCase);
|
||||
PlayerCache.getInstance().removePlayer(playerNameLowerCase);
|
||||
Utils.setGroup(target, Utils.GroupType.UNREGISTERED);
|
||||
@@ -71,19 +71,21 @@ public class UnregisterCommand extends ExecutableCommand {
|
||||
BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), delay);
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id);
|
||||
}
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(scheduler.runTaskAsynchronously(plugin, new MessageTask(plugin, playerNameLowerCase, m.send("reg_msg"), interval)));
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(
|
||||
scheduler.runTaskAsynchronously(plugin,
|
||||
new MessageTask(plugin, playerNameLowerCase, m.retrieve(MessageKey.REGISTER_MESSAGE), interval)));
|
||||
if (Settings.applyBlindEffect)
|
||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
||||
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||
target.setWalkSpeed(0.0f);
|
||||
target.setFlySpeed(0.0f);
|
||||
}
|
||||
m.send(target, "unregistered");
|
||||
m.send(target, MessageKey.UNREGISTERED_SUCCESS);
|
||||
|
||||
}
|
||||
|
||||
// Show a status message
|
||||
m.send(sender, "unregistered");
|
||||
m.send(sender, MessageKey.UNREGISTERED_SUCCESS);
|
||||
ConsoleLogger.info(playerName + " unregistered");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -20,13 +19,13 @@ public class VersionCommand extends ExecutableCommand {
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Show some version info
|
||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.PLUGIN_NAME.toUpperCase() + " ABOUT ]==========");
|
||||
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.PLUGIN_NAME + " v" + AuthMe.getVersionName() + ChatColor.GRAY + " (code: " + AuthMe.getVersionCode() + ")");
|
||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.getPluginName().toUpperCase() + " ABOUT ]==========");
|
||||
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.getPluginName() + " v" + AuthMe.getVersionName() + ChatColor.GRAY + " (code: " + AuthMe.getVersionCode() + ")");
|
||||
sender.sendMessage(ChatColor.GOLD + "Developers:");
|
||||
printDeveloper(sender, "Xephi", "xephi59", "Lead Developer");
|
||||
printDeveloper(sender, "DNx5", "DNx5", "Developer");
|
||||
@@ -42,10 +41,10 @@ public class VersionCommand extends ExecutableCommand {
|
||||
/**
|
||||
* Print a developer with proper styling.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param name The display name of the developer.
|
||||
* @param sender The command sender.
|
||||
* @param name The display name of the developer.
|
||||
* @param minecraftName The Minecraft username of the developer, if available.
|
||||
* @param function The function of the developer.
|
||||
* @param function The function of the developer.
|
||||
*/
|
||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||
private void printDeveloper(CommandSender sender, String name, String minecraftName, String function) {
|
||||
@@ -55,13 +54,13 @@ public class VersionCommand extends ExecutableCommand {
|
||||
msg.append(name);
|
||||
|
||||
// Append the Minecraft name, if available
|
||||
if(minecraftName.length() != 0)
|
||||
if (minecraftName.length() != 0)
|
||||
msg.append(ChatColor.GRAY + " // " + ChatColor.WHITE + minecraftName);
|
||||
msg.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (" + function + ")");
|
||||
|
||||
// Show the online status
|
||||
if(minecraftName.length() != 0)
|
||||
if(isPlayerOnline(minecraftName))
|
||||
if (minecraftName.length() != 0)
|
||||
if (isPlayerOnline(minecraftName))
|
||||
msg.append(ChatColor.GREEN + "" + ChatColor.ITALIC + " (In-Game)");
|
||||
|
||||
// Print the message
|
||||
@@ -73,12 +72,16 @@ public class VersionCommand extends ExecutableCommand {
|
||||
*
|
||||
* @param minecraftName The Minecraft player name.
|
||||
*
|
||||
|
||||
* @return True if the player is online, false otherwise. */
|
||||
* @return True if the player is online, false otherwise.
|
||||
*/
|
||||
private boolean isPlayerOnline(String minecraftName) {
|
||||
for(Player player : Bukkit.getOnlinePlayers())
|
||||
if(player.getName().equalsIgnoreCase(minecraftName))
|
||||
// Note ljacqu 20151121: Generally you should use Utils#getOnlinePlayers to retrieve the list of online players.
|
||||
// If it's only used in a for-each loop such as here, it's fine. For other purposes, go through the Utils class.
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (player.getName().equalsIgnoreCase(minecraftName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,24 @@
|
||||
package fr.xephi.authme.command.executable.captcha;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.settings.MessageKey;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class CaptchaCommand extends ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
final Messages m = Messages.getInstance();
|
||||
|
||||
// Random string instance, for captcha generation (I think) -- timvisee
|
||||
RandomString randStr = new RandomString(Settings.captchaLength);
|
||||
|
||||
// Get the parameter values
|
||||
String captcha = commandArguments.get(0);
|
||||
|
||||
// Make sure the current command executor is a player
|
||||
if(!(sender instanceof Player)) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -47,39 +26,47 @@ public class CaptchaCommand extends ExecutableCommand {
|
||||
final Player player = (Player) sender;
|
||||
final String playerNameLowerCase = player.getName().toLowerCase();
|
||||
|
||||
// Get the parameter values
|
||||
String captcha = commandArguments.get(0);
|
||||
|
||||
// Messages instance
|
||||
final Messages m = Messages.getInstance();
|
||||
|
||||
// Command logic
|
||||
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||
m.send(player, "logged_in");
|
||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Settings.useCaptcha) {
|
||||
m.send(player, "usage_log");
|
||||
m.send(player, MessageKey.USAGE_LOGIN);
|
||||
return true;
|
||||
}
|
||||
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
if (!plugin.cap.containsKey(playerNameLowerCase)) {
|
||||
m.send(player, "usage_log");
|
||||
m.send(player, MessageKey.USAGE_LOGIN);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
|
||||
plugin.cap.remove(playerNameLowerCase);
|
||||
plugin.cap.put(playerNameLowerCase, randStr.nextString());
|
||||
for (String s : m.send("wrong_captcha")) {
|
||||
String randStr = new RandomString(Settings.captchaLength).nextString();
|
||||
plugin.cap.put(playerNameLowerCase, randStr);
|
||||
for (String s : m.retrieve(MessageKey.CAPTCHA_WRONG_ERROR)) {
|
||||
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
plugin.captcha.remove(playerNameLowerCase);
|
||||
plugin.cap.remove(playerNameLowerCase);
|
||||
} catch (NullPointerException ignored) { }
|
||||
plugin.captcha.remove(playerNameLowerCase);
|
||||
plugin.cap.remove(playerNameLowerCase);
|
||||
|
||||
// Show a status message
|
||||
m.send(player, "valid_captcha");
|
||||
m.send(player, "login_msg");
|
||||
m.send(player, MessageKey.CAPTCHA_SUCCESS);
|
||||
m.send(player, MessageKey.LOGIN_MESSAGE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -1,8 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.changepassword;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
@@ -10,6 +7,8 @@ import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.task.ChangePasswordTask;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
package fr.xephi.authme.command.executable.converter;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.converter.Converter;
|
||||
import fr.xephi.authme.converter.CrazyLoginConverter;
|
||||
import fr.xephi.authme.converter.FlatToSql;
|
||||
import fr.xephi.authme.converter.FlatToSqlite;
|
||||
import fr.xephi.authme.converter.RakamakConverter;
|
||||
import fr.xephi.authme.converter.RoyalAuthConverter;
|
||||
import fr.xephi.authme.converter.SqlToFlat;
|
||||
import fr.xephi.authme.converter.vAuthConverter;
|
||||
import fr.xephi.authme.converter.xAuthConverter;
|
||||
import fr.xephi.authme.converter.*;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -24,12 +15,12 @@ public class ConverterCommand extends ExecutableCommand {
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
@@ -51,32 +42,32 @@ public class ConverterCommand extends ExecutableCommand {
|
||||
// Get the proper converter instance
|
||||
Converter converter = null;
|
||||
switch (jobType) {
|
||||
case ftsql:
|
||||
converter = new FlatToSql();
|
||||
break;
|
||||
case ftsqlite:
|
||||
converter = new FlatToSqlite(sender);
|
||||
break;
|
||||
case xauth:
|
||||
converter = new xAuthConverter(plugin, sender);
|
||||
break;
|
||||
case crazylogin:
|
||||
converter = new CrazyLoginConverter(plugin, sender);
|
||||
break;
|
||||
case rakamak:
|
||||
converter = new RakamakConverter(plugin, sender);
|
||||
break;
|
||||
case royalauth:
|
||||
converter = new RoyalAuthConverter(plugin);
|
||||
break;
|
||||
case vauth:
|
||||
converter = new vAuthConverter(plugin, sender);
|
||||
break;
|
||||
case sqltoflat:
|
||||
converter = new SqlToFlat(plugin, sender);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case ftsql:
|
||||
converter = new FlatToSql();
|
||||
break;
|
||||
case ftsqlite:
|
||||
converter = new FlatToSqlite(sender);
|
||||
break;
|
||||
case xauth:
|
||||
converter = new xAuthConverter(plugin, sender);
|
||||
break;
|
||||
case crazylogin:
|
||||
converter = new CrazyLoginConverter(plugin, sender);
|
||||
break;
|
||||
case rakamak:
|
||||
converter = new RakamakConverter(plugin, sender);
|
||||
break;
|
||||
case royalauth:
|
||||
converter = new RoyalAuthConverter(plugin);
|
||||
break;
|
||||
case vauth:
|
||||
converter = new vAuthConverter(plugin, sender);
|
||||
break;
|
||||
case sqltoflat:
|
||||
converter = new SqlToFlat(plugin, sender);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Run the convert job
|
||||
@@ -99,29 +90,24 @@ public class ConverterCommand extends ExecutableCommand {
|
||||
vauth("vauth"),
|
||||
sqltoflat("sqltoflat");
|
||||
|
||||
String name;
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* Constructor for ConvertType.
|
||||
*
|
||||
* @param name String
|
||||
*/
|
||||
ConvertType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getName.
|
||||
|
||||
* @return String */
|
||||
String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method fromName.
|
||||
*
|
||||
* @param name String
|
||||
|
||||
* @return ConvertType */
|
||||
*
|
||||
* @return ConvertType
|
||||
*/
|
||||
public static ConvertType fromName(String name) {
|
||||
for (ConvertType type : ConvertType.values()) {
|
||||
if (type.getName().equalsIgnoreCase(name))
|
||||
@@ -129,5 +115,14 @@ public class ConverterCommand extends ExecutableCommand {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getName.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
@@ -15,6 +10,10 @@ import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package fr.xephi.authme.command.executable.login;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -21,10 +20,10 @@ public class LoginCommand extends ExecutableCommand {
|
||||
// Get the necessary objects
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
final Player player = (Player) sender;
|
||||
final String playerPass = commandArguments.get(0);
|
||||
final String password = commandArguments.get(0);
|
||||
|
||||
// Log the player in
|
||||
plugin.getManagement().performLogin(player, playerPass, false);
|
||||
plugin.getManagement().performLogin(player, password, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package fr.xephi.authme.command.executable.logout;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package fr.xephi.authme.command.executable.register;
|
||||
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package fr.xephi.authme.command.executable.unregister;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -16,12 +15,12 @@ public class UnregisterCommand extends ExecutableCommand {
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
|
||||
* @return True if the command was executed successfully, false otherwise. */
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
@@ -31,7 +30,7 @@ public class UnregisterCommand extends ExecutableCommand {
|
||||
final Messages m = Messages.getInstance();
|
||||
|
||||
// Make sure the current command executor is a player
|
||||
if(!(sender instanceof Player)) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package fr.xephi.authme.command.help;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandArgumentDescription;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandPermissions;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -23,8 +22,8 @@ public class HelpPrinter {
|
||||
/**
|
||||
* Print the command help information.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print.
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print.
|
||||
* @param commandReference The command reference used.
|
||||
*/
|
||||
public static void printCommand(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||
@@ -35,16 +34,16 @@ public class HelpPrinter {
|
||||
/**
|
||||
* Print the command help description information. This will print both the short, as the detailed description if available.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print the description help for.
|
||||
*/
|
||||
public static void printCommandDescription(CommandSender sender, CommandDescription command) {
|
||||
// Print the regular description, if available
|
||||
if(command.hasDescription())
|
||||
if (command.hasDescription())
|
||||
sender.sendMessage(ChatColor.GOLD + "Short Description: " + ChatColor.WHITE + command.getDescription());
|
||||
|
||||
// Print the detailed description, if available
|
||||
if(command.hasDetailedDescription()) {
|
||||
if (command.hasDetailedDescription()) {
|
||||
sender.sendMessage(ChatColor.GOLD + "Detailed Description:");
|
||||
sender.sendMessage(ChatColor.WHITE + " " + command.getDetailedDescription());
|
||||
}
|
||||
@@ -53,26 +52,26 @@ public class HelpPrinter {
|
||||
/**
|
||||
* Print the command help arguments information if available.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print the argument help for.
|
||||
*/
|
||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||
public static void printArguments(CommandSender sender, CommandDescription command) {
|
||||
// Make sure there are any commands to print
|
||||
if(!command.hasArguments() && command.getMaximumArguments() >= 0)
|
||||
if (!command.hasArguments() && command.getMaximumArguments() >= 0)
|
||||
return;
|
||||
|
||||
// Print the header
|
||||
sender.sendMessage(ChatColor.GOLD + "Arguments:");
|
||||
|
||||
// Print each argument
|
||||
for(CommandArgumentDescription arg : command.getArguments()) {
|
||||
for (CommandArgumentDescription arg : command.getArguments()) {
|
||||
// Create a string builder to build the syntax in
|
||||
StringBuilder argString = new StringBuilder();
|
||||
argString.append(" " + ChatColor.YELLOW + ChatColor.ITALIC + arg.getLabel() + " : " + ChatColor.WHITE + arg.getDescription());
|
||||
|
||||
// Suffix a note if the command is optional
|
||||
if(arg.isOptional())
|
||||
if (arg.isOptional())
|
||||
argString.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (Optional)");
|
||||
|
||||
// Print the syntax
|
||||
@@ -80,57 +79,57 @@ public class HelpPrinter {
|
||||
}
|
||||
|
||||
// Show the unlimited arguments argument
|
||||
if(command.getMaximumArguments() < 0)
|
||||
if (command.getMaximumArguments() < 0)
|
||||
sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + "... : " + ChatColor.WHITE + "Any additional arguments." + ChatColor.GRAY + ChatColor.ITALIC + " (Optional)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the command help permissions information if available.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print the permissions help for.
|
||||
*/
|
||||
public static void printPermissions(CommandSender sender, CommandDescription command) {
|
||||
// Get the permissions and make sure it isn't null
|
||||
CommandPermissions permissions = command.getCommandPermissions();
|
||||
if(permissions == null)
|
||||
if (permissions == null)
|
||||
return;
|
||||
|
||||
// Make sure any permission node is set
|
||||
if(permissions.getPermissionNodeCount() <= 0)
|
||||
if (permissions.getPermissionNodeCount() <= 0)
|
||||
return;
|
||||
|
||||
// Print the header
|
||||
sender.sendMessage(ChatColor.GOLD + "Permissions:");
|
||||
|
||||
// Print each node
|
||||
for(String node : permissions.getPermissionNodes()) {
|
||||
for (String node : permissions.getPermissionNodes()) {
|
||||
boolean nodePermission = true;
|
||||
if(sender instanceof Player)
|
||||
if (sender instanceof Player)
|
||||
nodePermission = AuthMe.getInstance().getPermissionsManager().hasPermission((Player) sender, node);
|
||||
final String nodePermsString = ChatColor.GRAY + (nodePermission ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
|
||||
sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + node + nodePermsString);
|
||||
}
|
||||
|
||||
// Print the default permission
|
||||
switch(permissions.getDefaultPermission()) {
|
||||
case ALLOWED:
|
||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "Permission!");
|
||||
break;
|
||||
switch (permissions.getDefaultPermission()) {
|
||||
case ALLOWED:
|
||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "Permission!");
|
||||
break;
|
||||
|
||||
case OP_ONLY:
|
||||
final String defaultPermsString = ChatColor.GRAY + (permissions.getDefaultPermissionCommandSender(sender) ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
|
||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.YELLOW + ChatColor.ITALIC + "OP's Only!" + defaultPermsString);
|
||||
break;
|
||||
case OP_ONLY:
|
||||
final String defaultPermsString = ChatColor.GRAY + (permissions.getDefaultPermissionCommandSender(sender) ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
|
||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.YELLOW + ChatColor.ITALIC + "OP's Only!" + defaultPermsString);
|
||||
break;
|
||||
|
||||
case NOT_ALLOWED:
|
||||
default:
|
||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "No Permission!");
|
||||
break;
|
||||
case NOT_ALLOWED:
|
||||
default:
|
||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "No Permission!");
|
||||
break;
|
||||
}
|
||||
|
||||
// Print the permission result
|
||||
if(permissions.hasPermission(sender))
|
||||
if (permissions.hasPermission(sender))
|
||||
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.GREEN + ChatColor.ITALIC + "Permission!");
|
||||
else
|
||||
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.DARK_RED + ChatColor.ITALIC + "No Permission!");
|
||||
@@ -139,13 +138,13 @@ public class HelpPrinter {
|
||||
/**
|
||||
* Print the command help alternatives information if available.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command used.
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command used.
|
||||
* @param commandReference The original command reference used for this command.
|
||||
*/
|
||||
public static void printAlternatives(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||
// Make sure there are any alternatives
|
||||
if(command.getLabels().size() <= 1)
|
||||
if (command.getLabels().size() <= 1)
|
||||
return;
|
||||
|
||||
// Print the header
|
||||
@@ -156,9 +155,9 @@ public class HelpPrinter {
|
||||
|
||||
// Create a list of alternatives
|
||||
List<String> alternatives = new ArrayList<>();
|
||||
for(String entry : command.getLabels()) {
|
||||
for (String entry : command.getLabels()) {
|
||||
// Exclude the proper argument
|
||||
if(entry.equalsIgnoreCase(usedLabel))
|
||||
if (entry.equalsIgnoreCase(usedLabel))
|
||||
continue;
|
||||
alternatives.add(entry);
|
||||
}
|
||||
@@ -172,27 +171,27 @@ public class HelpPrinter {
|
||||
});
|
||||
|
||||
// Print each alternative with proper syntax
|
||||
for(String alternative : alternatives)
|
||||
for (String alternative : alternatives)
|
||||
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(command, commandReference, alternative, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the command help child's information if available.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print the help for.
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print the help for.
|
||||
* @param commandReference The original command reference used for this command.
|
||||
*/
|
||||
public static void printChildren(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||
// Make sure there are child's
|
||||
if(command.getChildren().size() <= 0)
|
||||
if (command.getChildren().size() <= 0)
|
||||
return;
|
||||
|
||||
// Print the header
|
||||
sender.sendMessage(ChatColor.GOLD + "Commands:");
|
||||
|
||||
// Loop through each child
|
||||
for(CommandDescription child : command.getChildren())
|
||||
for (CommandDescription child : command.getChildren())
|
||||
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(child, commandReference, null, false) + ChatColor.GRAY + ChatColor.ITALIC + " : " + child.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package fr.xephi.authme.command.help;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.FoundCommandResult;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -15,7 +14,7 @@ public class HelpProvider {
|
||||
/**
|
||||
* Show help for a specific command.
|
||||
*
|
||||
* @param sender The command sender the help needs to be shown to.
|
||||
* @param sender The command sender the help needs to be shown to.
|
||||
* @param reference The command reference to the help command.
|
||||
* @param helpQuery The query to show help for.
|
||||
*/
|
||||
@@ -26,31 +25,31 @@ public class HelpProvider {
|
||||
/**
|
||||
* Show help for a specific command.
|
||||
*
|
||||
* @param sender The command sender the help needs to be shown to.
|
||||
* @param reference The command reference to the help command.
|
||||
* @param helpQuery The query to show help for.
|
||||
* @param showCommand True to show the command.
|
||||
* @param showDescription True to show the command description, both the short and detailed description.
|
||||
* @param showArguments True to show the command argument help.
|
||||
* @param showPermissions True to show the command permission help.
|
||||
* @param sender The command sender the help needs to be shown to.
|
||||
* @param reference The command reference to the help command.
|
||||
* @param helpQuery The query to show help for.
|
||||
* @param showCommand True to show the command.
|
||||
* @param showDescription True to show the command description, both the short and detailed description.
|
||||
* @param showArguments True to show the command argument help.
|
||||
* @param showPermissions True to show the command permission help.
|
||||
* @param showAlternatives True to show the command alternatives.
|
||||
* @param showCommands True to show the child commands.
|
||||
* @param showCommands True to show the child commands.
|
||||
*/
|
||||
public static void showHelp(CommandSender sender, CommandParts reference, CommandParts helpQuery, boolean showCommand, boolean showDescription, boolean showArguments, boolean showPermissions, boolean showAlternatives, boolean showCommands) {
|
||||
// Find the command for this help query, one with and one without a prefixed base command
|
||||
FoundCommandResult result = AuthMe.getInstance().getCommandHandler().getCommandManager().findCommand(new CommandParts(helpQuery.getList()));
|
||||
CommandParts commandReferenceOther = new CommandParts(reference.get(0), helpQuery.getList());
|
||||
FoundCommandResult resultOther = AuthMe.getInstance().getCommandHandler().getCommandManager().findCommand(commandReferenceOther);
|
||||
if(resultOther != null) {
|
||||
if(result == null)
|
||||
if (resultOther != null) {
|
||||
if (result == null)
|
||||
result = resultOther;
|
||||
|
||||
else if(result.getDifference() > resultOther.getDifference())
|
||||
else if (result.getDifference() > resultOther.getDifference())
|
||||
result = resultOther;
|
||||
}
|
||||
|
||||
// Make sure a result was found
|
||||
if(result == null) {
|
||||
if (result == null) {
|
||||
// Show a warning message
|
||||
sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.ITALIC + helpQuery);
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Couldn't show any help information for this help query.");
|
||||
@@ -59,7 +58,7 @@ public class HelpProvider {
|
||||
|
||||
// Get the command description, and make sure it's valid
|
||||
CommandDescription command = result.getCommandDescription();
|
||||
if(command == null) {
|
||||
if (command == null) {
|
||||
// Show a warning message
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Failed to retrieve any help information!");
|
||||
return;
|
||||
@@ -73,7 +72,7 @@ public class HelpProvider {
|
||||
|
||||
// Make sure the difference between the command reference and the actual command isn't too big
|
||||
final double commandDifference = result.getDifference();
|
||||
if(commandDifference > 0.20) {
|
||||
if (commandDifference > 0.20) {
|
||||
// Show the unknown command warning
|
||||
sender.sendMessage(ChatColor.DARK_RED + "No help found for '" + helpQuery + "'!");
|
||||
|
||||
@@ -81,8 +80,8 @@ public class HelpProvider {
|
||||
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1));
|
||||
|
||||
// Show a command suggestion if available and the difference isn't too big
|
||||
if(commandDifference < 0.75)
|
||||
if(result.getCommandDescription() != null)
|
||||
if (commandDifference < 0.75)
|
||||
if (result.getCommandDescription() != null)
|
||||
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + baseCommand + " help " + suggestedCommandParts + ChatColor.YELLOW + "?");
|
||||
|
||||
// Show the help command
|
||||
@@ -91,7 +90,7 @@ public class HelpProvider {
|
||||
}
|
||||
|
||||
// Show a message when the command handler is assuming a command
|
||||
if(commandDifference > 0) {
|
||||
if (commandDifference > 0) {
|
||||
// Get the suggested command
|
||||
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1));
|
||||
|
||||
@@ -100,20 +99,20 @@ public class HelpProvider {
|
||||
}
|
||||
|
||||
// Print the help header
|
||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.PLUGIN_NAME.toUpperCase() + " HELP ]==========");
|
||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.getPluginName().toUpperCase() + " HELP ]==========");
|
||||
|
||||
// Print the command help information
|
||||
if(showCommand)
|
||||
if (showCommand)
|
||||
HelpPrinter.printCommand(sender, command, commandReference);
|
||||
if(showDescription)
|
||||
if (showDescription)
|
||||
HelpPrinter.printCommandDescription(sender, command);
|
||||
if(showArguments)
|
||||
if (showArguments)
|
||||
HelpPrinter.printArguments(sender, command);
|
||||
if(showPermissions)
|
||||
if (showPermissions)
|
||||
HelpPrinter.printPermissions(sender, command);
|
||||
if(showAlternatives)
|
||||
if (showAlternatives)
|
||||
HelpPrinter.printAlternatives(sender, command, commandReference);
|
||||
if(showCommands)
|
||||
if (showCommands)
|
||||
HelpPrinter.printChildren(sender, command, commandReference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package fr.xephi.authme.command.help;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import fr.xephi.authme.command.CommandArgumentDescription;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* Helper class for formatting a command's structure (name and arguments)
|
||||
@@ -21,9 +20,9 @@ public final class HelpSyntaxHelper {
|
||||
* Get the formatted syntax for a command.
|
||||
*
|
||||
* @param commandDescription The command to build the syntax for.
|
||||
* @param commandReference The reference of the command.
|
||||
* @param alternativeLabel The alternative label to use for this command syntax.
|
||||
* @param highlight True to highlight the important parts of this command.
|
||||
* @param commandReference The reference of the command.
|
||||
* @param alternativeLabel The alternative label to use for this command syntax.
|
||||
* @param highlight True to highlight the important parts of this command.
|
||||
*
|
||||
* @return The command with proper syntax.
|
||||
*/
|
||||
@@ -37,7 +36,7 @@ public final class HelpSyntaxHelper {
|
||||
// Get the help command reference, and the command label
|
||||
CommandParts helpCommandReference = commandDescription.getCommandReference(commandReference);
|
||||
final String parentCommand = new CommandParts(
|
||||
helpCommandReference.getRange(0, helpCommandReference.getCount() - 1)).toString();
|
||||
helpCommandReference.getRange(0, helpCommandReference.getCount() - 1)).toString();
|
||||
|
||||
// Check whether the alternative label should be used
|
||||
String commandLabel;
|
||||
|
||||
Reference in New Issue
Block a user