Permalink
Browse files

Drop trivial Guava usages (#142)

  • Loading branch information...
osipxd authored and aikar committed Jul 19, 2018
1 parent 786ebe8 commit 3c979a9ef24dc62e6611832cc97ef25f77afec2d
Showing with 103 additions and 111 deletions.
  1. +1 −0 .gitignore
  2. +0 −1 bukkit/src/main/java/co/aikar/commands/BukkitCommandExecutionContext.java
  3. +0 −2 bukkit/src/main/java/co/aikar/commands/BukkitRootCommand.java
  4. +0 −1 bungee/src/main/java/co/aikar/commands/BungeeCommandExecutionContext.java
  5. +12 −0 core/src/main/java/co/aikar/commands/ACFUtil.java
  6. +8 −8 core/src/main/java/co/aikar/commands/Annotations.java
  7. +5 −10 core/src/main/java/co/aikar/commands/BaseCommand.java
  8. +4 −6 core/src/main/java/co/aikar/commands/CommandCompletionContext.java
  9. +12 −10 core/src/main/java/co/aikar/commands/CommandCompletions.java
  10. +2 −2 core/src/main/java/co/aikar/commands/CommandConditions.java
  11. +2 −2 core/src/main/java/co/aikar/commands/CommandContexts.java
  12. +0 −2 core/src/main/java/co/aikar/commands/CommandExecutionContext.java
  13. +9 −9 core/src/main/java/co/aikar/commands/CommandManager.java
  14. +2 −2 core/src/main/java/co/aikar/commands/CommandParameter.java
  15. +2 −3 core/src/main/java/co/aikar/commands/ConditionContext.java
  16. +2 −2 core/src/main/java/co/aikar/commands/Locales.java
  17. +9 −9 core/src/main/java/co/aikar/commands/RegisteredCommand.java
  18. +0 −2 core/src/main/java/co/aikar/commands/RootCommand.java
  19. +2 −3 core/src/main/java/co/aikar/commands/ShowCommandHelp.java
  20. +15 −15 core/src/main/java/co/aikar/commands/apachecommonslang/ApacheCommonsExceptionUtil.java
  21. +5 −4 example/src/main/java/co/aikar/acfexample/ACFExample.java
  22. +3 −3 jda/src/main/java/co/aikar/commands/JDACommandCompletions.java
  23. +3 −3 jda/src/main/java/co/aikar/commands/JDACommandManager.java
  24. +5 −10 paper/src/main/java/co/aikar/commands/PaperAsyncTabCompleteHandler.java
  25. +0 −1 sponge/src/main/java/co/aikar/commands/SpongeCommandExecutionContext.java
  26. +0 −1 sponge/src/main/java/co/aikar/commands/SpongeCommandIssuer.java
@@ -11,6 +11,7 @@
.idea/kotlinc.xml
.idea/modules.xml
.idea/usage.statistics.xml
.idea/checkstyle-idea.xml
**/*.iml
@@ -26,7 +26,6 @@
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 @@
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.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 static void sneaky(Throwable t) {
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 @@
@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.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 @@
/**
* 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 @@ private void executeCommand(CommandOperationContext commandOperationContext,
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 boolean canExecute(CommandIssuer issuer, RegisteredCommand<?> cmd) {
*/
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 boolean hasPermission(CommandIssuer issuer) {
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 @@
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 @@
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 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 CommandCompletions(CommandManager manager) {
}
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 CommandCompletionHandler registerStaticCompletion(String id, String list)
* @return
*/
public CommandCompletionHandler registerStaticCompletion(String id, String[] completions) {
return registerStaticCompletion(id, Lists.newArrayList(completions));
return registerStaticCompletion(id, Arrays.asList(completions));
}
/**
@@ -178,7 +180,7 @@ CommandCompletionHandler setDefaultCompletion(String id, Class... classes) {
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 @@ CommandCompletionHandler setDefaultCompletion(String id, Class... classes) {
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 @@ CommandCompletionHandler setDefaultCompletion(String id, Class... classes) {
} 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 @@
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.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 @@
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.Set;
import java.util.Stack;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@SuppressWarnings("WeakerAccess")
@@ -75,15 +75,15 @@ public synchronized CommandOperationContext peek() {
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 synchronized RootCommand obtainRootCommand(@NotNull String cmd) {
}
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.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 CommandParameter(RegisteredCommand<CEC> command, Parameter param, int par
}
}
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 @@
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);
Oops, something went wrong.

0 comments on commit 3c979a9

Please sign in to comment.