Fix dependency graph and replace Guava

This commit is contained in:
Alexander Söderberg 2020-09-28 16:05:14 +02:00 committed by Alexander Söderberg
parent 4ca47777a3
commit e914d04450
35 changed files with 184 additions and 191 deletions

View file

@ -5,7 +5,6 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath("com.github.jengelman.gradle.plugins:shadow:5.0.0")
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1' classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
} }
} }
@ -51,11 +50,13 @@ subprojects {
apply plugin: 'java-library' apply plugin: 'java-library'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
test {
useJUnitPlatform()
}
repositories { repositories {
mavenLocal() mavenLocal()
maven { mavenCentral()
url = 'https://repo1.maven.org/maven2'
}
maven { maven {
url = 'https://oss.sonatype.org/content/repositories/snapshots' url = 'https://oss.sonatype.org/content/repositories/snapshots'

View file

@ -1,4 +1,3 @@
dependencies { dependencies {
implementation project(':cloud-core') implementation project(':cloud-core')
implementation 'com.google.guava:guava:29.0-jre'
} }

View file

@ -34,8 +34,7 @@ import cloud.commandframework.execution.CommandExecutionHandler;
import cloud.commandframework.extra.confirmation.CommandConfirmationManager; import cloud.commandframework.extra.confirmation.CommandConfirmationManager;
import cloud.commandframework.meta.CommandMeta; import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.meta.SimpleCommandMeta; import cloud.commandframework.meta.SimpleCommandMeta;
import com.google.common.collect.Maps; import io.leangen.geantyref.TypeToken;
import com.google.common.reflect.TypeToken;
import cloud.commandframework.arguments.parser.ParserParameters; import cloud.commandframework.arguments.parser.ParserParameters;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -46,6 +45,7 @@ import java.lang.reflect.Parameter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
@ -81,7 +81,7 @@ public final class AnnotationParser<C> {
this.commandSenderClass = commandSenderClass; this.commandSenderClass = commandSenderClass;
this.manager = manager; this.manager = manager;
this.metaFactory = new MetaFactory(this, metaMapper); this.metaFactory = new MetaFactory(this, metaMapper);
this.annotationMappers = Maps.newHashMap(); this.annotationMappers = new HashMap<>();
this.registerAnnotationMapper(CommandDescription.class, d -> this.registerAnnotationMapper(CommandDescription.class, d ->
ParserParameters.single(StandardParameters.DESCRIPTION, d.value())); ParserParameters.single(StandardParameters.DESCRIPTION, d.value()));
} }
@ -156,8 +156,8 @@ public final class AnnotationParser<C> {
tokens.get(commandToken).getMinor(), tokens.get(commandToken).getMinor(),
metaBuilder.build()); metaBuilder.build());
final Collection<ArgumentParameterPair> arguments = this.argumentExtractor.apply(method); final Collection<ArgumentParameterPair> arguments = this.argumentExtractor.apply(method);
final Map<String, CommandArgument<C, ?>> commandArguments = Maps.newHashMap(); final Map<String, CommandArgument<C, ?>> commandArguments = new HashMap<>();
final Map<CommandArgument<C, ?>, String> argumentDescriptions = Maps.newHashMap(); final Map<CommandArgument<C, ?>, String> argumentDescriptions = new HashMap<>();
/* Go through all annotated parameters and build up the argument tree */ /* Go through all annotated parameters and build up the argument tree */
for (final ArgumentParameterPair argumentPair : arguments) { for (final ArgumentParameterPair argumentPair : arguments) {
final CommandArgument<C, ?> argument = this.buildArgument(method, final CommandArgument<C, ?> argument = this.buildArgument(method,
@ -246,7 +246,7 @@ public final class AnnotationParser<C> {
@Nonnull final ArgumentParameterPair argumentPair) { @Nonnull final ArgumentParameterPair argumentPair) {
final Parameter parameter = argumentPair.getParameter(); final Parameter parameter = argumentPair.getParameter();
final Collection<Annotation> annotations = Arrays.asList(parameter.getAnnotations()); final Collection<Annotation> annotations = Arrays.asList(parameter.getAnnotations());
final TypeToken<?> token = TypeToken.of(parameter.getParameterizedType()); final TypeToken<?> token = TypeToken.get(parameter.getParameterizedType());
final ParserParameters parameters = this.manager.getParserRegistry() final ParserParameters parameters = this.manager.getParserRegistry()
.parseAnnotations(token, annotations); .parseAnnotations(token, annotations);

View file

@ -1,6 +1,5 @@
dependencies { dependencies {
api project(':cloud-services') api project(':cloud-services')
api 'com.google.guava:guava:29.0-jre'
testImplementation 'org.openjdk.jmh:jmh-core:1.25.2' testImplementation 'org.openjdk.jmh:jmh-core:1.25.2'
testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.25.2' testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.25.2'
} }

View file

@ -44,9 +44,7 @@ import cloud.commandframework.execution.preprocessor.AcceptingCommandPreprocesso
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext; import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
import cloud.commandframework.execution.preprocessor.CommandPreprocessor; import cloud.commandframework.execution.preprocessor.CommandPreprocessor;
import cloud.commandframework.internal.CommandRegistrationHandler; import cloud.commandframework.internal.CommandRegistrationHandler;
import com.google.common.collect.Lists; import io.leangen.geantyref.TypeToken;
import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken;
import cloud.commandframework.meta.CommandMeta; import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.permission.CommandPermission; import cloud.commandframework.permission.CommandPermission;
import cloud.commandframework.permission.OrPermission; import cloud.commandframework.permission.OrPermission;
@ -59,6 +57,7 @@ import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -76,13 +75,13 @@ import java.util.function.Function;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public abstract class CommandManager<C> { public abstract class CommandManager<C> {
private final Map<Class<? extends Exception>, BiConsumer<C, ? extends Exception>> exceptionHandlers = Maps.newHashMap(); private final Map<Class<? extends Exception>, BiConsumer<C, ? extends Exception>> exceptionHandlers = new HashMap<>();
private final EnumSet<ManagerSettings> managerSettings = EnumSet.of(ManagerSettings.ENFORCE_INTERMEDIARY_PERMISSIONS); private final EnumSet<ManagerSettings> managerSettings = EnumSet.of(ManagerSettings.ENFORCE_INTERMEDIARY_PERMISSIONS);
private final CommandContextFactory<C> commandContextFactory = new StandardCommandContextFactory<>(); private final CommandContextFactory<C> commandContextFactory = new StandardCommandContextFactory<>();
private final ServicePipeline servicePipeline = ServicePipeline.builder().build(); private final ServicePipeline servicePipeline = ServicePipeline.builder().build();
private final ParserRegistry<C> parserRegistry = new StandardParserRegistry<>(); private final ParserRegistry<C> parserRegistry = new StandardParserRegistry<>();
private final Collection<Command<C>> commands = Lists.newLinkedList(); private final Collection<Command<C>> commands = new LinkedList<>();
private final CommandExecutionCoordinator<C> commandExecutionCoordinator; private final CommandExecutionCoordinator<C> commandExecutionCoordinator;
private final CommandTree<C> commandTree; private final CommandTree<C> commandTree;

View file

@ -24,7 +24,7 @@
package cloud.commandframework.arguments; package cloud.commandframework.arguments;
import cloud.commandframework.arguments.parser.ArgumentParser; import cloud.commandframework.arguments.parser.ArgumentParser;
import com.google.common.reflect.TypeToken; import io.leangen.geantyref.TypeToken;
import cloud.commandframework.Command; import cloud.commandframework.Command;
import cloud.commandframework.CommandManager; import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.parser.ArgumentParseResult; import cloud.commandframework.arguments.parser.ArgumentParseResult;
@ -180,7 +180,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
@Nonnull @Nonnull
public static <C, T> CommandArgument.Builder<C, T> ofType(@Nonnull final Class<T> clazz, public static <C, T> CommandArgument.Builder<C, T> ofType(@Nonnull final Class<T> clazz,
@Nonnull final String name) { @Nonnull final String name) {
return new Builder<>(TypeToken.of(clazz), name); return new Builder<>(TypeToken.get(clazz), name);
} }
/** /**

View file

@ -23,7 +23,7 @@
// //
package cloud.commandframework.arguments.parser; package cloud.commandframework.arguments.parser;
import com.google.common.reflect.TypeToken; import io.leangen.geantyref.TypeToken;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Objects; import java.util.Objects;

View file

@ -23,10 +23,9 @@
// //
package cloud.commandframework.arguments.parser; package cloud.commandframework.arguments.parser;
import com.google.common.collect.Maps;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
@ -34,7 +33,7 @@ import java.util.Map;
*/ */
public final class ParserParameters { public final class ParserParameters {
private final Map<ParserParameter<?>, Object> internalMap = Maps.newHashMap(); private final Map<ParserParameter<?>, Object> internalMap = new HashMap<>();
/** /**
* Get an empty {@link ParserParameters} instance * Get an empty {@link ParserParameters} instance

View file

@ -23,7 +23,7 @@
// //
package cloud.commandframework.arguments.parser; package cloud.commandframework.arguments.parser;
import com.google.common.reflect.TypeToken; import io.leangen.geantyref.TypeToken;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
@ -34,7 +34,7 @@ import java.util.function.Function;
/** /**
* Registry of {@link ArgumentParser} that allows these arguments to be * Registry of {@link ArgumentParser} that allows these arguments to be
* referenced by a {@link Class} (or really, a {@link com.google.common.reflect.TypeToken}) * referenced by a {@link Class} (or really, a {@link TypeToken})
* or a {@link String} key * or a {@link String} key
* *
* @param <C> Command sender type * @param <C> Command sender type

View file

@ -23,7 +23,7 @@
// //
package cloud.commandframework.arguments.parser; package cloud.commandframework.arguments.parser;
import com.google.common.reflect.TypeToken; import io.leangen.geantyref.TypeToken;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -35,27 +35,27 @@ public final class StandardParameters {
/** /**
* Minimum value accepted by a numerical parser * Minimum value accepted by a numerical parser
*/ */
public static final ParserParameter<Number> RANGE_MIN = create("min", TypeToken.of(Number.class)); public static final ParserParameter<Number> RANGE_MIN = create("min", TypeToken.get(Number.class));
/** /**
* Maximum value accepted by a numerical parser * Maximum value accepted by a numerical parser
*/ */
public static final ParserParameter<Number> RANGE_MAX = create("max", TypeToken.of(Number.class)); public static final ParserParameter<Number> RANGE_MAX = create("max", TypeToken.get(Number.class));
/** /**
* Command description * Command description
*/ */
public static final ParserParameter<String> DESCRIPTION = create("description", TypeToken.of(String.class)); public static final ParserParameter<String> DESCRIPTION = create("description", TypeToken.get(String.class));
/** /**
* Command confirmation * Command confirmation
*/ */
public static final ParserParameter<Boolean> CONFIRMATION = create("confirmation", TypeToken.of(Boolean.class)); public static final ParserParameter<Boolean> CONFIRMATION = create("confirmation", TypeToken.get(Boolean.class));
/** /**
* Command completions * Command completions
*/ */
public static final ParserParameter<String[]> COMPLETIONS = create("completions", TypeToken.of(String[].class)); public static final ParserParameter<String[]> COMPLETIONS = create("completions", TypeToken.get(String[].class));
/** /**
* The command should be hidden from help menus, etc * The command should be hidden from help menus, etc
*/ */
public static final ParserParameter<Boolean> HIDDEN = create("hidden", TypeToken.of(Boolean.class)); public static final ParserParameter<Boolean> HIDDEN = create("hidden", TypeToken.get(Boolean.class));
private StandardParameters() { private StandardParameters() {
} }

View file

@ -23,8 +23,6 @@
// //
package cloud.commandframework.arguments.parser; package cloud.commandframework.arguments.parser;
import com.google.common.collect.ImmutableMap;
import com.google.common.reflect.TypeToken;
import cloud.commandframework.annotations.specifier.Completions; import cloud.commandframework.annotations.specifier.Completions;
import cloud.commandframework.annotations.specifier.Range; import cloud.commandframework.annotations.specifier.Range;
import cloud.commandframework.arguments.standard.BooleanArgument; import cloud.commandframework.arguments.standard.BooleanArgument;
@ -36,6 +34,8 @@ import cloud.commandframework.arguments.standard.FloatArgument;
import cloud.commandframework.arguments.standard.IntegerArgument; import cloud.commandframework.arguments.standard.IntegerArgument;
import cloud.commandframework.arguments.standard.ShortArgument; import cloud.commandframework.arguments.standard.ShortArgument;
import cloud.commandframework.arguments.standard.StringArgument; import cloud.commandframework.arguments.standard.StringArgument;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
@ -54,16 +54,18 @@ import java.util.function.Function;
*/ */
public final class StandardParserRegistry<C> implements ParserRegistry<C> { public final class StandardParserRegistry<C> implements ParserRegistry<C> {
private static final Map<Class<?>, Class<?>> PRIMITIVE_MAPPINGS = ImmutableMap.<Class<?>, Class<?>>builder() private static final Map<Class<?>, Class<?>> PRIMITIVE_MAPPINGS = new HashMap<Class<?>, Class<?>>() {
.put(char.class, Character.class) {
.put(int.class, Integer.class) put(char.class, Character .class);
.put(short.class, Short.class) put(int.class, Integer .class);
.put(byte.class, Byte.class) put(short.class, Short .class);
.put(float.class, Float.class) put(byte.class, Byte .class);
.put(double.class, Double.class) put(float.class, Float .class);
.put(long.class, Long.class) put(double.class, Double .class);
.put(boolean.class, Boolean.class) put(long.class, Long .class);
.build(); put(boolean.class, Boolean .class);
}
};
private final Map<String, Function<ParserParameters, ArgumentParser<C, ?>>> namedParsers = new HashMap<>(); private final Map<String, Function<ParserParameters, ArgumentParser<C, ?>>> namedParsers = new HashMap<>();
private final Map<TypeToken<?>, Function<ParserParameters, ArgumentParser<C, ?>>> parserSuppliers = new HashMap<>(); private final Map<TypeToken<?>, Function<ParserParameters, ArgumentParser<C, ?>>> parserSuppliers = new HashMap<>();
@ -80,28 +82,28 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
this.<Completions, String>registerAnnotationMapper(Completions.class, new CompletionsMapper()); this.<Completions, String>registerAnnotationMapper(Completions.class, new CompletionsMapper());
/* Register standard types */ /* Register standard types */
this.registerParserSupplier(TypeToken.of(Byte.class), options -> this.registerParserSupplier(TypeToken.get(Byte.class), options ->
new ByteArgument.ByteParser<C>((byte) options.get(StandardParameters.RANGE_MIN, Byte.MIN_VALUE), new ByteArgument.ByteParser<C>((byte) options.get(StandardParameters.RANGE_MIN, Byte.MIN_VALUE),
(byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE))); (byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE)));
this.registerParserSupplier(TypeToken.of(Short.class), options -> this.registerParserSupplier(TypeToken.get(Short.class), options ->
new ShortArgument.ShortParser<C>((short) options.get(StandardParameters.RANGE_MIN, Short.MIN_VALUE), new ShortArgument.ShortParser<C>((short) options.get(StandardParameters.RANGE_MIN, Short.MIN_VALUE),
(short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE))); (short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE)));
this.registerParserSupplier(TypeToken.of(Integer.class), options -> this.registerParserSupplier(TypeToken.get(Integer.class), options ->
new IntegerArgument.IntegerParser<C>((int) options.get(StandardParameters.RANGE_MIN, Integer.MIN_VALUE), new IntegerArgument.IntegerParser<C>((int) options.get(StandardParameters.RANGE_MIN, Integer.MIN_VALUE),
(int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE))); (int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE)));
this.registerParserSupplier(TypeToken.of(Float.class), options -> this.registerParserSupplier(TypeToken.get(Float.class), options ->
new FloatArgument.FloatParser<C>((float) options.get(StandardParameters.RANGE_MIN, Float.MIN_VALUE), new FloatArgument.FloatParser<C>((float) options.get(StandardParameters.RANGE_MIN, Float.MIN_VALUE),
(float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE))); (float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE)));
this.registerParserSupplier(TypeToken.of(Double.class), options -> this.registerParserSupplier(TypeToken.get(Double.class), options ->
new DoubleArgument.DoubleParser<C>((double) options.get(StandardParameters.RANGE_MIN, Double.MIN_VALUE), new DoubleArgument.DoubleParser<C>((double) options.get(StandardParameters.RANGE_MIN, Double.MIN_VALUE),
(double) options.get(StandardParameters.RANGE_MAX, Double.MAX_VALUE))); (double) options.get(StandardParameters.RANGE_MAX, Double.MAX_VALUE)));
this.registerParserSupplier(TypeToken.of(Character.class), options -> new CharArgument.CharacterParser<C>()); this.registerParserSupplier(TypeToken.get(Character.class), options -> new CharArgument.CharacterParser<C>());
/* Make this one less awful */ /* Make this one less awful */
this.registerParserSupplier(TypeToken.of(String.class), options -> new StringArgument.StringParser<C>( this.registerParserSupplier(TypeToken.get(String.class), options -> new StringArgument.StringParser<C>(
StringArgument.StringMode.SINGLE, (context, s) -> StringArgument.StringMode.SINGLE, (context, s) ->
Arrays.asList(options.get(StandardParameters.COMPLETIONS, new String[0])))); Arrays.asList(options.get(StandardParameters.COMPLETIONS, new String[0]))));
/* Add options to this */ /* Add options to this */
this.registerParserSupplier(TypeToken.of(Boolean.class), options -> new BooleanArgument.BooleanParser<>(false)); this.registerParserSupplier(TypeToken.get(Boolean.class), options -> new BooleanArgument.BooleanParser<>(false));
} }
@Override @Override
@ -146,17 +148,17 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
public <T> Optional<ArgumentParser<C, T>> createParser(@Nonnull final TypeToken<T> type, public <T> Optional<ArgumentParser<C, T>> createParser(@Nonnull final TypeToken<T> type,
@Nonnull final ParserParameters parserParameters) { @Nonnull final ParserParameters parserParameters) {
final TypeToken<?> actualType; final TypeToken<?> actualType;
if (type.isPrimitive()) { if (GenericTypeReflector.erase(type.getType()).isPrimitive()) {
actualType = TypeToken.of(PRIMITIVE_MAPPINGS.get(type.getRawType())); actualType = TypeToken.get(PRIMITIVE_MAPPINGS.get(GenericTypeReflector.erase(type.getType())));
} else { } else {
actualType = type; actualType = type;
} }
final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.parserSuppliers.get(actualType); final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.parserSuppliers.get(actualType);
if (producer == null) { if (producer == null) {
/* Give enums special treatment */ /* Give enums special treatment */
if (actualType.isSubtypeOf(Enum.class)) { if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {
@SuppressWarnings("all") final EnumArgument.EnumParser enumArgument @SuppressWarnings("all") final EnumArgument.EnumParser enumArgument
= new EnumArgument.EnumParser((Class<Enum>) actualType.getRawType()); = new EnumArgument.EnumParser((Class<Enum>) GenericTypeReflector.erase(actualType.getType()));
// noinspection all // noinspection all
return Optional.of(enumArgument); return Optional.of(enumArgument);
} }
@ -181,15 +183,20 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
} }
private static boolean isPrimitive(@Nonnull final TypeToken<?> type) {
return GenericTypeReflector.erase(type.getType()).isPrimitive();
}
private static final class RangeMapper<T> implements BiFunction<Range, TypeToken<?>, ParserParameters> { private static final class RangeMapper<T> implements BiFunction<Range, TypeToken<?>, ParserParameters> {
@Override @Override
public ParserParameters apply(final Range range, final TypeToken<?> type) { public ParserParameters apply(final Range range, final TypeToken<?> type) {
final Class<?> clazz; final Class<?> clazz;
if (type.isPrimitive()) { if (isPrimitive(type)) {
clazz = PRIMITIVE_MAPPINGS.get(type.getRawType()); clazz = PRIMITIVE_MAPPINGS.get(GenericTypeReflector.erase(type.getType()));
} else { } else {
clazz = type.getRawType(); clazz = GenericTypeReflector.erase(type.getType());
} }
if (!Number.class.isAssignableFrom(clazz)) { if (!Number.class.isAssignableFrom(clazz)) {
return ParserParameters.empty(); return ParserParameters.empty();
@ -256,7 +263,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
@Override @Override
public ParserParameters apply(final Completions completions, final TypeToken<?> token) { public ParserParameters apply(final Completions completions, final TypeToken<?> token) {
if (token.getRawType().equals(String.class)) { if (GenericTypeReflector.erase(token.getType()).equals(String.class)) {
final String[] splitCompletions = completions.value().replace(" ", "").split(","); final String[] splitCompletions = completions.value().replace(" ", "").split(",");
return ParserParameters.single(StandardParameters.COMPLETIONS, splitCompletions); return ParserParameters.single(StandardParameters.COMPLETIONS, splitCompletions);
} }

View file

@ -24,10 +24,10 @@
package cloud.commandframework.context; package cloud.commandframework.context;
import cloud.commandframework.arguments.CommandArgument; import cloud.commandframework.arguments.CommandArgument;
import com.google.common.collect.Maps;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -38,8 +38,8 @@ import java.util.Optional;
*/ */
public final class CommandContext<C> { public final class CommandContext<C> {
private final Map<CommandArgument<C, ?>, ArgumentTiming> argumentTimings = Maps.newHashMap(); private final Map<CommandArgument<C, ?>, ArgumentTiming> argumentTimings = new HashMap<>();
private final Map<String, Object> internalStorage = Maps.newHashMap(); private final Map<String, Object> internalStorage = new HashMap<>();
private final C commandSender; private final C commandSender;
private final boolean suggestions; private final boolean suggestions;
@ -197,6 +197,7 @@ public final class CommandContext<C> {
* *
* @param start Start time (in nanoseconds) * @param start Start time (in nanoseconds)
*/ */
@SuppressWarnings("unused")
public ArgumentTiming(final long start) { public ArgumentTiming(final long start) {
this(start, -1, false); this(start, -1, false);
} }

View file

@ -23,16 +23,17 @@
// //
package cloud.commandframework.extra.confirmation; package cloud.commandframework.extra.confirmation;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import cloud.commandframework.CommandManager; import cloud.commandframework.CommandManager;
import cloud.commandframework.execution.CommandExecutionHandler; import cloud.commandframework.execution.CommandExecutionHandler;
import cloud.commandframework.execution.postprocessor.CommandPostprocessingContext; import cloud.commandframework.execution.postprocessor.CommandPostprocessingContext;
import cloud.commandframework.execution.postprocessor.CommandPostprocessor; import cloud.commandframework.execution.postprocessor.CommandPostprocessor;
import cloud.commandframework.meta.SimpleCommandMeta; import cloud.commandframework.meta.SimpleCommandMeta;
import cloud.commandframework.services.types.ConsumerService; import cloud.commandframework.services.types.ConsumerService;
import cloud.commandframework.types.tuples.Pair;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -55,10 +56,13 @@ public class CommandConfirmationManager<C> {
* Meta data stored for commands that require confirmation * Meta data stored for commands that require confirmation
*/ */
public static final String CONFIRMATION_REQUIRED_META = "__REQUIRE_CONFIRMATION__"; public static final String CONFIRMATION_REQUIRED_META = "__REQUIRE_CONFIRMATION__";
private static final int MAXIMUM_PENDING_SIZE = 100;
private final Consumer<CommandPostprocessingContext<C>> notifier; private final Consumer<CommandPostprocessingContext<C>> notifier;
private final Consumer<C> errorNotifier; private final Consumer<C> errorNotifier;
private final Cache<C, CommandPostprocessingContext<C>> pendingCommands; private final Map<C, Pair<CommandPostprocessingContext<C>, Long>> pendingCommands;
private final long timeoutMillis;
/** /**
* Create a new confirmation manager instance * Create a new confirmation manager instance
@ -74,7 +78,13 @@ public class CommandConfirmationManager<C> {
@Nonnull final Consumer<C> errorNotifier) { @Nonnull final Consumer<C> errorNotifier) {
this.notifier = notifier; this.notifier = notifier;
this.errorNotifier = errorNotifier; this.errorNotifier = errorNotifier;
this.pendingCommands = CacheBuilder.newBuilder().expireAfterWrite(timeout, timeoutTimeUnit).concurrencyLevel(1).build(); this.pendingCommands = new LinkedHashMap<C, Pair<CommandPostprocessingContext<C>, Long>>() {
@Override
protected boolean removeEldestEntry(final Map.Entry<C, Pair<CommandPostprocessingContext<C>, Long>> eldest) {
return this.size() > MAXIMUM_PENDING_SIZE;
}
};
this.timeoutMillis = timeoutTimeUnit.toMillis(timeout);
} }
private void notifyConsumer(@Nonnull final CommandPostprocessingContext<C> context) { private void notifyConsumer(@Nonnull final CommandPostprocessingContext<C> context) {
@ -82,7 +92,7 @@ public class CommandConfirmationManager<C> {
} }
private void addPending(@Nonnull final CommandPostprocessingContext<C> context) { private void addPending(@Nonnull final CommandPostprocessingContext<C> context) {
this.pendingCommands.put(context.getCommandContext().getSender(), context); this.pendingCommands.put(context.getCommandContext().getSender(), Pair.of(context, System.currentTimeMillis()));
} }
/** /**
@ -93,7 +103,13 @@ public class CommandConfirmationManager<C> {
*/ */
@Nonnull @Nonnull
public Optional<CommandPostprocessingContext<C>> getPending(@Nonnull final C sender) { public Optional<CommandPostprocessingContext<C>> getPending(@Nonnull final C sender) {
return Optional.ofNullable(this.pendingCommands.getIfPresent(sender)); final Pair<CommandPostprocessingContext<C>, Long> pair = this.pendingCommands.remove(sender);
if (pair != null) {
if (System.currentTimeMillis() < pair.getSecond() + this.timeoutMillis) {
return Optional.of(pair.getFirst());
}
}
return Optional.empty();
} }
/** /**

View file

@ -23,9 +23,8 @@
// //
package cloud.commandframework.types.tuples; package cloud.commandframework.types.tuples;
import com.google.common.base.Objects;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Objects;
/** /**
* Immutable generic 2-tuple * Immutable generic 2-tuple
@ -90,13 +89,13 @@ public class Pair<U, V> implements Tuple {
return false; return false;
} }
final Pair<?, ?> pair = (Pair<?, ?>) o; final Pair<?, ?> pair = (Pair<?, ?>) o;
return Objects.equal(getFirst(), pair.getFirst()) return Objects.equals(getFirst(), pair.getFirst())
&& Objects.equal(getSecond(), pair.getSecond()); && Objects.equals(getSecond(), pair.getSecond());
} }
@Override @Override
public final int hashCode() { public final int hashCode() {
return Objects.hashCode(getFirst(), getSecond()); return Objects.hash(getFirst(), getSecond());
} }
@Override @Override

View file

@ -23,9 +23,8 @@
// //
package cloud.commandframework.types.tuples; package cloud.commandframework.types.tuples;
import com.google.common.base.Objects;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Objects;
/** /**
* Immutable generic 5-tuple * Immutable generic 5-tuple
@ -126,15 +125,15 @@ public class Quartet<U, V, W, X> implements Tuple {
return false; return false;
} }
final Quartet<?, ?, ?, ?> quartet = (Quartet<?, ?, ?, ?>) o; final Quartet<?, ?, ?, ?> quartet = (Quartet<?, ?, ?, ?>) o;
return Objects.equal(getFirst(), quartet.getFirst()) return Objects.equals(getFirst(), quartet.getFirst())
&& Objects.equal(getSecond(), quartet.getSecond()) && Objects.equals(getSecond(), quartet.getSecond())
&& Objects.equal(getThird(), quartet.getThird()) && Objects.equals(getThird(), quartet.getThird())
&& Objects.equal(getFourth(), quartet.getFourth()); && Objects.equals(getFourth(), quartet.getFourth());
} }
@Override @Override
public final int hashCode() { public final int hashCode() {
return Objects.hashCode(getFirst(), getSecond(), getThird(), getFourth()); return Objects.hash(getFirst(), getSecond(), getThird(), getFourth());
} }
@Override @Override

View file

@ -23,9 +23,8 @@
// //
package cloud.commandframework.types.tuples; package cloud.commandframework.types.tuples;
import com.google.common.base.Objects;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Objects;
/** /**
* Immutable generic 5-tuple * Immutable generic 5-tuple
@ -144,16 +143,16 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
return false; return false;
} }
final Quintet<?, ?, ?, ?, ?> quintet = (Quintet<?, ?, ?, ?, ?>) o; final Quintet<?, ?, ?, ?, ?> quintet = (Quintet<?, ?, ?, ?, ?>) o;
return Objects.equal(getFirst(), quintet.getFirst()) return Objects.equals(getFirst(), quintet.getFirst())
&& Objects.equal(getSecond(), quintet.getSecond()) && Objects.equals(getSecond(), quintet.getSecond())
&& Objects.equal(getThird(), quintet.getThird()) && Objects.equals(getThird(), quintet.getThird())
&& Objects.equal(getFourth(), quintet.getFourth()) && Objects.equals(getFourth(), quintet.getFourth())
&& Objects.equal(getFifth(), quintet.getFifth()); && Objects.equals(getFifth(), quintet.getFifth());
} }
@Override @Override
public final int hashCode() { public final int hashCode() {
return Objects.hashCode(getFirst(), getSecond(), getThird(), getFourth(), getFifth()); return Objects.hash(getFirst(), getSecond(), getThird(), getFourth(), getFifth());
} }
@Override @Override

View file

@ -23,9 +23,8 @@
// //
package cloud.commandframework.types.tuples; package cloud.commandframework.types.tuples;
import com.google.common.base.Objects;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Objects;
/** /**
* Immutable generic 6-tuple * Immutable generic 6-tuple
@ -162,17 +161,17 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
return false; return false;
} }
final Sextet<?, ?, ?, ?, ?, ?> sextet = (Sextet<?, ?, ?, ?, ?, ?>) o; final Sextet<?, ?, ?, ?, ?, ?> sextet = (Sextet<?, ?, ?, ?, ?, ?>) o;
return Objects.equal(getFirst(), sextet.getFirst()) return Objects.equals(getFirst(), sextet.getFirst())
&& Objects.equal(getSecond(), sextet.getSecond()) && Objects.equals(getSecond(), sextet.getSecond())
&& Objects.equal(getThird(), sextet.getThird()) && Objects.equals(getThird(), sextet.getThird())
&& Objects.equal(getFourth(), sextet.getFourth()) && Objects.equals(getFourth(), sextet.getFourth())
&& Objects.equal(getFifth(), sextet.getFifth()) && Objects.equals(getFifth(), sextet.getFifth())
&& Objects.equal(getSixth(), sextet.getSixth()); && Objects.equals(getSixth(), sextet.getSixth());
} }
@Override @Override
public final int hashCode() { public final int hashCode() {
return Objects.hashCode(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth()); return Objects.hash(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth());
} }
@Override @Override

View file

@ -23,9 +23,8 @@
// //
package cloud.commandframework.types.tuples; package cloud.commandframework.types.tuples;
import com.google.common.base.Objects;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Objects;
/** /**
* Immutable generic 3-tuple * Immutable generic 3-tuple
@ -108,14 +107,14 @@ public class Triplet<U, V, W> implements Tuple {
return false; return false;
} }
final Triplet<?, ?, ?> triplet = (Triplet<?, ?, ?>) o; final Triplet<?, ?, ?> triplet = (Triplet<?, ?, ?>) o;
return Objects.equal(getFirst(), triplet.getFirst()) return Objects.equals(getFirst(), triplet.getFirst())
&& Objects.equal(getSecond(), triplet.getSecond()) && Objects.equals(getSecond(), triplet.getSecond())
&& Objects.equal(getThird(), triplet.getThird()); && Objects.equals(getThird(), triplet.getThird());
} }
@Override @Override
public final int hashCode() { public final int hashCode() {
return Objects.hashCode(getFirst(), getSecond(), getThird()); return Objects.hash(getFirst(), getSecond(), getThird());
} }
@Override @Override

View file

@ -25,7 +25,7 @@ package cloud.commandframework;
import cloud.commandframework.annotations.specifier.Range; import cloud.commandframework.annotations.specifier.Range;
import cloud.commandframework.arguments.standard.IntegerArgument; import cloud.commandframework.arguments.standard.IntegerArgument;
import com.google.common.reflect.TypeToken; import io.leangen.geantyref.TypeToken;
import cloud.commandframework.arguments.parser.ArgumentParser; import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.arguments.parser.ParserParameters; import cloud.commandframework.arguments.parser.ParserParameters;
import cloud.commandframework.arguments.parser.ParserRegistry; import cloud.commandframework.arguments.parser.ParserRegistry;
@ -67,7 +67,7 @@ public class ParserRegistryTest {
}; };
final TypeToken<?> parsedType = TypeToken.of(int.class); final TypeToken<?> parsedType = TypeToken.get(int.class);
final ParserParameters parserParameters = parserRegistry.parseAnnotations(parsedType, Collections.singleton(range)); final ParserParameters parserParameters = parserRegistry.parseAnnotations(parsedType, Collections.singleton(range));
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MIN)); Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MIN));
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MAX)); Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MAX));
@ -81,6 +81,14 @@ public class ParserRegistryTest {
(IntegerArgument.IntegerParser<TestCommandSender>) parser; (IntegerArgument.IntegerParser<TestCommandSender>) parser;
Assertions.assertEquals(RANGE_MIN, integerParser.getMin()); Assertions.assertEquals(RANGE_MIN, integerParser.getMin());
Assertions.assertEquals(RANGE_MAX, integerParser.getMax()); Assertions.assertEquals(RANGE_MAX, integerParser.getMax());
/* Test integer */
parserRegistry.createParser(TypeToken.get(int.class), ParserParameters.empty())
.orElseThrow(() -> new IllegalArgumentException("No parser found for int.class"));
/* Test Enum */
parserRegistry.createParser(TypeToken.get(CommandManager.ManagerSettings.class), ParserParameters.empty())
.orElseThrow(() -> new IllegalArgumentException("No parser found for enum"));
} }
} }

View file

@ -1,5 +1,5 @@
dependencies { dependencies {
implementation project(':cloud-core') implementation project(':cloud-core')
/* Needs to be provided by the platform */ /* Needs to be provided by the platform */
implementation 'com.mojang:brigadier:1.0.17' compileOnly 'com.mojang:brigadier:1.0.17'
} }

View file

@ -23,6 +23,8 @@
// //
package cloud.commandframework.brigadier; package cloud.commandframework.brigadier;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.Command; import cloud.commandframework.Command;
import cloud.commandframework.CommandManager; import cloud.commandframework.CommandManager;
import cloud.commandframework.CommandTree; import cloud.commandframework.CommandTree;
@ -41,8 +43,6 @@ import cloud.commandframework.context.CommandContext;
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext; import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
import cloud.commandframework.permission.CommandPermission; import cloud.commandframework.permission.CommandPermission;
import cloud.commandframework.permission.Permission; import cloud.commandframework.permission.Permission;
import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken;
import com.mojang.brigadier.LiteralMessage; import com.mojang.brigadier.LiteralMessage;
import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType;
@ -61,6 +61,7 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -96,8 +97,8 @@ public final class CloudBrigadierManager<C, S> {
public CloudBrigadierManager(@Nonnull final CommandManager<C> commandManager, public CloudBrigadierManager(@Nonnull final CommandManager<C> commandManager,
@Nonnull final Supplier<CommandContext<C>> @Nonnull final Supplier<CommandContext<C>>
dummyContextProvider) { dummyContextProvider) {
this.mappers = Maps.newHashMap(); this.mappers = new HashMap<>();
this.defaultArgumentTypeSuppliers = Maps.newHashMap(); this.defaultArgumentTypeSuppliers = new HashMap<>();
this.commandManager = commandManager; this.commandManager = commandManager;
this.dummyContextProvider = dummyContextProvider; this.dummyContextProvider = dummyContextProvider;
this.registerInternalMappings(); this.registerInternalMappings();
@ -196,7 +197,7 @@ public final class CloudBrigadierManager<C, S> {
public <T, K extends ArgumentParser<C, T>, O> void registerMapping(@Nonnull final TypeToken<K> argumentType, public <T, K extends ArgumentParser<C, T>, O> void registerMapping(@Nonnull final TypeToken<K> argumentType,
@Nonnull final Function<? extends K, @Nonnull final Function<? extends K,
? extends ArgumentType<O>> mapper) { ? extends ArgumentType<O>> mapper) {
this.mappers.put(argumentType.getRawType(), mapper); this.mappers.put(GenericTypeReflector.erase(argumentType.getType()), mapper);
} }
/** /**
@ -217,7 +218,7 @@ public final class CloudBrigadierManager<C, S> {
@Nonnull final TypeToken<T> argumentType, @Nonnull final TypeToken<T> argumentType,
@Nonnull final K argument) { @Nonnull final K argument) {
final ArgumentParser<C, ?> commandArgument = (ArgumentParser<C, ?>) argument; final ArgumentParser<C, ?> commandArgument = (ArgumentParser<C, ?>) argument;
Function function = this.mappers.get(argumentType.getRawType()); Function function = this.mappers.get(GenericTypeReflector.erase(argumentType.getType()));
if (function == null) { if (function == null) {
return this.createDefaultMapper(valueType, commandArgument); return this.createDefaultMapper(valueType, commandArgument);
} }
@ -350,7 +351,7 @@ public final class CloudBrigadierManager<C, S> {
.executes(executor); .executes(executor);
} else { } else {
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(root.getValue().getValueType(), final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(root.getValue().getValueType(),
TypeToken.of(root.getValue().getParser().getClass()), TypeToken.get(root.getValue().getParser().getClass()),
root.getValue().getParser()); root.getValue().getParser());
final SuggestionProvider<S> provider = pair.getRight() ? null : suggestionProvider; final SuggestionProvider<S> provider = pair.getRight() ? null : suggestionProvider;
argumentBuilder = RequiredArgumentBuilder argumentBuilder = RequiredArgumentBuilder

View file

@ -4,29 +4,7 @@ def adventureVersion = '4.0.0-SNAPSHOT'
shadowJar { shadowJar {
dependencies { dependencies {
include(project(':cloud-paper')) exclude(dependency('org.bukkit:bukkit:1.8.8-R0.1-SNAPSHOT'))
include(project(':cloud-annotations'))
include(project(':cloud-minecraft-extras'))
include(project(':cloud-core'))
include(project(':cloud-services'))
include(project(':cloud-brigadier'))
include(project(':cloud-bukkit'))
/* Commodore */
include(dependency('me.lucko:commodore:1.9'))
/* Adventure */
include(dependency("net.kyori:adventure-platform-bukkit:${adventureVersion}"))
include(dependency("net.kyori:adventure-text-minimessage:${adventureVersion}"))
include(dependency("net.kyori:adventure-text-serializer-bungeecord:${adventureVersion}"))
include(dependency("net.kyori:adventure-text-serializer-legacy:${adventureVersion}"))
include(dependency("net.kyori:adventure-text-serializer-gson:${adventureVersion}"))
include(dependency("net.kyori:adventure-api:${adventureVersion}"))
include(dependency("net.kyori:adventure-platform-api:${adventureVersion}"))
include(dependency("net.kyori:adventure-platform-common:${adventureVersion}"))
include(dependency("net.kyori:adventure-platform-viaversion:${adventureVersion}"))
include(dependency("net.kyori:adventure-nbt:${adventureVersion}"))
/* Examination */
include(dependency("net.kyori:examination-api:1.0.0"))
include(dependency("net.kyori:examination-string:1.0.0"))
} }
} }

View file

@ -1,12 +1,6 @@
dependencies { dependencies {
api (project(':cloud-core')) { api project(':cloud-core')
/* Exposed by Bukkit */ api project(':cloud-brigadier')
exclude group: 'com.google.guava', module: 'guava' compileOnly 'org.bukkit:bukkit:1.8.8-R0.1-SNAPSHOT'
} compileOnly 'me.lucko:commodore:1.9'
api (project(':cloud-brigadier')) {
/* Once again exposed by Bukkit */
exclude group: 'com.google.guava', module: 'guava'
}
implementation 'org.bukkit:bukkit:1.8.8-R0.1-SNAPSHOT'
implementation 'me.lucko:commodore:1.9'
} }

View file

@ -28,7 +28,7 @@ import cloud.commandframework.CommandTree;
import cloud.commandframework.bukkit.parsers.MaterialArgument; import cloud.commandframework.bukkit.parsers.MaterialArgument;
import cloud.commandframework.bukkit.parsers.WorldArgument; import cloud.commandframework.bukkit.parsers.WorldArgument;
import cloud.commandframework.execution.CommandExecutionCoordinator; import cloud.commandframework.execution.CommandExecutionCoordinator;
import com.google.common.reflect.TypeToken; import io.leangen.geantyref.TypeToken;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
@ -84,8 +84,8 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
this.backwardsCommandSenderMapper = backwardsCommandSenderMapper; this.backwardsCommandSenderMapper = backwardsCommandSenderMapper;
/* Register Bukkit parsers */ /* Register Bukkit parsers */
this.getParserRegistry().registerParserSupplier(TypeToken.of(World.class), params -> new WorldArgument.WorldParser<>()); this.getParserRegistry().registerParserSupplier(TypeToken.get(World.class), params -> new WorldArgument.WorldParser<>());
this.getParserRegistry().registerParserSupplier(TypeToken.of(Material.class), this.getParserRegistry().registerParserSupplier(TypeToken.get(Material.class),
params -> new MaterialArgument.MaterialParser<>()); params -> new MaterialArgument.MaterialParser<>());
/* Try to determine the Minecraft version */ /* Try to determine the Minecraft version */

View file

@ -1,8 +1,5 @@
dependencies { dependencies {
api (project(':cloud-bukkit')) { api project(':cloud-bukkit')
/* Exposed by Bukkit */
exclude group: 'com.google.guava', module: 'guava'
}
compileOnly 'com.destroystokyo.paper:paper-api:1.15.2-R0.1-SNAPSHOT' compileOnly 'com.destroystokyo.paper:paper-api:1.15.2-R0.1-SNAPSHOT'
compileOnly 'com.destroystokyo.paper:paper-mojangapi:1.15.2-R0.1-SNAPSHOT' compileOnly 'com.destroystokyo.paper:paper-mojangapi:1.15.2-R0.1-SNAPSHOT'
} }

View file

@ -111,7 +111,7 @@ public class DefaultMockService implements MockService {
Example Registration: Example Registration:
```java ```java
servicePipeline.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService()); servicePipeline.registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
``` ```
Example Usage: Example Usage:

View file

@ -1,4 +1,3 @@
dependencies { dependencies {
/* Exposed by Core later on */ api 'io.leangen.geantyref:geantyref:1.3.4'
implementation 'com.google.guava:guava:29.0-jre'
} }

View file

@ -23,7 +23,6 @@
// //
package cloud.commandframework.services; package cloud.commandframework.services;
import com.google.common.base.Objects;
import cloud.commandframework.services.annotations.Order; import cloud.commandframework.services.annotations.Order;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
@ -32,6 +31,7 @@ import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Objects;
class AnnotatedMethodService<Context, Result> implements Service<Context, Result> { class AnnotatedMethodService<Context, Result> implements Service<Context, Result> {
@ -87,12 +87,12 @@ class AnnotatedMethodService<Context, Result> implements Service<Context, Result
return false; return false;
} }
final AnnotatedMethodService<?, ?> that = (AnnotatedMethodService<?, ?>) o; final AnnotatedMethodService<?, ?> that = (AnnotatedMethodService<?, ?>) o;
return Objects.equal(this.methodHandle, that.methodHandle); return Objects.equals(this.methodHandle, that.methodHandle);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(this.methodHandle); return Objects.hash(this.methodHandle);
} }
} }

View file

@ -23,7 +23,7 @@
// //
package cloud.commandframework.services; package cloud.commandframework.services;
import com.google.common.reflect.TypeToken; import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.annotations.ServiceImplementation; import cloud.commandframework.services.annotations.ServiceImplementation;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
@ -53,7 +53,7 @@ enum AnnotatedMethodServiceFactory {
} }
map.put(new AnnotatedMethodService<>(instance, method), map.put(new AnnotatedMethodService<>(instance, method),
TypeToken.of(serviceImplementation.value())); TypeToken.get(serviceImplementation.value()));
} }
return map; return map;
} }

View file

@ -23,7 +23,7 @@
// //
package cloud.commandframework.services; package cloud.commandframework.services;
import com.google.common.reflect.TypeToken; import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -166,7 +166,7 @@ public final class ServicePipeline {
@Nonnull final Class<? extends Service<Context, Result>> type, @Nonnull final Class<? extends Service<Context, Result>> type,
@Nonnull final Service<Context, Result> implementation, @Nonnull final Service<Context, Result> implementation,
@Nonnull final Collection<Predicate<Context>> filters) { @Nonnull final Collection<Predicate<Context>> filters) {
return registerServiceImplementation(TypeToken.of(type), implementation, filters); return registerServiceImplementation(TypeToken.get(type), implementation, filters);
} }
/** /**
@ -227,7 +227,7 @@ public final class ServicePipeline {
Collections.reverse(queue); Collections.reverse(queue);
for (ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>> wrapper : queue) { for (ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>> wrapper : queue) {
collection collection
.add((TypeToken<? extends S>) TypeToken.of(wrapper.getImplementation().getClass())); .add((TypeToken<? extends S>) TypeToken.get(wrapper.getImplementation().getClass()));
} }
return Collections.unmodifiableList(collection); return Collections.unmodifiableList(collection);
} }

View file

@ -23,9 +23,8 @@
// //
package cloud.commandframework.services; package cloud.commandframework.services;
import com.google.common.base.Preconditions;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Objects;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -59,7 +58,7 @@ public final class ServicePipelineBuilder {
*/ */
@Nonnull @Nonnull
public ServicePipelineBuilder withExecutor(@Nonnull final Executor executor) { public ServicePipelineBuilder withExecutor(@Nonnull final Executor executor) {
this.executor = Preconditions.checkNotNull(executor, "Executor may not be null"); this.executor = Objects.requireNonNull(executor, "Executor may not be null");
return this; return this;
} }

View file

@ -23,8 +23,8 @@
// //
package cloud.commandframework.services; package cloud.commandframework.services;
import com.google.common.reflect.TypeToken;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import io.leangen.geantyref.TypeToken;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -66,7 +66,7 @@ public final class ServicePump<Context> {
@Nonnull @Nonnull
public <Result> ServiceSpigot<Context, Result> through( public <Result> ServiceSpigot<Context, Result> through(
@Nonnull final Class<? extends Service<Context, Result>> clazz) { @Nonnull final Class<? extends Service<Context, Result>> clazz) {
return this.through(TypeToken.of(clazz)); return this.through(TypeToken.get(clazz));
} }
} }

View file

@ -23,7 +23,7 @@
// //
package cloud.commandframework.services; package cloud.commandframework.services;
import com.google.common.reflect.TypeToken; import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.annotations.Order; import cloud.commandframework.services.annotations.Order;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
@ -136,7 +136,7 @@ public final class ServiceRepository<Context, Response> {
public String toString() { public String toString() {
return String return String
.format("ServiceWrapper{type=%s,implementation=%s}", serviceType.toString(), .format("ServiceWrapper{type=%s,implementation=%s}", serviceType.toString(),
TypeToken.of(implementation.getClass()).toString()); TypeToken.get(implementation.getClass()).toString());
} }
@Override @Override

View file

@ -23,7 +23,7 @@
// //
package cloud.commandframework.services; package cloud.commandframework.services;
import com.google.common.reflect.TypeToken; import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.types.ConsumerService; import cloud.commandframework.services.types.ConsumerService;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import cloud.commandframework.services.types.SideEffectService; import cloud.commandframework.services.types.SideEffectService;

View file

@ -23,7 +23,8 @@
// //
package cloud.commandframework.services; package cloud.commandframework.services;
import com.google.common.reflect.TypeToken; import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.services.mock.*; import cloud.commandframework.services.mock.*;
import cloud.commandframework.services.types.Service; import cloud.commandframework.services.types.Service;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
@ -38,12 +39,12 @@ public class ServicesTest {
final ServicePipeline servicePipeline = ServicePipeline.builder().build(); final ServicePipeline servicePipeline = ServicePipeline.builder().build();
Assertions.assertNotNull(servicePipeline); Assertions.assertNotNull(servicePipeline);
servicePipeline servicePipeline
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService()); .registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
Assertions.assertThrows(IllegalArgumentException.class, () -> servicePipeline Assertions.assertThrows(IllegalArgumentException.class, () -> servicePipeline
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService())); .registerServiceType(TypeToken.get(MockService.class), new DefaultMockService()));
final SecondaryMockService secondaryMockService = new SecondaryMockService(); final SecondaryMockService secondaryMockService = new SecondaryMockService();
servicePipeline servicePipeline
.registerServiceImplementation(TypeToken.of(MockService.class), secondaryMockService, .registerServiceImplementation(TypeToken.get(MockService.class), secondaryMockService,
Collections.singleton(secondaryMockService)); Collections.singleton(secondaryMockService));
servicePipeline.registerServiceImplementation(MockService.class, servicePipeline.registerServiceImplementation(MockService.class,
mockContext -> new MockService.MockResult(-91), mockContext -> new MockService.MockResult(-91),
@ -69,7 +70,7 @@ public class ServicesTest {
@Test @Test
public void testSideEffectServices() { public void testSideEffectServices() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build(); final ServicePipeline servicePipeline = ServicePipeline.builder().build();
servicePipeline.registerServiceType(TypeToken.of(MockSideEffectService.class), servicePipeline.registerServiceType(TypeToken.get(MockSideEffectService.class),
new DefaultSideEffectService()); new DefaultSideEffectService());
final MockSideEffectService.MockPlayer mockPlayer = final MockSideEffectService.MockPlayer mockPlayer =
new MockSideEffectService.MockPlayer(20); new MockSideEffectService.MockPlayer(20);
@ -88,8 +89,8 @@ public class ServicesTest {
@Test @Test
public void testForwarding() throws Exception { public void testForwarding() throws Exception {
final ServicePipeline servicePipeline = ServicePipeline.builder().build() final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService()) .registerServiceType(TypeToken.get(MockService.class), new DefaultMockService())
.registerServiceType(TypeToken.of(MockResultConsumer.class), new MockResultConsumer()); .registerServiceType(TypeToken.get(MockResultConsumer.class), new MockResultConsumer());
Assertions.assertEquals(State.ACCEPTED, Assertions.assertEquals(State.ACCEPTED,
servicePipeline.pump(new MockService.MockContext("huh")).through(MockService.class) servicePipeline.pump(new MockService.MockContext("huh")).through(MockService.class)
.forward().through(MockResultConsumer.class).getResult()); .forward().through(MockResultConsumer.class).getResult());
@ -103,7 +104,7 @@ public class ServicesTest {
@Test @Test
public void testSorting() { public void testSorting() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build() final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService()); .registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedFirst(), servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedFirst(),
Collections.emptyList()); Collections.emptyList());
servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedLast(), servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedLast(),
@ -117,21 +118,21 @@ public class ServicesTest {
@Test @Test
public void testRecognisedTypes() { public void testRecognisedTypes() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build() final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService()); .registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
Assertions.assertEquals(1, servicePipeline.getRecognizedTypes().size()); Assertions.assertEquals(1, servicePipeline.getRecognizedTypes().size());
} }
@Test @Test
public void testImplementationGetters() { public void testImplementationGetters() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build() final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService()); .registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedFirst(), servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedFirst(),
Collections.emptyList()); Collections.emptyList());
servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedLast(), servicePipeline.registerServiceImplementation(MockService.class, new MockOrderedLast(),
Collections.emptyList()); Collections.emptyList());
final TypeToken<? extends Service<?, ?>> first = TypeToken.of(MockOrderedFirst.class), final TypeToken<? extends Service<?, ?>> first = TypeToken.get(MockOrderedFirst.class),
last = TypeToken.of(MockOrderedLast.class); last = TypeToken.get(MockOrderedLast.class);
final TypeToken<MockService> mockServiceType = TypeToken.of(MockService.class); final TypeToken<MockService> mockServiceType = TypeToken.get(MockService.class);
for (TypeToken<?> typeToken : servicePipeline.getRecognizedTypes()) { for (TypeToken<?> typeToken : servicePipeline.getRecognizedTypes()) {
Assertions.assertEquals(mockServiceType, typeToken); Assertions.assertEquals(mockServiceType, typeToken);
} }
@ -142,13 +143,13 @@ public class ServicesTest {
iterator = impls.iterator(); iterator = impls.iterator();
Assertions.assertEquals(first, iterator.next()); Assertions.assertEquals(first, iterator.next());
Assertions.assertEquals(last, iterator.next()); Assertions.assertEquals(last, iterator.next());
Assertions.assertEquals(DefaultMockService.class, iterator.next().getRawType()); Assertions.assertEquals(DefaultMockService.class, GenericTypeReflector.erase(iterator.next().getType()));
} }
@Test @Test
public void testAnnotatedMethods() throws Exception { public void testAnnotatedMethods() throws Exception {
final ServicePipeline servicePipeline = ServicePipeline.builder().build() final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService()) .registerServiceType(TypeToken.get(MockService.class), new DefaultMockService())
.registerMethods(new AnnotatedMethodTest()); .registerMethods(new AnnotatedMethodTest());
final String testString = UUID.randomUUID().toString(); final String testString = UUID.randomUUID().toString();
Assertions.assertEquals(testString.length(), Assertions.assertEquals(testString.length(),
@ -159,7 +160,7 @@ public class ServicesTest {
@Test @Test
public void testConsumerServices() { public void testConsumerServices() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build() final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockConsumerService.class), .registerServiceType(TypeToken.get(MockConsumerService.class),
new StateSettingConsumerService()) new StateSettingConsumerService())
.registerServiceImplementation(MockConsumerService.class, .registerServiceImplementation(MockConsumerService.class,
new InterruptingMockConsumer(), Collections.emptyList()); new InterruptingMockConsumer(), Collections.emptyList());
@ -171,7 +172,7 @@ public class ServicesTest {
@Test @Test
public void testPartialResultServices() { public void testPartialResultServices() {
final ServicePipeline servicePipeline = ServicePipeline.builder().build() final ServicePipeline servicePipeline = ServicePipeline.builder().build()
.registerServiceType(TypeToken.of(MockPartialResultService.class), .registerServiceType(TypeToken.get(MockPartialResultService.class),
new DefaultPartialRequestService()) new DefaultPartialRequestService())
.registerServiceImplementation(MockPartialResultService.class, .registerServiceImplementation(MockPartialResultService.class,
new CompletingPartialResultService(), Collections.emptyList()); new CompletingPartialResultService(), Collections.emptyList());
@ -191,7 +192,7 @@ public class ServicesTest {
final ServicePipeline servicePipeline = ServicePipeline.builder().build(); final ServicePipeline servicePipeline = ServicePipeline.builder().build();
Assertions.assertNotNull(servicePipeline); Assertions.assertNotNull(servicePipeline);
servicePipeline servicePipeline
.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService()); .registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
final PipelineException pipelineException = Assertions.assertThrows(PipelineException.class, final PipelineException pipelineException = Assertions.assertThrows(PipelineException.class,
() -> servicePipeline.pump(new MockService.MockContext("pls throw exception")) () -> servicePipeline.pump(new MockService.MockContext("pls throw exception"))
.through(MockService.class).getResult()); .through(MockService.class).getResult());