Move most API of CommandParts to util classes
Gradual transition to removing CommandParts altogether. - Move logic from CommandParts to utils classes
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class CommandUtils {
|
||||
|
||||
public static int getMinNumberOfArguments(CommandDescription command) {
|
||||
@@ -16,4 +22,37 @@ public final class CommandUtils {
|
||||
return command.getArguments().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a textual representation of a list of labels to show it as a command. For example, a list containing
|
||||
* the items ["authme", "register", "player"] it will return "authme register player".
|
||||
*
|
||||
* @param labels The labels to format
|
||||
* @return The space-separated labels
|
||||
*/
|
||||
public static String labelsToString(Iterable<String> labels) {
|
||||
return StringUtils.join(" ", labels);
|
||||
}
|
||||
|
||||
public static double getDifference(List<String> labels1, List<String> labels2, boolean fullCompare) {
|
||||
// Make sure the other reference is correct
|
||||
if (labels1 == null || labels2 == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the range to use
|
||||
int range = Math.min(labels1.size(), labels2.size());
|
||||
|
||||
// Get and the difference
|
||||
if (fullCompare) {
|
||||
return StringUtils.getDifference(CommandUtils.labelsToString(labels1), CommandUtils.labelsToString(labels2));
|
||||
}
|
||||
return StringUtils.getDifference(
|
||||
labelsToString(CollectionUtils.getRange(labels1, range - 1, 1)),
|
||||
labelsToString(CollectionUtils.getRange(labels2, range - 1, 1)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user