Set help index page to 1 for invalid numbers. Fixes BUKKIT-1569

By: feildmaster <admin@feildmaster.com>
This commit is contained in:
Bukkit/Spigot 2012-04-28 11:09:43 -05:00
parent 8726d93ca1
commit b475946a3d

View File

@ -37,7 +37,14 @@ public class HelpCommand extends VanillaCommand {
pageNumber = 1; pageNumber = 1;
} else if (NumberUtils.isDigits(args[args.length - 1])) { } else if (NumberUtils.isDigits(args[args.length - 1])) {
command = StringUtils.join(ArrayUtils.subarray(args, 0, args.length - 1), " "); command = StringUtils.join(ArrayUtils.subarray(args, 0, args.length - 1), " ");
try {
pageNumber = NumberUtils.createInteger(args[args.length - 1]); pageNumber = NumberUtils.createInteger(args[args.length - 1]);
} catch (NumberFormatException exception) {
pageNumber = 1;
}
if (pageNumber <= 0) {
pageNumber = 1;
}
} else { } else {
command = StringUtils.join(args, " "); command = StringUtils.join(args, " ");
pageNumber = 1; pageNumber = 1;
@ -131,17 +138,24 @@ public class HelpCommand extends VanillaCommand {
} }
/** /**
* Computes the Dameraur-Levenshtein Distance between two strings. Adapted from the algorithm at * Computes the Dameraur-Levenshtein Distance between two strings. Adapted
* http://en.wikipedia.org/wiki/DamerauLevenshtein_distance * from the algorithm at <a href="http://en.wikipedia.org/wiki/DamerauLevenshtein_distance">Wikipedia: DamerauLevenshtein distance</a>
* *
* @param s1 The first string being compared. * @param s1 The first string being compared.
* @param s2 The second string being compared. * @param s2 The second string being compared.
* @return The number of substitutions, deletions, insertions, and transpositions required to get from s1 to s2. * @return The number of substitutions, deletions, insertions, and
* transpositions required to get from s1 to s2.
*/ */
protected static int damerauLevenshteinDistance(String s1, String s2) { protected static int damerauLevenshteinDistance(String s1, String s2) {
if (s1 == null && s2 == null) return 0; if (s1 == null && s2 == null) {
if (s1 != null && s2 == null) return s1.length(); return 0;
if (s1 == null && s2 != null) return s2.length(); }
if (s1 != null && s2 == null) {
return s1.length();
}
if (s1 == null && s2 != null) {
return s2.length();
}
int s1Len = s1.length(); int s1Len = s1.length();
int s2Len = s2.length(); int s2Len = s2.length();
@ -160,7 +174,9 @@ public class HelpCommand extends VanillaCommand {
Map<Character, Integer> sd = new HashMap<Character, Integer>(); Map<Character, Integer> sd = new HashMap<Character, Integer>();
for (char Letter : (s1 + s2).toCharArray()) { for (char Letter : (s1 + s2).toCharArray()) {
if (!sd.containsKey(Letter)) sd.put(Letter, 0); if (!sd.containsKey(Letter)) {
sd.put(Letter, 0);
}
} }
for (int i = 1; i <= s1Len; i++) { for (int i = 1; i <= s1Len; i++) {