From efa458cae1954e7efc2907fd87ed9e98d4aa9c38 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 19 Dec 2015 20:25:12 +0100 Subject: [PATCH] Finalization for #305 - command refactor --- .../fr/xephi/authme/command/CommandDescription.java | 11 +++++------ .../java/fr/xephi/authme/command/CommandHandler.java | 4 ++-- .../fr/xephi/authme/command/CommandInitializer.java | 6 ++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/fr/xephi/authme/command/CommandDescription.java b/src/main/java/fr/xephi/authme/command/CommandDescription.java index 6e69c7653..d398af674 100644 --- a/src/main/java/fr/xephi/authme/command/CommandDescription.java +++ b/src/main/java/fr/xephi/authme/command/CommandDescription.java @@ -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 getParentCount() { + public int getLabelCount() { if (parent == null) { - return 0; + return 1; } - return parent.getParentCount() + 1; + return parent.getLabelCount() + 1; } /** diff --git a/src/main/java/fr/xephi/authme/command/CommandHandler.java b/src/main/java/fr/xephi/authme/command/CommandHandler.java index a6f7f4b67..fad9a2699 100644 --- a/src/main/java/fr/xephi/authme/command/CommandHandler.java +++ b/src/main/java/fr/xephi/authme/command/CommandHandler.java @@ -125,7 +125,7 @@ public class CommandHandler { sender.sendMessage(ChatColor.DARK_RED + "Unknown command!"); // 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 + CommandUtils.constructCommandPath(result.getCommandDescription()) + ChatColor.YELLOW + "?"); } @@ -215,7 +215,7 @@ public class CommandHandler { FoundResultStatus status = (minDifference == 0.0) ? INCORRECT_ARGUMENTS : UNKNOWN_LABEL; final int partsSize = parts.size(); - List labels = parts.subList(0, Math.min(closestCommand.getParentCount() + 1, partsSize)); + List labels = parts.subList(0, Math.min(closestCommand.getLabelCount(), partsSize)); List arguments = (labels.size() == partsSize) ? new ArrayList() : parts.subList(labels.size(), partsSize); diff --git a/src/main/java/fr/xephi/authme/command/CommandInitializer.java b/src/main/java/fr/xephi/authme/command/CommandInitializer.java index 2866669e2..82f45fc29 100644 --- a/src/main/java/fr/xephi/authme/command/CommandInitializer.java +++ b/src/main/java/fr/xephi/authme/command/CommandInitializer.java @@ -34,7 +34,6 @@ import fr.xephi.authme.command.executable.register.RegisterCommand; import fr.xephi.authme.command.executable.unregister.UnregisterCommand; import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.PlayerPermission; -import fr.xephi.authme.util.Wrapper; import java.util.Arrays; import java.util.List; @@ -56,7 +55,6 @@ public final class CommandInitializer { public static Set getBaseCommands() { if (baseCommands == null) { - Wrapper.getInstance().getLogger().info("Initializing AuthMe commands"); initializeCommands(); } return baseCommands; @@ -287,8 +285,8 @@ public final class CommandInitializer { .parent(AUTHME_BASE) .labels("version", "ver", "v", "about", "info") .description("Version info") - .detailedDescription("Show detailed information about the installed AuthMeReloaded version, and shows the " - + "developers, contributors, license and other information.") + .detailedDescription("Show detailed information about the installed AuthMeReloaded version, the " + + "developers, contributors, and license.") .executableCommand(new VersionCommand()) .build();