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

View file

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

View file

@ -1,6 +1,5 @@
dependencies {
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-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.CommandPreprocessor;
import cloud.commandframework.internal.CommandRegistrationHandler;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.permission.CommandPermission;
import cloud.commandframework.permission.OrPermission;
@ -59,6 +57,7 @@ import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -76,13 +75,13 @@ import java.util.function.Function;
@SuppressWarnings("unused")
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 CommandContextFactory<C> commandContextFactory = new StandardCommandContextFactory<>();
private final ServicePipeline servicePipeline = ServicePipeline.builder().build();
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 CommandTree<C> commandTree;

View file

@ -24,7 +24,7 @@
package cloud.commandframework.arguments;
import cloud.commandframework.arguments.parser.ArgumentParser;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
@ -180,7 +180,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
@Nonnull
public static <C, T> CommandArgument.Builder<C, T> ofType(@Nonnull final Class<T> clazz,
@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;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.TypeToken;
import javax.annotation.Nonnull;
import java.util.Objects;

View file

@ -23,10 +23,9 @@
//
package cloud.commandframework.arguments.parser;
import com.google.common.collect.Maps;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
@ -34,7 +33,7 @@ import java.util.Map;
*/
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

View file

@ -23,7 +23,7 @@
//
package cloud.commandframework.arguments.parser;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.TypeToken;
import javax.annotation.Nonnull;
import java.lang.annotation.Annotation;
@ -34,7 +34,7 @@ import java.util.function.Function;
/**
* 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
*
* @param <C> Command sender type

View file

@ -23,7 +23,7 @@
//
package cloud.commandframework.arguments.parser;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.TypeToken;
import javax.annotation.Nonnull;
@ -35,27 +35,27 @@ public final class StandardParameters {
/**
* 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
*/
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
*/
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
*/
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
*/
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
*/
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() {
}

View file

@ -23,8 +23,6 @@
//
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.Range;
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.ShortArgument;
import cloud.commandframework.arguments.standard.StringArgument;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import javax.annotation.Nonnull;
import java.lang.annotation.Annotation;
@ -54,16 +54,18 @@ import java.util.function.Function;
*/
public final class StandardParserRegistry<C> implements ParserRegistry<C> {
private static final Map<Class<?>, Class<?>> PRIMITIVE_MAPPINGS = ImmutableMap.<Class<?>, Class<?>>builder()
.put(char.class, Character.class)
.put(int.class, Integer.class)
.put(short.class, Short.class)
.put(byte.class, Byte.class)
.put(float.class, Float.class)
.put(double.class, Double.class)
.put(long.class, Long.class)
.put(boolean.class, Boolean.class)
.build();
private static final Map<Class<?>, Class<?>> PRIMITIVE_MAPPINGS = new HashMap<Class<?>, Class<?>>() {
{
put(char.class, Character .class);
put(int.class, Integer .class);
put(short.class, Short .class);
put(byte.class, Byte .class);
put(float.class, Float .class);
put(double.class, Double .class);
put(long.class, Long .class);
put(boolean.class, Boolean .class);
}
};
private final Map<String, Function<ParserParameters, ArgumentParser<C, ?>>> namedParsers = 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());
/* 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),
(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),
(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),
(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),
(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),
(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 */
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) ->
Arrays.asList(options.get(StandardParameters.COMPLETIONS, new String[0]))));
/* 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
@ -146,17 +148,17 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
public <T> Optional<ArgumentParser<C, T>> createParser(@Nonnull final TypeToken<T> type,
@Nonnull final ParserParameters parserParameters) {
final TypeToken<?> actualType;
if (type.isPrimitive()) {
actualType = TypeToken.of(PRIMITIVE_MAPPINGS.get(type.getRawType()));
if (GenericTypeReflector.erase(type.getType()).isPrimitive()) {
actualType = TypeToken.get(PRIMITIVE_MAPPINGS.get(GenericTypeReflector.erase(type.getType())));
} else {
actualType = type;
}
final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.parserSuppliers.get(actualType);
if (producer == null) {
/* Give enums special treatment */
if (actualType.isSubtypeOf(Enum.class)) {
if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {
@SuppressWarnings("all") final EnumArgument.EnumParser enumArgument
= new EnumArgument.EnumParser((Class<Enum>) actualType.getRawType());
= new EnumArgument.EnumParser((Class<Enum>) GenericTypeReflector.erase(actualType.getType()));
// noinspection all
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> {
@Override
public ParserParameters apply(final Range range, final TypeToken<?> type) {
final Class<?> clazz;
if (type.isPrimitive()) {
clazz = PRIMITIVE_MAPPINGS.get(type.getRawType());
if (isPrimitive(type)) {
clazz = PRIMITIVE_MAPPINGS.get(GenericTypeReflector.erase(type.getType()));
} else {
clazz = type.getRawType();
clazz = GenericTypeReflector.erase(type.getType());
}
if (!Number.class.isAssignableFrom(clazz)) {
return ParserParameters.empty();
@ -256,7 +263,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
@Override
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(",");
return ParserParameters.single(StandardParameters.COMPLETIONS, splitCompletions);
}

View file

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

View file

@ -23,16 +23,17 @@
//
package cloud.commandframework.extra.confirmation;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import cloud.commandframework.CommandManager;
import cloud.commandframework.execution.CommandExecutionHandler;
import cloud.commandframework.execution.postprocessor.CommandPostprocessingContext;
import cloud.commandframework.execution.postprocessor.CommandPostprocessor;
import cloud.commandframework.meta.SimpleCommandMeta;
import cloud.commandframework.services.types.ConsumerService;
import cloud.commandframework.types.tuples.Pair;
import javax.annotation.Nonnull;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@ -55,10 +56,13 @@ public class CommandConfirmationManager<C> {
* Meta data stored for commands that 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<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
@ -74,7 +78,13 @@ public class CommandConfirmationManager<C> {
@Nonnull final Consumer<C> errorNotifier) {
this.notifier = notifier;
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) {
@ -82,7 +92,7 @@ public class CommandConfirmationManager<C> {
}
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
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;
import com.google.common.base.Objects;
import javax.annotation.Nonnull;
import java.util.Objects;
/**
* Immutable generic 2-tuple
@ -90,13 +89,13 @@ public class Pair<U, V> implements Tuple {
return false;
}
final Pair<?, ?> pair = (Pair<?, ?>) o;
return Objects.equal(getFirst(), pair.getFirst())
&& Objects.equal(getSecond(), pair.getSecond());
return Objects.equals(getFirst(), pair.getFirst())
&& Objects.equals(getSecond(), pair.getSecond());
}
@Override
public final int hashCode() {
return Objects.hashCode(getFirst(), getSecond());
return Objects.hash(getFirst(), getSecond());
}
@Override

View file

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

View file

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

View file

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

View file

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

View file

@ -25,7 +25,7 @@ package cloud.commandframework;
import cloud.commandframework.annotations.specifier.Range;
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.ParserParameters;
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));
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MIN));
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MAX));
@ -81,6 +81,14 @@ public class ParserRegistryTest {
(IntegerArgument.IntegerParser<TestCommandSender>) parser;
Assertions.assertEquals(RANGE_MIN, integerParser.getMin());
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 {
implementation project(':cloud-core')
/* 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;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.CommandTree;
@ -41,8 +43,6 @@ import cloud.commandframework.context.CommandContext;
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
import cloud.commandframework.permission.CommandPermission;
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.arguments.ArgumentType;
import com.mojang.brigadier.arguments.BoolArgumentType;
@ -61,6 +61,7 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -96,8 +97,8 @@ public final class CloudBrigadierManager<C, S> {
public CloudBrigadierManager(@Nonnull final CommandManager<C> commandManager,
@Nonnull final Supplier<CommandContext<C>>
dummyContextProvider) {
this.mappers = Maps.newHashMap();
this.defaultArgumentTypeSuppliers = Maps.newHashMap();
this.mappers = new HashMap<>();
this.defaultArgumentTypeSuppliers = new HashMap<>();
this.commandManager = commandManager;
this.dummyContextProvider = dummyContextProvider;
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,
@Nonnull final Function<? extends K,
? 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 K 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) {
return this.createDefaultMapper(valueType, commandArgument);
}
@ -350,7 +351,7 @@ public final class CloudBrigadierManager<C, S> {
.executes(executor);
} else {
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());
final SuggestionProvider<S> provider = pair.getRight() ? null : suggestionProvider;
argumentBuilder = RequiredArgumentBuilder

View file

@ -4,29 +4,7 @@ def adventureVersion = '4.0.0-SNAPSHOT'
shadowJar {
dependencies {
include(project(':cloud-paper'))
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"))
exclude(dependency('org.bukkit:bukkit:1.8.8-R0.1-SNAPSHOT'))
}
}

View file

@ -1,12 +1,6 @@
dependencies {
api (project(':cloud-core')) {
/* Exposed by Bukkit */
exclude group: 'com.google.guava', module: 'guava'
}
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'
api project(':cloud-core')
api project(':cloud-brigadier')
compileOnly 'org.bukkit:bukkit:1.8.8-R0.1-SNAPSHOT'
compileOnly '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.WorldArgument;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.TypeToken;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
@ -84,8 +84,8 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
this.backwardsCommandSenderMapper = backwardsCommandSenderMapper;
/* Register Bukkit parsers */
this.getParserRegistry().registerParserSupplier(TypeToken.of(World.class), params -> new WorldArgument.WorldParser<>());
this.getParserRegistry().registerParserSupplier(TypeToken.of(Material.class),
this.getParserRegistry().registerParserSupplier(TypeToken.get(World.class), params -> new WorldArgument.WorldParser<>());
this.getParserRegistry().registerParserSupplier(TypeToken.get(Material.class),
params -> new MaterialArgument.MaterialParser<>());
/* Try to determine the Minecraft version */

View file

@ -1,8 +1,5 @@
dependencies {
api (project(':cloud-bukkit')) {
/* Exposed by Bukkit */
exclude group: 'com.google.guava', module: 'guava'
}
api project(':cloud-bukkit')
compileOnly 'com.destroystokyo.paper:paper-api: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:
```java
servicePipeline.registerServiceType(TypeToken.of(MockService.class), new DefaultMockService());
servicePipeline.registerServiceType(TypeToken.get(MockService.class), new DefaultMockService());
```
Example Usage:

View file

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

View file

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

View file

@ -23,7 +23,7 @@
//
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.types.Service;
@ -53,7 +53,7 @@ enum AnnotatedMethodServiceFactory {
}
map.put(new AnnotatedMethodService<>(instance, method),
TypeToken.of(serviceImplementation.value()));
TypeToken.get(serviceImplementation.value()));
}
return map;
}

View file

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

View file

@ -23,9 +23,8 @@
//
package cloud.commandframework.services;
import com.google.common.base.Preconditions;
import javax.annotation.Nonnull;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@ -59,7 +58,7 @@ public final class ServicePipelineBuilder {
*/
@Nonnull
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;
}

View file

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

View file

@ -23,7 +23,7 @@
//
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.Service;
import cloud.commandframework.services.types.SideEffectService;

View file

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