Finalization for #305 - command refactor
This commit is contained in:
parent
3cc35baa5e
commit
efa458cae1
@ -146,16 +146,15 @@ public class CommandDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of parents that precede the command description.
|
* Return the number of labels necessary to get to this command. This corresponds to the number of parents + 1.
|
||||||
*
|
*
|
||||||
* @return The number of parents, e.g. for "/authme abc def" the parent count is 2 ("/authme abc", "/authme")
|
* @return The number of labels, e.g. for "/authme abc def" the label count is 3
|
||||||
*/
|
*/
|
||||||
// TODO ljacqu 20151217: If we always use `getParentCount() + 1` rewrite this method to a `getLabelCount()`
|
public int getLabelCount() {
|
||||||
public int getParentCount() {
|
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
return parent.getParentCount() + 1;
|
return parent.getLabelCount() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -125,7 +125,7 @@ public class CommandHandler {
|
|||||||
sender.sendMessage(ChatColor.DARK_RED + "Unknown command!");
|
sender.sendMessage(ChatColor.DARK_RED + "Unknown command!");
|
||||||
|
|
||||||
// Show a command suggestion if available and the difference isn't too big
|
// Show a command suggestion if available and the difference isn't too big
|
||||||
if (result.getDifference() < SUGGEST_COMMAND_THRESHOLD && result.getCommandDescription() != null) {
|
if (result.getDifference() <= SUGGEST_COMMAND_THRESHOLD && result.getCommandDescription() != null) {
|
||||||
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD
|
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD
|
||||||
+ CommandUtils.constructCommandPath(result.getCommandDescription()) + ChatColor.YELLOW + "?");
|
+ CommandUtils.constructCommandPath(result.getCommandDescription()) + ChatColor.YELLOW + "?");
|
||||||
}
|
}
|
||||||
@ -215,7 +215,7 @@ public class CommandHandler {
|
|||||||
|
|
||||||
FoundResultStatus status = (minDifference == 0.0) ? INCORRECT_ARGUMENTS : UNKNOWN_LABEL;
|
FoundResultStatus status = (minDifference == 0.0) ? INCORRECT_ARGUMENTS : UNKNOWN_LABEL;
|
||||||
final int partsSize = parts.size();
|
final int partsSize = parts.size();
|
||||||
List<String> labels = parts.subList(0, Math.min(closestCommand.getParentCount() + 1, partsSize));
|
List<String> labels = parts.subList(0, Math.min(closestCommand.getLabelCount(), partsSize));
|
||||||
List<String> arguments = (labels.size() == partsSize)
|
List<String> arguments = (labels.size() == partsSize)
|
||||||
? new ArrayList<String>()
|
? new ArrayList<String>()
|
||||||
: parts.subList(labels.size(), partsSize);
|
: parts.subList(labels.size(), partsSize);
|
||||||
|
|||||||
@ -34,7 +34,6 @@ import fr.xephi.authme.command.executable.register.RegisterCommand;
|
|||||||
import fr.xephi.authme.command.executable.unregister.UnregisterCommand;
|
import fr.xephi.authme.command.executable.unregister.UnregisterCommand;
|
||||||
import fr.xephi.authme.permission.AdminPermission;
|
import fr.xephi.authme.permission.AdminPermission;
|
||||||
import fr.xephi.authme.permission.PlayerPermission;
|
import fr.xephi.authme.permission.PlayerPermission;
|
||||||
import fr.xephi.authme.util.Wrapper;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -56,7 +55,6 @@ public final class CommandInitializer {
|
|||||||
|
|
||||||
public static Set<CommandDescription> getBaseCommands() {
|
public static Set<CommandDescription> getBaseCommands() {
|
||||||
if (baseCommands == null) {
|
if (baseCommands == null) {
|
||||||
Wrapper.getInstance().getLogger().info("Initializing AuthMe commands");
|
|
||||||
initializeCommands();
|
initializeCommands();
|
||||||
}
|
}
|
||||||
return baseCommands;
|
return baseCommands;
|
||||||
@ -287,8 +285,8 @@ public final class CommandInitializer {
|
|||||||
.parent(AUTHME_BASE)
|
.parent(AUTHME_BASE)
|
||||||
.labels("version", "ver", "v", "about", "info")
|
.labels("version", "ver", "v", "about", "info")
|
||||||
.description("Version info")
|
.description("Version info")
|
||||||
.detailedDescription("Show detailed information about the installed AuthMeReloaded version, and shows the "
|
.detailedDescription("Show detailed information about the installed AuthMeReloaded version, the "
|
||||||
+ "developers, contributors, license and other information.")
|
+ "developers, contributors, and license.")
|
||||||
.executableCommand(new VersionCommand())
|
.executableCommand(new VersionCommand())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user