mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
committed by
Daniel Ennis
parent
786ebe831f
commit
3c979a9ef2
@@ -11,6 +11,7 @@
|
||||
.idea/kotlinc.xml
|
||||
.idea/modules.xml
|
||||
.idea/usage.statistics.xml
|
||||
.idea/checkstyle-idea.xml
|
||||
**/*.iml
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ package co.aikar.commands;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
import org.bukkit.command.Command;
|
||||
|
||||
@@ -26,7 +26,6 @@ package co.aikar.commands;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -576,6 +577,17 @@ public final class ACFUtil {
|
||||
throw (T) t;
|
||||
}
|
||||
|
||||
public static <T> List<T> preformOnImmutable(List<T> list, Consumer<List<T>> action) {
|
||||
try {
|
||||
action.accept(list);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
list = new ArrayList<>(list);
|
||||
action.accept(list);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static class ApplyModifierToNumber {
|
||||
private String num;
|
||||
private boolean suffixes;
|
||||
|
||||
@@ -33,17 +33,17 @@ import java.util.Map;
|
||||
@SuppressWarnings("TypeParameterExplicitlyExtendsObject")
|
||||
class Annotations <M extends CommandManager> extends AnnotationLookups {
|
||||
|
||||
public static int NOTHING = 0;
|
||||
public static int REPLACEMENTS = 1;
|
||||
public static int LOWERCASE = 1 << 1;
|
||||
public static int UPPERCASE = 1 << 2;
|
||||
public static int NO_EMPTY = 1 << 3;
|
||||
public static int DEFAULT_EMPTY = 1 << 4;
|
||||
public static final int NOTHING = 0;
|
||||
public static final int REPLACEMENTS = 1;
|
||||
public static final int LOWERCASE = 1 << 1;
|
||||
public static final int UPPERCASE = 1 << 2;
|
||||
public static final int NO_EMPTY = 1 << 3;
|
||||
public static final int DEFAULT_EMPTY = 1 << 4;
|
||||
|
||||
private final M manager;
|
||||
|
||||
private Map<Class<? extends Annotation>, Method> valueMethods = new IdentityHashMap<>();
|
||||
private Map<Class<? extends Annotation>, Void> noValueAnnotations = new IdentityHashMap<>();
|
||||
private final Map<Class<? extends Annotation>, Method> valueMethods = new IdentityHashMap<>();
|
||||
private final Map<Class<? extends Annotation>, Void> noValueAnnotations = new IdentityHashMap<>();
|
||||
|
||||
Annotations(M manager) {
|
||||
this.manager = manager;
|
||||
|
||||
@@ -35,13 +35,8 @@ import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.UnknownHandler;
|
||||
import co.aikar.commands.apachecommonslang.ApacheCommonsLangUtil;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -95,7 +90,7 @@ public abstract class BaseCommand {
|
||||
/**
|
||||
* A map of flags to pass to Context Resolution for every parameter of the type. This is like an automatic @Flags on each.
|
||||
*/
|
||||
final Map<Class<?>, String> contextFlags = Maps.newHashMap();
|
||||
final Map<Class<?>, String> contextFlags = new HashMap<>();
|
||||
|
||||
/**
|
||||
* What method was annoated with {@link PreCommand} to execute before commands.
|
||||
@@ -653,7 +648,7 @@ public abstract class BaseCommand {
|
||||
if (checkPrecommand(commandOperationContext, cmd, issuer, args)) {
|
||||
return;
|
||||
}
|
||||
List<String> sargs = Lists.newArrayList(args);
|
||||
List<String> sargs = Arrays.asList(args);
|
||||
cmd.invoke(issuer, sargs, commandOperationContext);
|
||||
} else {
|
||||
issuer.sendMessage(MessageType.ERROR, MessageKeys.PERMISSION_DENIED);
|
||||
@@ -780,7 +775,7 @@ public abstract class BaseCommand {
|
||||
*/
|
||||
private List<String> completeCommand(CommandIssuer issuer, RegisteredCommand cmd, String[] args, String commandLabel, boolean isAsync) {
|
||||
if (!cmd.hasPermission(issuer) || args.length > cmd.consumeInputResolvers || args.length == 0 || cmd.complete == null) {
|
||||
return ImmutableList.of();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<String> cmds = manager.getCommandCompletions().of(cmd, issuer, args, isAsync);
|
||||
@@ -949,9 +944,9 @@ public abstract class BaseCommand {
|
||||
|
||||
public Set<String> getRequiredPermissions() {
|
||||
if (this.permission == null || this.permission.isEmpty()) {
|
||||
return ImmutableSet.of();
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return Sets.newHashSet(ACFPatterns.COMMA.split(this.permission));
|
||||
return new HashSet<>(Arrays.asList(ACFPatterns.COMMA.split(this.permission)));
|
||||
}
|
||||
|
||||
public boolean requiresPermission(String permission) {
|
||||
|
||||
@@ -23,10 +23,8 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -35,7 +33,7 @@ public class CommandCompletionContext <I extends CommandIssuer> {
|
||||
protected final I issuer;
|
||||
private final String input;
|
||||
private final String config;
|
||||
private final Map<String, String> configs = Maps.newHashMap();
|
||||
private final Map<String, String> configs = new HashMap<>();
|
||||
private final List<String> args;
|
||||
|
||||
CommandCompletionContext(RegisteredCommand command, I issuer, String input, String config, String[] args) {
|
||||
@@ -53,7 +51,7 @@ public class CommandCompletionContext <I extends CommandIssuer> {
|
||||
this.config = null;
|
||||
}
|
||||
|
||||
this.args = Lists.newArrayList(args);
|
||||
this.args = Arrays.asList(args);
|
||||
}
|
||||
|
||||
public Map<String, String> getConfigs() {
|
||||
|
||||
@@ -23,11 +23,12 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -44,11 +45,11 @@ public class CommandCompletions <C extends CommandCompletionContext> {
|
||||
|
||||
public CommandCompletions(CommandManager manager) {
|
||||
this.manager = manager;
|
||||
registerAsyncCompletion("nothing", c -> ImmutableList.of());
|
||||
registerAsyncCompletion("nothing", c -> Collections.emptyList());
|
||||
registerAsyncCompletion("range", (c) -> {
|
||||
String config = c.getConfig();
|
||||
if (config == null) {
|
||||
return ImmutableList.of();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final String[] ranges = ACFPatterns.DASH.split(config);
|
||||
int start;
|
||||
@@ -62,7 +63,8 @@ public class CommandCompletions <C extends CommandCompletionContext> {
|
||||
}
|
||||
return IntStream.rangeClosed(start, end).mapToObj(Integer::toString).collect(Collectors.toList());
|
||||
});
|
||||
registerAsyncCompletion("timeunits", (c) -> ImmutableList.of("minutes", "hours", "days", "weeks", "months", "years"));
|
||||
List<String> timeunits = Arrays.asList("minutes", "hours", "days", "weeks", "months", "years");
|
||||
registerAsyncCompletion("timeunits", (c) -> timeunits);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +119,7 @@ public class CommandCompletions <C extends CommandCompletionContext> {
|
||||
* @return
|
||||
*/
|
||||
public CommandCompletionHandler registerStaticCompletion(String id, String[] completions) {
|
||||
return registerStaticCompletion(id, Lists.newArrayList(completions));
|
||||
return registerStaticCompletion(id, Arrays.asList(completions));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +180,7 @@ public class CommandCompletions <C extends CommandCompletionContext> {
|
||||
completion = completions[completions.length - 1];
|
||||
}
|
||||
if (completion == null) {
|
||||
return ImmutableList.of(input);
|
||||
return Collections.singletonList(input);
|
||||
}
|
||||
|
||||
return getCompletionValues(cmd, sender, completion, args, isAsync);
|
||||
@@ -187,7 +189,7 @@ public class CommandCompletions <C extends CommandCompletionContext> {
|
||||
List<String> getCompletionValues(RegisteredCommand command, CommandIssuer sender, String completion, String[] args, boolean isAsync) {
|
||||
completion = manager.getCommandReplacements().replace(completion);
|
||||
|
||||
List<String> allCompletions = Lists.newArrayList();
|
||||
List<String> allCompletions = new ArrayList<>();
|
||||
String input = args.length > 0 ? args[args.length - 1] : "";
|
||||
|
||||
for (String value : ACFPatterns.PIPE.split(completion)) {
|
||||
@@ -215,10 +217,10 @@ public class CommandCompletions <C extends CommandCompletionContext> {
|
||||
} catch (CommandCompletionTextLookupException ignored) {
|
||||
// This should only happen if some other feedback error occured.
|
||||
} catch (Exception e) {
|
||||
command.handleException(sender, Lists.newArrayList(args), e);
|
||||
command.handleException(sender, Arrays.asList(args), e);
|
||||
}
|
||||
// Something went wrong in lookup, fall back to input
|
||||
return ImmutableList.of(input);
|
||||
return Collections.singletonList(input);
|
||||
} else {
|
||||
// Plaintext value
|
||||
allCompletions.add(value);
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
package co.aikar.commands;
|
||||
|
||||
import co.aikar.util.Table;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted") // No IDEA, you are wrong
|
||||
@@ -36,7 +36,7 @@ public class CommandConditions <
|
||||
CC extends ConditionContext<I>
|
||||
> {
|
||||
private CommandManager manager;
|
||||
private Map<String, Condition<I>> conditions = Maps.newHashMap();
|
||||
private Map<String, Condition<I>> conditions = new HashMap<>();
|
||||
private Table<Class<?>, String, ParameterCondition<?, ?, ?>> paramConditions = new Table<>();
|
||||
|
||||
CommandConditions(CommandManager manager) {
|
||||
|
||||
@@ -30,17 +30,17 @@ import co.aikar.commands.contexts.ContextResolver;
|
||||
import co.aikar.commands.contexts.IssuerAwareContextResolver;
|
||||
import co.aikar.commands.contexts.IssuerOnlyContextResolver;
|
||||
import co.aikar.commands.contexts.OptionalContextResolver;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class CommandContexts<R extends CommandExecutionContext<?, ? extends CommandIssuer>> {
|
||||
protected final Map<Class<?>, ContextResolver<?, R>> contextMap = Maps.newHashMap();
|
||||
protected final Map<Class<?>, ContextResolver<?, R>> contextMap = new HashMap<>();
|
||||
protected final CommandManager manager;
|
||||
|
||||
CommandContexts(CommandManager manager) {
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
import co.aikar.commands.contexts.ContextResolver;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,17 +26,16 @@ package co.aikar.commands;
|
||||
import co.aikar.commands.annotation.Dependency;
|
||||
import co.aikar.locales.MessageKeyProvider;
|
||||
import co.aikar.util.Table;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -45,6 +44,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@@ -75,15 +75,15 @@ public abstract class CommandManager <
|
||||
protected CommandHelpFormatter helpFormatter = new CommandHelpFormatter(this);
|
||||
|
||||
protected boolean usePerIssuerLocale = false;
|
||||
protected List<IssuerLocaleChangedCallback<I>> localeChangedCallbacks = Lists.newArrayList();
|
||||
protected Set<Locale> supportedLanguages = Sets.newHashSet(Locales.ENGLISH, Locales.GERMAN, Locales.SPANISH, Locales.CZECH, Locales.PORTUGUESE, Locales.SWEDISH, Locales.NORWEGIAN_BOKMAAL, Locales.NORWEGIAN_NYNORSK, Locales.RUSSIAN);
|
||||
protected List<IssuerLocaleChangedCallback<I>> localeChangedCallbacks = new ArrayList<>();
|
||||
protected Set<Locale> supportedLanguages = new HashSet<>(Arrays.asList(Locales.ENGLISH, Locales.GERMAN, Locales.SPANISH, Locales.CZECH, Locales.PORTUGUESE, Locales.SWEDISH, Locales.NORWEGIAN_BOKMAAL, Locales.NORWEGIAN_NYNORSK, Locales.RUSSIAN));
|
||||
protected Map<MessageType, MF> formatters = new IdentityHashMap<>();
|
||||
protected MF defaultFormatter;
|
||||
protected int defaultHelpPerPage = 10;
|
||||
|
||||
protected Map<UUID, Locale> issuersLocale = Maps.newConcurrentMap();
|
||||
protected Map<UUID, Locale> issuersLocale = new ConcurrentHashMap<>();
|
||||
|
||||
private Set<String> unstableAPIs = Sets.newHashSet();
|
||||
private Set<String> unstableAPIs = new HashSet<>();
|
||||
|
||||
private Annotations annotations = new Annotations<>(this);
|
||||
|
||||
@@ -287,7 +287,7 @@ public abstract class CommandManager <
|
||||
}
|
||||
|
||||
public abstract Collection<RootCommand> getRegisteredRootCommands();
|
||||
|
||||
|
||||
public RegisteredCommand createRegisteredCommand(BaseCommand command, String cmdName, Method method, String prefSubCommand) {
|
||||
return new RegisteredCommand(command, cmdName, method, prefSubCommand);
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ import co.aikar.commands.contexts.ContextResolver;
|
||||
import co.aikar.commands.contexts.IssuerAwareContextResolver;
|
||||
import co.aikar.commands.contexts.IssuerOnlyContextResolver;
|
||||
import co.aikar.commands.contexts.OptionalContextResolver;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandParameter <CEC extends CommandExecutionContext<CEC, ? extends CommandIssuer>> {
|
||||
@@ -101,7 +101,7 @@ public class CommandParameter <CEC extends CommandExecutionContext<CEC, ? extend
|
||||
}
|
||||
}
|
||||
|
||||
this.flags = Maps.newHashMap();
|
||||
this.flags = new HashMap<>();
|
||||
String flags = annotations.getAnnotationValue(param, Flags.class, Annotations.REPLACEMENTS | Annotations.NO_EMPTY);
|
||||
if (flags != null) {
|
||||
parseFlags(flags);
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConditionContext <I extends CommandIssuer> {
|
||||
@@ -36,7 +35,7 @@ public class ConditionContext <I extends CommandIssuer> {
|
||||
ConditionContext(I issuer, String config) {
|
||||
this.issuer = issuer;
|
||||
this.config = config;
|
||||
this.configs = Maps.newHashMap();
|
||||
this.configs = new HashMap<>();
|
||||
if (config != null) {
|
||||
for (String s : ACFPatterns.COMMA.split(config)) {
|
||||
String[] v = ACFPatterns.EQUALS.split(s, 2);
|
||||
|
||||
@@ -28,11 +28,11 @@ import co.aikar.locales.MessageKey;
|
||||
import co.aikar.locales.MessageKeyProvider;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -108,7 +108,7 @@ public class Locales {
|
||||
Set<Locale> supportedLanguages = manager.getSupportedLanguages();
|
||||
for (Locale locale : supportedLanguages) {
|
||||
for(SetMultimap<String, Locale> localeData: this.loadedBundles.values()) {
|
||||
for (String bundleName : Sets.newHashSet(localeData.keys())) {
|
||||
for (String bundleName : new HashSet<>(localeData.keys())) {
|
||||
addMessageBundle(bundleName, locale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,17 +32,17 @@ import co.aikar.commands.annotation.HelpSearchTags;
|
||||
import co.aikar.commands.annotation.Private;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import co.aikar.commands.contexts.ContextResolver;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -196,9 +196,9 @@ public class RegisteredCommand <CEC extends CommandExecutionContext<CEC, ? exten
|
||||
}
|
||||
@Nullable
|
||||
Map<String, Object> resolveContexts(CommandIssuer sender, List<String> args, int argLimit) throws InvalidCommandArgument {
|
||||
args = Lists.newArrayList(args);
|
||||
args = new ArrayList<>(args);
|
||||
String[] origArgs = args.toArray(new String[args.size()]);
|
||||
Map<String, Object> passedArgs = Maps.newLinkedHashMap();
|
||||
Map<String, Object> passedArgs = new LinkedHashMap<>();
|
||||
int remainingRequired = requiredResolvers;
|
||||
CommandOperationContext opContext = CommandManager.getCurrentCommandOperationContext();
|
||||
for (int i = 0; i < parameters.length && i < argLimit; i++) {
|
||||
@@ -239,7 +239,7 @@ public class RegisteredCommand <CEC extends CommandExecutionContext<CEC, ? exten
|
||||
if (parameter.getValues() != null) {
|
||||
String arg = !args.isEmpty() ? args.get(0) : "";
|
||||
|
||||
Set<String> possible = Sets.newHashSet();
|
||||
Set<String> possible = new HashSet<>();
|
||||
CommandCompletions commandCompletions = this.manager.getCommandCompletions();
|
||||
for (String s : parameter.getValues()) {
|
||||
//noinspection unchecked
|
||||
@@ -283,9 +283,9 @@ public class RegisteredCommand <CEC extends CommandExecutionContext<CEC, ? exten
|
||||
|
||||
public Set<String> getRequiredPermissions() {
|
||||
if (this.permission == null || this.permission.isEmpty()) {
|
||||
return ImmutableSet.of();
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return Sets.newHashSet(ACFPatterns.COMMA.split(this.permission));
|
||||
return new HashSet<>(Arrays.asList(ACFPatterns.COMMA.split(this.permission)));
|
||||
}
|
||||
|
||||
public boolean requiresPermission(String permission) {
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import co.aikar.commands.apachecommonslang.ApacheCommonsLangUtil;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ShowCommandHelp extends InvalidCommandArgument {
|
||||
@@ -38,6 +37,6 @@ public class ShowCommandHelp extends InvalidCommandArgument {
|
||||
}
|
||||
ShowCommandHelp(List<String> args) {
|
||||
this(true);
|
||||
this.searchArgs = Lists.newArrayList(args);
|
||||
this.searchArgs = new ArrayList<>(args);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -88,7 +88,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
}
|
||||
THROWABLE_CAUSE_METHOD = causeMethod;
|
||||
try {
|
||||
causeMethod = Throwable.class.getMethod("initCause", new Class[]{Throwable.class});
|
||||
causeMethod = Throwable.class.getMethod("initCause", Throwable.class);
|
||||
} catch (Exception e) {
|
||||
causeMethod = null;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
}
|
||||
}
|
||||
try {
|
||||
Method setCauseMethod = target.getClass().getMethod("setCause", new Class[]{Throwable.class});
|
||||
Method setCauseMethod = target.getClass().getMethod("setCause", Throwable.class);
|
||||
setCauseMethod.invoke(target, causeArgs);
|
||||
modifiedTarget = true;
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
@@ -342,7 +342,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
*/
|
||||
private static Throwable getCauseUsingWellKnownTypes(Throwable throwable) {
|
||||
if (throwable instanceof Nestable) {
|
||||
return ((Nestable) throwable).getCause();
|
||||
return throwable.getCause();
|
||||
} else if (throwable instanceof SQLException) {
|
||||
return ((SQLException) throwable).getNextException();
|
||||
} else if (throwable instanceof InvocationTargetException) {
|
||||
@@ -877,7 +877,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
*
|
||||
* @return throwable that caused the original exception
|
||||
*/
|
||||
public Throwable getCause();
|
||||
Throwable getCause();
|
||||
|
||||
/**
|
||||
* Returns the error message of this and any nested
|
||||
@@ -885,7 +885,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
*
|
||||
* @return the error message
|
||||
*/
|
||||
public String getMessage();
|
||||
String getMessage();
|
||||
|
||||
/**
|
||||
* Returns the error message of the <code>Throwable</code> in the chain
|
||||
@@ -899,7 +899,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
* negative or not less than the count of <code>Throwable</code>s in the
|
||||
* chain
|
||||
*/
|
||||
public String getMessage(int index);
|
||||
String getMessage(int index);
|
||||
|
||||
/**
|
||||
* Returns the error message of this and any nested <code>Throwable</code>s
|
||||
@@ -911,7 +911,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
*
|
||||
* @return the error messages
|
||||
*/
|
||||
public String[] getMessages();
|
||||
String[] getMessages();
|
||||
|
||||
/**
|
||||
* Returns the <code>Throwable</code> in the chain of
|
||||
@@ -924,7 +924,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
* negative or not less than the count of <code>Throwable</code>s in the
|
||||
* chain
|
||||
*/
|
||||
public Throwable getThrowable(int index);
|
||||
Throwable getThrowable(int index);
|
||||
|
||||
/**
|
||||
* Returns the number of nested <code>Throwable</code>s represented by
|
||||
@@ -932,7 +932,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
*
|
||||
* @return the throwable count
|
||||
*/
|
||||
public int getThrowableCount();
|
||||
int getThrowableCount();
|
||||
|
||||
/**
|
||||
* Returns this <code>Nestable</code> and any nested <code>Throwable</code>s
|
||||
@@ -941,7 +941,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
*
|
||||
* @return the <code>Throwable</code>s
|
||||
*/
|
||||
public Throwable[] getThrowables();
|
||||
Throwable[] getThrowables();
|
||||
|
||||
/**
|
||||
* Returns the index, numbered from 0, of the first occurrence of the
|
||||
@@ -957,7 +957,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
* @return index of the first occurrence of the type in the chain, or -1 if
|
||||
* the type is not found
|
||||
*/
|
||||
public int indexOfThrowable(Class type);
|
||||
int indexOfThrowable(Class type);
|
||||
|
||||
/**
|
||||
* Returns the index, numbered from 0, of the first <code>Throwable</code>
|
||||
@@ -979,7 +979,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
* is negative or not less than the count of <code>Throwable</code>s in the
|
||||
* chain
|
||||
*/
|
||||
public int indexOfThrowable(Class type, int fromIndex);
|
||||
int indexOfThrowable(Class type, int fromIndex);
|
||||
|
||||
/**
|
||||
* Prints the stack trace of this exception to the specified print
|
||||
@@ -988,7 +988,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
*
|
||||
* @param out <code>PrintWriter</code> to use for output.
|
||||
*/
|
||||
public void printStackTrace(PrintWriter out);
|
||||
void printStackTrace(PrintWriter out);
|
||||
|
||||
/**
|
||||
* Prints the stack trace of this exception to the specified print
|
||||
@@ -997,7 +997,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
*
|
||||
* @param out <code>PrintStream</code> to use for output.
|
||||
*/
|
||||
public void printStackTrace(PrintStream out);
|
||||
void printStackTrace(PrintStream out);
|
||||
|
||||
/**
|
||||
* Prints the stack trace for this exception only--root cause not
|
||||
@@ -1008,7 +1008,7 @@ public class ApacheCommonsExceptionUtil {
|
||||
*
|
||||
* @param out The writer to use.
|
||||
*/
|
||||
public void printPartialStackTrace(PrintWriter out);
|
||||
void printPartialStackTrace(PrintWriter out);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,10 @@ import co.aikar.commands.BukkitCommandManager;
|
||||
import co.aikar.commands.ConditionFailedException;
|
||||
import co.aikar.commands.MessageKeys;
|
||||
import co.aikar.commands.MessageType;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class ACFExample extends JavaPlugin {
|
||||
|
||||
private static ACFExample plugin;
|
||||
@@ -64,9 +65,9 @@ public final class ACFExample extends JavaPlugin {
|
||||
SomeObject.getContextResolver());
|
||||
|
||||
// 4: Register Command Completions - this will be accessible with @CommandCompletion("@test")
|
||||
commandManager.getCommandCompletions().registerAsyncCompletion("test", c -> (
|
||||
Lists.newArrayList("foo", "bar", "baz")
|
||||
));
|
||||
commandManager.getCommandCompletions().registerAsyncCompletion("test", c -> {
|
||||
Arrays.asList("foo", "bar", "baz")
|
||||
});
|
||||
|
||||
// 5: Register Command Conditions
|
||||
commandManager.getCommandConditions().addCondition(SomeObject.class, "limits", (c, exec, value) -> {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package co.aikar.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class JDACommandCompletions extends CommandCompletions<CommandCompletionContext<?>> {
|
||||
@@ -32,11 +32,11 @@ public class JDACommandCompletions extends CommandCompletions<CommandCompletionC
|
||||
@NotNull
|
||||
@Override
|
||||
List<String> of(RegisteredCommand command, CommandIssuer sender, String[] args, boolean isAsync) {
|
||||
return ImmutableList.of();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<String> getCompletionValues(RegisteredCommand command, CommandIssuer sender, String completion, String[] args, boolean isAsync) {
|
||||
return ImmutableList.of();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package co.aikar.commands;
|
||||
|
||||
import co.aikar.commands.apachecommonslang.ApacheCommonsExceptionUtil;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
@@ -10,6 +9,7 @@ import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -30,7 +30,7 @@ public class JDACommandManager extends CommandManager<
|
||||
protected JDACommandCompletions completions;
|
||||
protected JDACommandContexts contexts;
|
||||
protected JDALocales locales;
|
||||
protected Map<String, JDARootCommand> commands = Maps.newHashMap();
|
||||
protected Map<String, JDARootCommand> commands = new HashMap<>();
|
||||
private Logger logger;
|
||||
private CommandConfig defaultConfig;
|
||||
private CommandConfigProvider configProvider;
|
||||
@@ -183,7 +183,7 @@ public class JDACommandManager extends CommandManager<
|
||||
public RootCommand createRootCommand(String cmd) {
|
||||
return new JDARootCommand(this, cmd);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<RootCommand> getRegisteredRootCommands() {
|
||||
return Collections.unmodifiableCollection(commands.values());
|
||||
|
||||
@@ -24,12 +24,10 @@
|
||||
package co.aikar.commands;
|
||||
|
||||
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.TabCompleteEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -65,10 +63,8 @@ class PaperAsyncTabCompleteHandler implements Listener {
|
||||
|
||||
BukkitCommandIssuer issuer = this.manager.getCommandIssuer(event.getSender());
|
||||
List<String> results = cmd.tabComplete(issuer, commandLabel, args, true);
|
||||
if (event.getCompletions() instanceof ImmutableList) {
|
||||
event.setCompletions(new ArrayList<>(event.getCompletions()));
|
||||
}
|
||||
event.getCompletions().addAll(results);
|
||||
event.setCompletions(ACFUtil.preformOnImmutable(
|
||||
event.getCompletions(), (list) -> list.addAll(results)));
|
||||
event.setHandled(true);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
@@ -90,10 +86,9 @@ class PaperAsyncTabCompleteHandler implements Listener {
|
||||
if (rootCommand != null) {
|
||||
args = args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[]{""};
|
||||
BukkitCommandIssuer issuer = this.manager.getCommandIssuer(event.getSender());
|
||||
if (event.getCompletions() instanceof ImmutableList) {
|
||||
event.setCompletions(new ArrayList<>(event.getCompletions()));
|
||||
}
|
||||
event.getCompletions().addAll(rootCommand.getTabCompletions(issuer, commandLabel, args, true));
|
||||
List<String> tabCompletions = rootCommand.getTabCompletions(issuer, commandLabel, args, true);
|
||||
event.setCompletions(ACFUtil.preformOnImmutable(
|
||||
event.getCompletions(), (list) -> list.addAll(tabCompletions)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ package co.aikar.commands;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ package co.aikar.commands;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.command.source.ConsoleSource;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
import org.spongepowered.api.util.Identifiable;
|
||||
|
||||
Reference in New Issue
Block a user