mirror of
https://github.com/aikar/commands.git
synced 2026-06-10 02:07:36 +00:00
Rename stuff to ACF and expose util- Fixes #14
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="JavaDoc" enabled="false" level="WARNING" enabled_by_default="false">
|
||||
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="INNER_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="METHOD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="FIELD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SameParameterValue" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||
<option name="processCode" value="true" />
|
||||
<option name="processLiterals" value="true" />
|
||||
<option name="processComments" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
+5
-5
@@ -29,10 +29,10 @@ import org.bukkit.Bukkit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
final class CommandLog {
|
||||
final class ACFLog {
|
||||
private static final Logger LOGGER = Bukkit.getLogger();
|
||||
|
||||
private CommandLog() {}
|
||||
private ACFLog() {}
|
||||
|
||||
|
||||
public static void log(String message) {
|
||||
@@ -41,19 +41,19 @@ final class CommandLog {
|
||||
|
||||
|
||||
public static void info(String message) {
|
||||
for (String s : CommandPatterns.NEWLINE.split(message)) {
|
||||
for (String s : ACFPatterns.NEWLINE.split(message)) {
|
||||
LOGGER.info(s);
|
||||
}
|
||||
}
|
||||
|
||||
public static void warn(String message) {
|
||||
for (String s : CommandPatterns.NEWLINE.split(message)) {
|
||||
for (String s : ACFPatterns.NEWLINE.split(message)) {
|
||||
LOGGER.warning(s);
|
||||
}
|
||||
}
|
||||
|
||||
public static void severe(String message) {
|
||||
for (String s : CommandPatterns.NEWLINE.split(message)) {
|
||||
for (String s : ACFPatterns.NEWLINE.split(message)) {
|
||||
LOGGER.severe(s);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
final class CommandPatterns {
|
||||
final class ACFPatterns {
|
||||
public static final Pattern COMMA = Pattern.compile(",");
|
||||
public static final Pattern NEWLINE = Pattern.compile("\n");
|
||||
public static final Pattern DASH = Pattern.compile("-");
|
||||
@@ -49,7 +49,7 @@ final class CommandPatterns {
|
||||
|
||||
|
||||
|
||||
private CommandPatterns() {}
|
||||
private ACFPatterns() {}
|
||||
@SuppressWarnings("Convert2MethodRef")
|
||||
static final LoadingCache<String, Pattern> patternCache =
|
||||
CacheBuilder.newBuilder()
|
||||
+27
-30
@@ -53,12 +53,12 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
final class CommandUtil {
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
public final class ACFUtil {
|
||||
|
||||
public static final Random RANDOM = new Random();
|
||||
|
||||
private CommandUtil() {}
|
||||
private ACFUtil() {}
|
||||
|
||||
public static String padRight(String s, int n) {
|
||||
return String.format("%1$-" + n + "s", s);
|
||||
@@ -92,11 +92,11 @@ final class CommandUtil {
|
||||
public static void sendMsg(CommandSender player, String message) {
|
||||
message = color(message);
|
||||
if (player == null) {
|
||||
for (String msg : CommandPatterns.NEWLINE.split(message)) {
|
||||
CommandLog.info(msg);
|
||||
for (String msg : ACFPatterns.NEWLINE.split(message)) {
|
||||
ACFLog.info(msg);
|
||||
}
|
||||
} else {
|
||||
for (String msg : CommandPatterns.NEWLINE.split(message)) {
|
||||
for (String msg : ACFPatterns.NEWLINE.split(message)) {
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ final class CommandUtil {
|
||||
if (storedLoc == null) {
|
||||
return null;
|
||||
}
|
||||
String[] args = CommandPatterns.COLON.split(storedLoc);
|
||||
String[] args = ACFPatterns.COLON.split(storedLoc);
|
||||
if (args.length >= 4 || (args.length == 3 && forcedWorld != null)) {
|
||||
String world = forcedWorld != null ? forcedWorld.getName() : args[0];
|
||||
int i = args.length == 3 ? 0 : 1;
|
||||
@@ -123,7 +123,7 @@ final class CommandUtil {
|
||||
}
|
||||
return loc;
|
||||
} else if (args.length == 2) {
|
||||
String[] args2 = CommandPatterns.COMMA.split(args[1]);
|
||||
String[] args2 = ACFPatterns.COMMA.split(args[1]);
|
||||
if (args2.length == 3) {
|
||||
String world = forcedWorld != null ? forcedWorld.getName() : args[0];
|
||||
double x = Double.parseDouble(args2[0]);
|
||||
@@ -270,6 +270,7 @@ final class CommandUtil {
|
||||
}
|
||||
|
||||
public static <T> T nullDefault(Object val, Object def) {
|
||||
//noinspection unchecked
|
||||
return (T) (val != null ? val : def);
|
||||
}
|
||||
|
||||
@@ -302,7 +303,7 @@ final class CommandUtil {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
return CommandPatterns.NON_ALPHA_NUMERIC.matcher(str.toLowerCase()).replaceAll("");
|
||||
return ACFPatterns.NON_ALPHA_NUMERIC.matcher(str.toLowerCase()).replaceAll("");
|
||||
}
|
||||
|
||||
public static double round(double x, int scale) {
|
||||
@@ -333,7 +334,7 @@ final class CommandUtil {
|
||||
}
|
||||
|
||||
public static String removeColors(String msg) {
|
||||
return ChatColor.stripColor(CommandUtil.color(msg));
|
||||
return ChatColor.stripColor(ACFUtil.color(msg));
|
||||
|
||||
}
|
||||
|
||||
@@ -396,7 +397,7 @@ final class CommandUtil {
|
||||
* @return
|
||||
*/
|
||||
public static String replace(String string, String pattern, String repl) {
|
||||
return replace(string, CommandPatterns.getPattern(Pattern.quote(pattern)), repl);
|
||||
return replace(string, ACFPatterns.getPattern(Pattern.quote(pattern)), repl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -407,7 +408,7 @@ final class CommandUtil {
|
||||
* @return
|
||||
*/
|
||||
public static String replacePattern(String string, String pattern, String repl) {
|
||||
return replace(string, CommandPatterns.getPattern(pattern), repl);
|
||||
return replace(string, ACFPatterns.getPattern(pattern), repl);
|
||||
}
|
||||
/**
|
||||
* Pure Regex Pattern matching and replacement, no escaping
|
||||
@@ -428,7 +429,7 @@ final class CommandUtil {
|
||||
* @return
|
||||
*/
|
||||
public static String replacePatternMatch(String string, String pattern, String repl) {
|
||||
return replacePatternMatch(string, CommandPatterns.getPattern(pattern), repl);
|
||||
return replacePatternMatch(string, ACFPatterns.getPattern(pattern), repl);
|
||||
}
|
||||
|
||||
public static String replaceStrings(String string, String... replacements) {
|
||||
@@ -529,7 +530,7 @@ final class CommandUtil {
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
return CommandPatterns.NON_PRINTABLE_CHARACTERS.matcher(Normalizer.normalize(s, Form.NFD)).replaceAll("");
|
||||
return ACFPatterns.NON_PRINTABLE_CHARACTERS.matcher(Normalizer.normalize(s, Form.NFD)).replaceAll("");
|
||||
}
|
||||
|
||||
public static int indexOf(String arg, String[] split) {
|
||||
@@ -635,9 +636,9 @@ final class CommandUtil {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
item = CommandUtil.simplifyString(item);
|
||||
item = ACFUtil.simplifyString(item);
|
||||
for (Enum<?> s : list.getEnumConstants()) {
|
||||
String simple = CommandUtil.simplifyString(s.name());
|
||||
String simple = ACFUtil.simplifyString(s.name());
|
||||
if (item.equals(simple)) {
|
||||
return s;
|
||||
}
|
||||
@@ -761,14 +762,12 @@ final class CommandUtil {
|
||||
}
|
||||
|
||||
public static boolean isInteger(String string) {
|
||||
if (!CommandPatterns.INTEGER.matcher(string).matches()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return ACFPatterns.INTEGER.matcher(string).matches();
|
||||
}
|
||||
|
||||
public static boolean isFloat(String string) {
|
||||
try {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
Float.parseFloat(string);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
@@ -778,6 +777,7 @@ final class CommandUtil {
|
||||
|
||||
public static boolean isDouble(String string) {
|
||||
try {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
Double.parseDouble(string);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
@@ -786,20 +786,17 @@ final class CommandUtil {
|
||||
}
|
||||
|
||||
public static boolean isBetween(float num, double min, double max) {
|
||||
if (num >= min && num <= max){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return num >= min && num <= max;
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
public static double precision(double x, int p) {
|
||||
double pow = Math.pow(10, p);
|
||||
return Math.round(x * pow) / pow;
|
||||
}
|
||||
|
||||
public static Player findPlayerSmart(CommandSender requester, String origname) {
|
||||
String name = replace(origname, ":confirm", "");
|
||||
public static Player findPlayerSmart(CommandSender requester, String origName) {
|
||||
String name = replace(origName, ":confirm", "");
|
||||
if (name.length() < 3) {
|
||||
requester.sendMessage("§cUsername too short, must be at least three characters");
|
||||
return null;
|
||||
@@ -818,7 +815,7 @@ final class CommandUtil {
|
||||
Player player = iter.next();
|
||||
if (requester instanceof Player && !((Player) requester).canSee(player)) {
|
||||
if (requester.hasPermission("command.seevanish")) {
|
||||
if (!origname.endsWith(":confirm")) {
|
||||
if (!origName.endsWith(":confirm")) {
|
||||
confirmList.add(player);
|
||||
iter.remove();
|
||||
}
|
||||
@@ -851,12 +848,12 @@ final class CommandUtil {
|
||||
}
|
||||
|
||||
public static boolean isValidName(String name) {
|
||||
return name != null && !name.isEmpty() && CommandPatterns.VALID_NAME_PATTERN.matcher(name).matches();
|
||||
return name != null && !name.isEmpty() && ACFPatterns.VALID_NAME_PATTERN.matcher(name).matches();
|
||||
}
|
||||
|
||||
public static void sneaky(Throwable t) {
|
||||
//noinspection RedundantTypeArguments
|
||||
throw CommandUtil.<RuntimeException>superSneaky( t );
|
||||
throw ACFUtil.<RuntimeException>superSneaky( t );
|
||||
}
|
||||
|
||||
private static <T extends Throwable> T superSneaky(Throwable t) throws T {
|
||||
@@ -106,7 +106,7 @@ public abstract class BaseCommand extends Command {
|
||||
if (rootCmdAlias == null) {
|
||||
cmd = "__" + self.getSimpleName();
|
||||
} else {
|
||||
cmd = CommandPatterns.PIPE.split(rootCmdAlias.value())[0];
|
||||
cmd = ACFPatterns.PIPE.split(rootCmdAlias.value())[0];
|
||||
}
|
||||
cmd = cmd.toLowerCase();
|
||||
try {
|
||||
@@ -118,7 +118,7 @@ public abstract class BaseCommand extends Command {
|
||||
field.setAccessible(true);
|
||||
field.set(this, cmd);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
CommandLog.exception("Error setting name for command", e);
|
||||
ACFLog.exception("Error setting name for command", e);
|
||||
}
|
||||
}
|
||||
setLabel(cmd);
|
||||
@@ -146,7 +146,7 @@ public abstract class BaseCommand extends Command {
|
||||
registerSubcommand(method, "__default");
|
||||
foundDefault = true;
|
||||
} else {
|
||||
CommandUtil.sneaky(new InvalidConfigurationException("Multiple @Default commands"));
|
||||
ACFUtil.sneaky(new InvalidConfigurationException("Multiple @Default commands"));
|
||||
}
|
||||
}
|
||||
if (sub != null) {
|
||||
@@ -168,7 +168,7 @@ public abstract class BaseCommand extends Command {
|
||||
|
||||
if (rootCmdAlias != null) {
|
||||
List<String> cmdList = new ArrayList<>();
|
||||
Collections.addAll(cmdList, CommandPatterns.PIPE.split(rootCmdAlias.value().toLowerCase()));
|
||||
Collections.addAll(cmdList, ACFPatterns.PIPE.split(rootCmdAlias.value().toLowerCase()));
|
||||
cmdList.remove(cmd);
|
||||
for (String cmdAlias : cmdList) {
|
||||
register(cmdAlias, new ForwardingCommand(this));
|
||||
@@ -184,18 +184,18 @@ public abstract class BaseCommand extends Command {
|
||||
|
||||
private void registerSubcommand(Method method, String subCommand) {
|
||||
subCommand = subCommand.toLowerCase();
|
||||
final String[] subCommandParts = CommandPatterns.SPACE.split(subCommand);
|
||||
final String[] subCommandParts = ACFPatterns.SPACE.split(subCommand);
|
||||
// Must run getSubcommandPossibility BEFORE we rewrite it just after this.
|
||||
List<String> cmdList = getSubCommandPossibilityList(subCommandParts);
|
||||
|
||||
// Strip pipes off for auto complete addition
|
||||
for (int i = 0; i < subCommandParts.length; i++) {
|
||||
subCommandParts[i] = CommandPatterns.PIPE.split(subCommandParts[i])[0];
|
||||
subCommandParts[i] = ACFPatterns.PIPE.split(subCommandParts[i])[0];
|
||||
}
|
||||
String prefSubCommand = StringUtils.join(subCommandParts, " ");
|
||||
final CommandAlias cmdAlias = method.getAnnotation(CommandAlias.class);
|
||||
|
||||
final String[] aliasNames = cmdAlias != null ? CommandPatterns.PIPE.split(cmdAlias.value().toLowerCase()) : null;
|
||||
final String[] aliasNames = cmdAlias != null ? ACFPatterns.PIPE.split(cmdAlias.value().toLowerCase()) : null;
|
||||
String cmdName = aliasNames != null ? aliasNames[0] : getLabel() + " ";
|
||||
RegisteredCommand cmd = new RegisteredCommand(this, cmdName, method, prefSubCommand);
|
||||
|
||||
@@ -229,7 +229,7 @@ public abstract class BaseCommand extends Command {
|
||||
ArrayList<String> newList = new ArrayList<>();
|
||||
|
||||
if (i < subCommandParts.length) {
|
||||
for (String s1 : CommandPatterns.PIPE.split(subCommandParts[i])) {
|
||||
for (String s1 : ACFPatterns.PIPE.split(subCommandParts[i])) {
|
||||
if (current != null) {
|
||||
newList.addAll(current.stream().map(s -> s + " " + s1).collect(Collectors.toList()));
|
||||
} else {
|
||||
@@ -330,7 +330,7 @@ public abstract class BaseCommand extends Command {
|
||||
cmd.invoke(sender, sargs);
|
||||
}
|
||||
} else {
|
||||
CommandUtil.sendMsg(sender, "&cI'm sorry, but you do not have permission to perform this command.");
|
||||
ACFUtil.sendMsg(sender, "&cI'm sorry, but you do not have permission to perform this command.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ public abstract class BaseCommand extends Command {
|
||||
}
|
||||
String prefCommand = value.prefSubCommand;
|
||||
|
||||
final String[] psplit = CommandPatterns.SPACE.split(prefCommand);
|
||||
final String[] psplit = ACFPatterns.SPACE.split(prefCommand);
|
||||
cmds.add(psplit[args.length - 1]);
|
||||
}
|
||||
}
|
||||
@@ -392,7 +392,7 @@ public abstract class BaseCommand extends Command {
|
||||
return args.length < 2 ? super.tabComplete(sender, commandLabel, args) : ImmutableList.of();
|
||||
}
|
||||
|
||||
String[] completions = CommandPatterns.SPACE.split(cmd.complete.value());
|
||||
String[] completions = ACFPatterns.SPACE.split(cmd.complete.value());
|
||||
final int argIndex = args.length - 1;
|
||||
|
||||
String input = args[argIndex];
|
||||
@@ -413,7 +413,7 @@ public abstract class BaseCommand extends Command {
|
||||
}
|
||||
|
||||
public void help(CommandSender sender, String[] args) {
|
||||
CommandUtil.sendMsg(sender, "&cUnknown Command, please type &f/help");
|
||||
ACFUtil.sendMsg(sender, "&cUnknown Command, please type &f/help");
|
||||
}
|
||||
|
||||
public void onDefault(CommandSender sender, String commandLabel) {
|
||||
@@ -447,7 +447,7 @@ public abstract class BaseCommand extends Command {
|
||||
}
|
||||
|
||||
public void showSyntax(CommandSender sender, RegisteredCommand cmd) {
|
||||
CommandUtil.sendMsg(sender, "&cUsage: /" + cmd.command + " " + cmd.syntaxText);
|
||||
ACFUtil.sendMsg(sender, "&cUsage: /" + cmd.command + " " + cmd.syntaxText);
|
||||
}
|
||||
|
||||
private static class CommandSearch { RegisteredCommand cmd; int argIndex; String checkSub;
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@@ -32,8 +31,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -43,7 +40,7 @@ public class BukkitCommandCompletions extends CommandCompletions {
|
||||
super();
|
||||
registerCompletion("mobs", (sender, completionConfig, input) -> {
|
||||
final Stream<String> normal = Stream.of(EntityType.values())
|
||||
.map(entityType -> CommandUtil.simplifyString(entityType.getName()));
|
||||
.map(entityType -> ACFUtil.simplifyString(entityType.getName()));
|
||||
return normal.collect(Collectors.toList());
|
||||
});
|
||||
registerCompletion("worlds", (sender, completionConfig, input) -> (
|
||||
|
||||
@@ -40,9 +40,9 @@ public class BukkitCommandContexts extends CommandContexts {
|
||||
|
||||
registerContext(OnlinePlayer.class, (c) -> {
|
||||
final String playercheck = c.popFirstArg();
|
||||
Player player = CommandUtil.findPlayerSmart(c.getSender(), playercheck);
|
||||
Player player = ACFUtil.findPlayerSmart(c.getSender(), playercheck);
|
||||
if (player == null) {
|
||||
CommandUtil.sendMsg(c.getSender(), "&cCould not find a player by the name " + playercheck);
|
||||
ACFUtil.sendMsg(c.getSender(), "&cCould not find a player by the name " + playercheck);
|
||||
throw new InvalidCommandArgument(false);
|
||||
}
|
||||
return new OnlinePlayer(player);
|
||||
@@ -68,7 +68,7 @@ public class BukkitCommandContexts extends CommandContexts {
|
||||
throw new InvalidCommandArgument("Requires a player to run this command", false);
|
||||
}
|
||||
PlayerInventory inventory = player != null ? player.getInventory() : null;
|
||||
if (inventory != null && c.hasFlag("itemheld") && !CommandUtil.isValidItem(inventory.getItem(inventory.getHeldItemSlot()))) {
|
||||
if (inventory != null && c.hasFlag("itemheld") && !ACFUtil.isValidItem(inventory.getItem(inventory.getHeldItemSlot()))) {
|
||||
throw new InvalidCommandArgument("You must be holding an item in your main hand.", false);
|
||||
}
|
||||
return player;
|
||||
|
||||
@@ -43,15 +43,15 @@ public class CommandCompletions {
|
||||
if (completionConfig == null) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
final String[] ranges = CommandPatterns.DASH.split(completionConfig);
|
||||
final String[] ranges = ACFPatterns.DASH.split(completionConfig);
|
||||
int start;
|
||||
int end;
|
||||
if (ranges.length != 2) {
|
||||
start = 0;
|
||||
end = CommandUtil.parseInt(ranges[0], 0);
|
||||
end = ACFUtil.parseInt(ranges[0], 0);
|
||||
} else {
|
||||
start = CommandUtil.parseInt(ranges[0], 0);
|
||||
end = CommandUtil.parseInt(ranges[1], 0);
|
||||
start = ACFUtil.parseInt(ranges[0], 0);
|
||||
end = ACFUtil.parseInt(ranges[1], 0);
|
||||
}
|
||||
return IntStream.rangeClosed(start, end).mapToObj(Integer::toString).collect(Collectors.toList());
|
||||
});
|
||||
@@ -70,7 +70,7 @@ public class CommandCompletions {
|
||||
input = "";
|
||||
}
|
||||
|
||||
String[] complete = CommandPatterns.COLON.split(completion, 2);
|
||||
String[] complete = ACFPatterns.COLON.split(completion, 2);
|
||||
|
||||
CommandCompletionHandler handler = this.completionMap.get(complete[0].toLowerCase());
|
||||
if (handler != null) {
|
||||
@@ -81,7 +81,7 @@ public class CommandCompletions {
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
return Lists.newArrayList(CommandPatterns.PIPE.split(completion));
|
||||
return Lists.newArrayList(ACFPatterns.PIPE.split(completion));
|
||||
}
|
||||
|
||||
public interface CommandCompletionHandler {
|
||||
|
||||
@@ -41,14 +41,14 @@ public class CommandContexts {
|
||||
CommandContexts() {
|
||||
registerContext(Integer.class, (c) -> {
|
||||
try {
|
||||
return CommandUtil.parseNumber(c.popFirstArg(), c.hasFlag("suffixes")).intValue();
|
||||
return ACFUtil.parseNumber(c.popFirstArg(), c.hasFlag("suffixes")).intValue();
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InvalidCommandArgument("Must be a number");
|
||||
}
|
||||
});
|
||||
registerContext(Long.class, (c) -> {
|
||||
try {
|
||||
return CommandUtil.parseNumber(c.popFirstArg(), c.hasFlag("suffixes")).longValue();
|
||||
return ACFUtil.parseNumber(c.popFirstArg(), c.hasFlag("suffixes")).longValue();
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InvalidCommandArgument("Must be a number");
|
||||
}
|
||||
@@ -56,40 +56,40 @@ public class CommandContexts {
|
||||
});
|
||||
registerContext(Float.class, (c) -> {
|
||||
try {
|
||||
return CommandUtil.parseNumber(c.popFirstArg(), c.hasFlag("suffixes")).floatValue();
|
||||
return ACFUtil.parseNumber(c.popFirstArg(), c.hasFlag("suffixes")).floatValue();
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InvalidCommandArgument("Must be a number");
|
||||
}
|
||||
});
|
||||
registerContext(Double.class, (c) -> {
|
||||
try {
|
||||
return CommandUtil.parseNumber(c.popFirstArg(), c.hasFlag("suffixes")).doubleValue();
|
||||
return ACFUtil.parseNumber(c.popFirstArg(), c.hasFlag("suffixes")).doubleValue();
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InvalidCommandArgument("Must be a number");
|
||||
}
|
||||
});
|
||||
registerContext(Number.class, (c) -> {
|
||||
try {
|
||||
return CommandUtil.parseNumber(c.popFirstArg(), c.hasFlag("suffixes"));
|
||||
return ACFUtil.parseNumber(c.popFirstArg(), c.hasFlag("suffixes"));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InvalidCommandArgument("Must be a number");
|
||||
}
|
||||
});
|
||||
registerContext(Boolean.class, (c) -> CommandUtil.isTruthy(c.popFirstArg()));
|
||||
registerContext(Boolean.class, (c) -> ACFUtil.isTruthy(c.popFirstArg()));
|
||||
registerContext(String.class, (c) -> {
|
||||
final Values values = c.getParam().getAnnotation(Values.class);
|
||||
if (values != null) {
|
||||
return c.popFirstArg();
|
||||
}
|
||||
if (c.isLastArg() && c.getParam().getAnnotation(Single.class) == null) {
|
||||
return CommandUtil.join(c.getArgs());
|
||||
return ACFUtil.join(c.getArgs());
|
||||
}
|
||||
return c.popFirstArg();
|
||||
});
|
||||
registerContext(String[].class, (c) -> {
|
||||
String val;
|
||||
if (c.isLastArg() && c.getParam().getAnnotation(Single.class) == null) {
|
||||
val = CommandUtil.join(c.getArgs());
|
||||
val = ACFUtil.join(c.getArgs());
|
||||
} else {
|
||||
val = c.popFirstArg();
|
||||
}
|
||||
@@ -98,9 +98,9 @@ public class CommandContexts {
|
||||
if (val.isEmpty()) {
|
||||
throw new InvalidCommandArgument();
|
||||
}
|
||||
return CommandPatterns.getPattern(split.value()).split(val);
|
||||
return ACFPatterns.getPattern(split.value()).split(val);
|
||||
} else if (!c.isLastArg()) {
|
||||
CommandUtil.sneaky(new InvalidConfigurationException("Weird Command signature... String[] should be last or @Split"));
|
||||
ACFUtil.sneaky(new InvalidConfigurationException("Weird Command signature... String[] should be last or @Split"));
|
||||
}
|
||||
|
||||
String[] result = c.getArgs().toArray(new String[c.getArgs().size()]);
|
||||
@@ -111,10 +111,10 @@ public class CommandContexts {
|
||||
registerContext(Enum.class, (c) -> {
|
||||
final String first = c.popFirstArg();
|
||||
Class<? extends Enum<?>> enumCls = (Class<? extends Enum<?>>) c.getParam().getType();
|
||||
Enum<?> match = CommandUtil.simpleMatch(enumCls, first);
|
||||
Enum<?> match = ACFUtil.simpleMatch(enumCls, first);
|
||||
if (match == null) {
|
||||
List<String> names = CommandUtil.enumNames(enumCls);
|
||||
throw new InvalidCommandArgument("Please specify one of: " + CommandUtil.join(names));
|
||||
List<String> names = ACFUtil.enumNames(enumCls);
|
||||
throw new InvalidCommandArgument("Please specify one of: " + ACFUtil.join(names));
|
||||
}
|
||||
return match;
|
||||
});
|
||||
@@ -140,7 +140,7 @@ public class CommandContexts {
|
||||
}
|
||||
} while ((type = type.getSuperclass()) != null);
|
||||
|
||||
CommandLog.exception(new InvalidConfigurationException("No context resolver defined for " + rootType.getName()));
|
||||
ACFLog.exception(new InvalidConfigurationException("No context resolver defined for " + rootType.getName()));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ public class CommandExecutionContext {
|
||||
Flags flags = param.getAnnotation(Flags.class);
|
||||
if (flags != null) {
|
||||
this.flags = Maps.newHashMap();
|
||||
for (String s : CommandPatterns.COMMA.split(flags.value())) {
|
||||
String[] v = CommandPatterns.EQUALS.split(s, 2);
|
||||
for (String s : ACFPatterns.COMMA.split(flags.value())) {
|
||||
String[] v = ACFPatterns.EQUALS.split(s, 2);
|
||||
this.flags.put(v[0], v.length > 1 ? v[1] : null);
|
||||
}
|
||||
} else {
|
||||
@@ -138,7 +138,7 @@ public class CommandExecutionContext {
|
||||
}
|
||||
|
||||
public Integer getFlagValue(String flag, Integer def) {
|
||||
return CommandUtil.parseInt(this.flags.get(flag), def);
|
||||
return ACFUtil.parseInt(this.flags.get(flag), def);
|
||||
}
|
||||
|
||||
public <T extends Annotation> T getAnnotation(Class<T> cls) {
|
||||
|
||||
@@ -106,7 +106,7 @@ public class RegisteredCommand {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
CommandUtil.sneaky(new InvalidConfigurationException(
|
||||
ACFUtil.sneaky(new InvalidConfigurationException(
|
||||
"Parameter " + type.getSimpleName() + " of " + this.command + " has no resolver"
|
||||
));
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class RegisteredCommand {
|
||||
if (values != null) {
|
||||
String arg = args.get(0);
|
||||
|
||||
final String[] split = CommandPatterns.PIPE.split(values.value());
|
||||
final String[] split = ACFPatterns.PIPE.split(values.value());
|
||||
Set<String> possible = Sets.newHashSet();
|
||||
for (String s : split) {
|
||||
List<String> check = this.scope.manager.getCommandCompletions().of(sender, s, arg);
|
||||
@@ -163,7 +163,7 @@ public class RegisteredCommand {
|
||||
}
|
||||
|
||||
if (!possible.contains(arg.toLowerCase())) {
|
||||
throw new InvalidCommandArgument("Must be one of: " + CommandUtil.join(possible, ", "));
|
||||
throw new InvalidCommandArgument("Must be one of: " + ACFUtil.join(possible, ", "));
|
||||
}
|
||||
}
|
||||
passedArgs.put(parameterName, resolver.getContext(context));
|
||||
@@ -177,21 +177,21 @@ public class RegisteredCommand {
|
||||
if (e instanceof InvalidCommandArgument) {
|
||||
|
||||
if (e.getMessage() != null && !e.getMessage().isEmpty()) {
|
||||
CommandUtil.sendMsg(sender, "&cError: " + e.getMessage());
|
||||
ACFUtil.sendMsg(sender, "&cError: " + e.getMessage());
|
||||
}
|
||||
if (((InvalidCommandArgument) e).showSyntax) {
|
||||
scope.showSyntax(sender, this);
|
||||
}
|
||||
} else {
|
||||
CommandUtil.sendMsg(sender, "&cI'm sorry, but there was an error performing this command.");
|
||||
CommandLog.exception("Exception in command: " + command + " " + CommandUtil.join(args), e);
|
||||
ACFUtil.sendMsg(sender, "&cI'm sorry, but there was an error performing this command.");
|
||||
ACFLog.exception("Exception in command: " + command + " " + ACFUtil.join(args), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CommandTiming getTiming() {
|
||||
if (this.timing == null) {
|
||||
this.timing = CommandUtil.getTiming(scope, command);
|
||||
this.timing = ACFUtil.getTiming(scope, command);
|
||||
}
|
||||
return this.timing;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user