Patterns too

This commit is contained in:
Aikar
2017-01-07 15:09:15 -05:00
parent 2ff4d919a4
commit bbe1cfc49e
8 changed files with 33 additions and 33 deletions
@@ -53,7 +53,7 @@ public abstract class BaseCommand extends Command {
if (rootCmdAlias == null) {
cmd = "__" + self.getSimpleName();
} else {
cmd = Patterns.PIPE.split(rootCmdAlias.value())[0];
cmd = CommandPatterns.PIPE.split(rootCmdAlias.value())[0];
}
cmd = cmd.toLowerCase();
setName(cmd);
@@ -103,7 +103,7 @@ public abstract class BaseCommand extends Command {
if (rootCmdAlias != null) {
List<String> cmdList = new ArrayList<>();
Collections.addAll(cmdList, Patterns.PIPE.split(rootCmdAlias.value().toLowerCase()));
Collections.addAll(cmdList, CommandPatterns.PIPE.split(rootCmdAlias.value().toLowerCase()));
cmdList.remove(cmd);
for (String cmdAlias : cmdList) {
register(cmdAlias, new ForwardingCommand(this));
@@ -119,18 +119,18 @@ public abstract class BaseCommand extends Command {
private void registerSubcommand(Method method, String subCommand) {
subCommand = subCommand.toLowerCase();
final String[] subCommandParts = Patterns.SPACE.split(subCommand);
final String[] subCommandParts = CommandPatterns.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] = Patterns.PIPE.split(subCommandParts[i])[0];
subCommandParts[i] = CommandPatterns.PIPE.split(subCommandParts[i])[0];
}
String prefSubCommand = StringUtils.join(subCommandParts, " ");
final CommandAlias cmdAlias = method.getAnnotation(CommandAlias.class);
final String[] aliasNames = cmdAlias != null ? Patterns.PIPE.split(cmdAlias.value().toLowerCase()) : null;
final String[] aliasNames = cmdAlias != null ? CommandPatterns.PIPE.split(cmdAlias.value().toLowerCase()) : null;
String cmdName = aliasNames != null ? aliasNames[0] : getLabel() + " ";
RegisteredCommand cmd = new RegisteredCommand(this, cmdName, method, prefSubCommand);
@@ -164,7 +164,7 @@ public abstract class BaseCommand extends Command {
ArrayList<String> newList = new ArrayList<>();
if (i < subCommandParts.length) {
for (String s1 : Patterns.PIPE.split(subCommandParts[i])) {
for (String s1 : CommandPatterns.PIPE.split(subCommandParts[i])) {
if (current != null) {
newList.addAll(current.stream().map(s -> s + " " + s1).collect(Collectors.toList()));
} else {
@@ -298,7 +298,7 @@ public abstract class BaseCommand extends Command {
}
String prefCommand = value.prefSubCommand;
final String[] psplit = Patterns.SPACE.split(prefCommand);
final String[] psplit = CommandPatterns.SPACE.split(prefCommand);
cmds.add(psplit[args.length - 1]);
}
}
@@ -325,7 +325,7 @@ public abstract class BaseCommand extends Command {
return args.length < 2 ? super.tabComplete(sender, commandLabel, args) : ImmutableList.of();
}
String[] completions = Patterns.SPACE.split(cmd.complete.value());
String[] completions = CommandPatterns.SPACE.split(cmd.complete.value());
final int argIndex = args.length - 1;
String input = args[argIndex];
@@ -26,14 +26,14 @@ public final class CommandCompletions {
if (completion == null) {
return ImmutableList.of();
}
String[] complete = Patterns.COLON.split(completion, 2);
String[] complete = CommandPatterns.COLON.split(completion, 2);
switch (complete[0]) {
case "@range":
if (complete.length == 1) {
return ImmutableList.of();
}
final String[] ranges = Patterns.DASH.split(complete[1]);
final String[] ranges = CommandPatterns.DASH.split(complete[1]);
int start;
int end;
if (ranges.length != 2) {
@@ -52,7 +52,7 @@ public final class CommandCompletions {
.map(entityType -> CommandUtil.simplifyString(entityType.getName()));
return normal.collect(Collectors.toList());
default:
return Lists.newArrayList(Patterns.PIPE.split(completion));
return Lists.newArrayList(CommandPatterns.PIPE.split(completion));
}
}
}
@@ -23,19 +23,19 @@ public final class CommandLog {
public static void info(String message) {
for (String s : Patterns.NEWLINE.split(message)) {
for (String s : CommandPatterns.NEWLINE.split(message)) {
LOGGER.info(s);
}
}
public static void warn(String message) {
for (String s : Patterns.NEWLINE.split(message)) {
for (String s : CommandPatterns.NEWLINE.split(message)) {
LOGGER.warning(s);
}
}
public static void severe(String message) {
for (String s : Patterns.NEWLINE.split(message)) {
for (String s : CommandPatterns.NEWLINE.split(message)) {
LOGGER.severe(s);
}
}
@@ -16,7 +16,7 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
@SuppressWarnings("WeakerAccess")
public final class Patterns {
public final class CommandPatterns {
public static final Pattern COMMA = Pattern.compile(",");
public static final Pattern NEWLINE = Pattern.compile("\n");
public static final Pattern DASH = Pattern.compile("-");
@@ -33,7 +33,7 @@ public final class Patterns {
private Patterns() {}
private CommandPatterns() {}
@SuppressWarnings("Convert2MethodRef")
static final LoadingCache<String, Pattern> patternCache =
CacheBuilder.newBuilder()
@@ -75,11 +75,11 @@ public final class CommandUtil {
public static void sendMsg(CommandSender player, String message) {
message = color(message);
if (player == null) {
for (String msg : Patterns.NEWLINE.split(message)) {
for (String msg : CommandPatterns.NEWLINE.split(message)) {
CommandLog.info(msg);
}
} else {
for (String msg : Patterns.NEWLINE.split(message)) {
for (String msg : CommandPatterns.NEWLINE.split(message)) {
player.sendMessage(msg);
}
}
@@ -92,7 +92,7 @@ public final class CommandUtil {
if (storedLoc == null) {
return null;
}
String[] args = Patterns.COLON.split(storedLoc);
String[] args = CommandPatterns.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;
@@ -106,7 +106,7 @@ public final class CommandUtil {
}
return loc;
} else if (args.length == 2) {
String[] args2 = Patterns.COMMA.split(args[1]);
String[] args2 = CommandPatterns.COMMA.split(args[1]);
if (args2.length == 3) {
String world = forcedWorld != null ? forcedWorld.getName() : args[0];
double x = Double.parseDouble(args2[0]);
@@ -285,7 +285,7 @@ public final class CommandUtil {
if (str == null) {
return null;
}
return Patterns.NON_ALPHA_NUMERIC.matcher(str.toLowerCase()).replaceAll("");
return CommandPatterns.NON_ALPHA_NUMERIC.matcher(str.toLowerCase()).replaceAll("");
}
public static double round(double x, int scale) {
@@ -379,7 +379,7 @@ public final class CommandUtil {
* @return
*/
public static String replace(String string, String pattern, String repl) {
return replace(string, Patterns.getPattern(Pattern.quote(pattern)), repl);
return replace(string, CommandPatterns.getPattern(Pattern.quote(pattern)), repl);
}
/**
@@ -390,7 +390,7 @@ public final class CommandUtil {
* @return
*/
public static String replacePattern(String string, String pattern, String repl) {
return replace(string, Patterns.getPattern(pattern), repl);
return replace(string, CommandPatterns.getPattern(pattern), repl);
}
/**
* Pure Regex Pattern matching and replacement, no escaping
@@ -411,7 +411,7 @@ public final class CommandUtil {
* @return
*/
public static String replacePatternMatch(String string, String pattern, String repl) {
return replacePatternMatch(string, Patterns.getPattern(pattern), repl);
return replacePatternMatch(string, CommandPatterns.getPattern(pattern), repl);
}
public static String replaceStrings(String string, String... replacements) {
@@ -512,7 +512,7 @@ public final class CommandUtil {
if (s == null) {
return null;
}
return Patterns.NON_PRINTABLE_CHARACTERS.matcher(Normalizer.normalize(s, Form.NFD)).replaceAll("");
return CommandPatterns.NON_PRINTABLE_CHARACTERS.matcher(Normalizer.normalize(s, Form.NFD)).replaceAll("");
}
public static int indexOf(String arg, String[] split) {
@@ -744,7 +744,7 @@ public final class CommandUtil {
}
public static boolean isInteger(String string) {
if (!Patterns.INTEGER.matcher(string).matches()) {
if (!CommandPatterns.INTEGER.matcher(string).matches()) {
return false;
}
return true;
@@ -834,6 +834,6 @@ public final class CommandUtil {
}
public static boolean isValidName(String name) {
return name != null && !name.isEmpty() && Patterns.VALID_NAME_PATTERN.matcher(name).matches();
return name != null && !name.isEmpty() && CommandPatterns.VALID_NAME_PATTERN.matcher(name).matches();
}
}
@@ -132,7 +132,7 @@ public class RegisteredCommand {
if (values != null) {
String arg = args.get(0);
final String[] split = Patterns.PIPE.split(values.value());
final String[] split = CommandPatterns.PIPE.split(values.value());
Set<String> possible = Sets.newHashSet();
for (String s : split) {
List<String> check = CommandCompletions.of(sender, s, arg);
@@ -13,7 +13,7 @@ import co.aikar.commands.annotation.Split;
import co.aikar.commands.annotation.Optional;
import co.aikar.commands.annotation.Values;
import co.aikar.commands.CommandLog;
import co.aikar.commands.Patterns;
import co.aikar.commands.CommandPatterns;
import co.aikar.commands.SneakyThrow;
import co.aikar.commands.CommandUtil;
import com.google.common.collect.Maps;
@@ -94,7 +94,7 @@ public final class CommandContexts {
if (val.isEmpty()) {
throw new InvalidCommandArgument();
}
return Patterns.getPattern(split.value()).split(val);
return CommandPatterns.getPattern(split.value()).split(val);
} else if (!c.isLastArg()) {
SneakyThrow.sneaky(new InvalidConfigurationException("Weird Command signature... String[] should be last or @Split"));
}
@@ -11,7 +11,7 @@ import co.aikar.commands.RegisteredCommand;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Flags;
import co.aikar.commands.annotation.Optional;
import co.aikar.commands.Patterns;
import co.aikar.commands.CommandPatterns;
import co.aikar.commands.CommandUtil;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
@@ -42,8 +42,8 @@ import java.util.Map;
Flags flags = param.getAnnotation(Flags.class);
if (flags != null) {
this.flags = Maps.newHashMap();
for (String s : Patterns.COMMA.split(flags.value())) {
String[] v = Patterns.EQUALS.split(s, 2);
for (String s : CommandPatterns.COMMA.split(flags.value())) {
String[] v = CommandPatterns.EQUALS.split(s, 2);
this.flags.put(v[0], v.length > 1 ? v[1] : null);
}
} else {