diff --git a/build.gradle b/build.gradle index 93902835..ed030bff 100644 --- a/build.gradle +++ b/build.gradle @@ -34,9 +34,6 @@ dependencies { include implementation("rip.hippo:Doctor:1.0.1") include implementation("javax.inject:javax.inject:1") - include implementation("org.reflections:reflections:0.10.2") - include implementation("org.javassist:javassist:3.30.2-GA") - // Json include implementation("javax.json:javax.json-api:1.1.4") include "org.glassfish:javax.json:1.1.4" diff --git a/src/main/java/tools/redstone/redstonetools/RedstoneToolsClient.java b/src/main/java/tools/redstone/redstonetools/RedstoneToolsClient.java index 66467350..0d8a922c 100644 --- a/src/main/java/tools/redstone/redstonetools/RedstoneToolsClient.java +++ b/src/main/java/tools/redstone/redstonetools/RedstoneToolsClient.java @@ -5,14 +5,10 @@ import net.fabricmc.loader.api.FabricLoader; import net.minecraft.command.argument.serialize.ArgumentSerializer; import net.minecraft.util.Identifier; - -import org.reflections.Reflections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import rip.hippo.inject.Doctor; import rip.hippo.inject.Injector; -import tools.redstone.redstonetools.features.arguments.serializers.GenericArgumentType; import tools.redstone.redstonetools.utils.DependencyLookup; import tools.redstone.redstonetools.utils.ReflectionUtils; @@ -27,7 +23,6 @@ public class RedstoneToolsClient implements ClientModInitializer { public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static final Path CONFIG_DIR = FabricLoader.getInstance().getConfigDir().resolve("redstonetools"); public static final Injector INJECTOR = Doctor.createInjector(ReflectionUtils.getModules()); - public static final Reflections REFLECTIONS = new Reflections("tools.redstone.redstonetools"); @Override public void onInitializeClient() { diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BigIntegerArgumentType.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BigIntegerArgumentType.java index b3651c4a..12167f3c 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BigIntegerArgumentType.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BigIntegerArgumentType.java @@ -1,11 +1,13 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; import java.math.BigInteger; import java.util.Optional; +@AutoService(GenericArgumentType.class) public class BigIntegerArgumentType extends IntLikeArgumentType { private static final BigIntegerArgumentType INSTANCE = new BigIntegerArgumentType(null, null); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockColorSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockColorSerializer.java index b79060f0..9ca9ac82 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockColorSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockColorSerializer.java @@ -1,9 +1,11 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; import tools.redstone.redstonetools.utils.BlockColor; +@AutoService(GenericArgumentType.class) public class BlockColorSerializer extends EnumSerializer { private static final BlockColorSerializer INSTANCE = new BlockColorSerializer(); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockStateArgumentType.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockStateArgumentType.java index 9ce1dbcb..6d5d6bd4 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockStateArgumentType.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockStateArgumentType.java @@ -1,5 +1,6 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.command.CommandRegistryAccess; @@ -7,6 +8,7 @@ import net.minecraft.command.argument.serialize.ArgumentSerializer; import net.minecraft.registry.Registries; +@AutoService(GenericArgumentType.class) public class BlockStateArgumentType extends BrigadierArgumentType { private static BlockStateArgumentType INSTANCE; diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BoolSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BoolSerializer.java index 81c400e1..22c1f8aa 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BoolSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BoolSerializer.java @@ -1,11 +1,13 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; +@AutoService(GenericArgumentType.class) public class BoolSerializer extends StringBrigadierSerializer { private static final BoolSerializer INSTANCE = new BoolSerializer(BoolArgumentType.bool()); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BrigadierArgumentType.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BrigadierArgumentType.java index 846a3bcf..2745f9f1 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BrigadierArgumentType.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BrigadierArgumentType.java @@ -1,5 +1,6 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.context.CommandContext; diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/CollectionSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/CollectionSerializer.java index c01c7ef6..fed8f7a0 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/CollectionSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/CollectionSerializer.java @@ -1,5 +1,6 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -20,6 +21,7 @@ * @param The element type. * @param The collection type. */ +@AutoService(GenericArgumentType.class) public class CollectionSerializer> extends GenericArgumentType> { diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/ColoredBlockTypeSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/ColoredBlockTypeSerializer.java index b19a3ee1..bf79b1c9 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/ColoredBlockTypeSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/ColoredBlockTypeSerializer.java @@ -1,9 +1,11 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; import tools.redstone.redstonetools.utils.ColoredBlockType; +@AutoService(GenericArgumentType.class) public class ColoredBlockTypeSerializer extends EnumSerializer { private static final ColoredBlockTypeSerializer INSTANCE = new ColoredBlockTypeSerializer(); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/DirectionSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/DirectionSerializer.java index daddaeea..0793a737 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/DirectionSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/DirectionSerializer.java @@ -1,9 +1,11 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; import tools.redstone.redstonetools.utils.DirectionArgument; +@AutoService(GenericArgumentType.class) public class DirectionSerializer extends EnumSerializer { private static final DirectionSerializer INSTANCE = new DirectionSerializer(); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/DoubleSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/DoubleSerializer.java index f1c2b394..db6d25d9 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/DoubleSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/DoubleSerializer.java @@ -1,11 +1,13 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.DoubleArgumentType; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; +@AutoService(GenericArgumentType.class) public class DoubleSerializer extends StringBrigadierSerializer { private static final DoubleSerializer INSTANCE = new DoubleSerializer(DoubleArgumentType.doubleArg()); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/FloatSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/FloatSerializer.java index fd9ae6bb..7c6c698f 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/FloatSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/FloatSerializer.java @@ -1,11 +1,13 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.FloatArgumentType; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; +@AutoService(GenericArgumentType.class) public class FloatSerializer extends StringBrigadierSerializer { private static final FloatSerializer INSTANCE = new FloatSerializer(FloatArgumentType.floatArg()); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/IntegerSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/IntegerSerializer.java index bc8bfb4f..990873df 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/IntegerSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/IntegerSerializer.java @@ -2,9 +2,11 @@ import java.util.Optional; +import com.google.auto.service.AutoService; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; +@AutoService(GenericArgumentType.class) public class IntegerSerializer extends IntLikeArgumentType { private static final IntegerSerializer INSTANCE = new IntegerSerializer(Integer.MIN_VALUE, Integer.MAX_VALUE); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/LongSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/LongSerializer.java index 8c2577e3..ec9f9ee2 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/LongSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/LongSerializer.java @@ -2,9 +2,11 @@ import java.util.Optional; +import com.google.auto.service.AutoService; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; +@AutoService(GenericArgumentType.class) public class LongSerializer extends IntLikeArgumentType { private static final LongSerializer INSTANCE = new LongSerializer(Long.MIN_VALUE, Long.MAX_VALUE); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/MacroNameSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/MacroNameSerializer.java index 72ab8516..8769506c 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/MacroNameSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/MacroNameSerializer.java @@ -1,18 +1,18 @@ package tools.redstone.redstonetools.features.arguments.serializers; -import tools.redstone.redstonetools.macros.Macro; -import tools.redstone.redstonetools.macros.MacroManager; +import com.google.auto.service.AutoService; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; - import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; +import tools.redstone.redstonetools.macros.MacroManager; import java.util.concurrent.CompletableFuture; import static tools.redstone.redstonetools.RedstoneToolsClient.INJECTOR; +@AutoService(GenericArgumentType.class) public class MacroNameSerializer extends StringSerializer { private static final MacroNameSerializer INSTANCE = new MacroNameSerializer(); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/NumberBaseArgumentType.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/NumberBaseArgumentType.java index acace7d2..d8dd9b86 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/NumberBaseArgumentType.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/NumberBaseArgumentType.java @@ -1,5 +1,6 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -14,6 +15,7 @@ import java.util.Collection; import java.util.concurrent.CompletableFuture; +@AutoService(GenericArgumentType.class) public class NumberBaseArgumentType extends GenericArgumentType { private static final IntegerSerializer INT_SERIALIZER = IntegerSerializer.integer(2, 36); private static final NumberBaseArgumentType INSTANCE = new NumberBaseArgumentType(); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/NumberSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/NumberSerializer.java index 7c8426f0..7dc6145b 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/NumberSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/NumberSerializer.java @@ -1,5 +1,6 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import tools.redstone.redstonetools.utils.NumberArg; import java.util.Optional; @@ -7,6 +8,7 @@ import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; +@AutoService(GenericArgumentType.class) public class NumberSerializer extends IntLikeArgumentType { private static final NumberSerializer INSTANCE = new NumberSerializer(null, null); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/SignalBlockSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/SignalBlockSerializer.java index 8c76b91d..b517287b 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/SignalBlockSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/SignalBlockSerializer.java @@ -1,9 +1,11 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; import tools.redstone.redstonetools.utils.SignalBlock; +@AutoService(GenericArgumentType.class) public class SignalBlockSerializer extends EnumSerializer { private static final SignalBlockSerializer INSTANCE = new SignalBlockSerializer(); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/StringSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/StringSerializer.java index db8f7b66..6da4e2ca 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/StringSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/StringSerializer.java @@ -1,11 +1,13 @@ package tools.redstone.redstonetools.features.arguments.serializers; +import com.google.auto.service.AutoService; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.serialize.ArgumentSerializer; +@AutoService(GenericArgumentType.class) public class StringSerializer extends StringBrigadierSerializer { private static final StringSerializer INSTANCE_WORD = new StringSerializer(StringArgumentType.word()); diff --git a/src/main/java/tools/redstone/redstonetools/utils/ReflectionUtils.java b/src/main/java/tools/redstone/redstonetools/utils/ReflectionUtils.java index d1f54a95..eaab5ad7 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/ReflectionUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/ReflectionUtils.java @@ -1,25 +1,9 @@ package tools.redstone.redstonetools.utils; -import static tools.redstone.redstonetools.RedstoneToolsClient.REFLECTIONS; - -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.net.URL; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; - import org.apache.commons.io.IOUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; - import rip.hippo.inject.DoctorModule; import sun.misc.Unsafe; import tools.redstone.redstonetools.features.AbstractFeature; @@ -27,6 +11,14 @@ import tools.redstone.redstonetools.features.arguments.Argument; import tools.redstone.redstonetools.features.arguments.serializers.GenericArgumentType; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.net.URL; +import java.util.*; +import java.util.stream.Collectors; + public class ReflectionUtils { private static final Logger LOGGER = LogManager.getLogger(); private static DoctorModule[] modules; @@ -81,8 +73,14 @@ public static DoctorModule[] getModules() { public static Set> getAllArguments() { if (arguments == null) { - arguments = REFLECTIONS.getSubTypesOf(GenericArgumentType.class).stream() - .filter(argument -> !Modifier.isAbstract(argument.getModifiers())).collect(Collectors.toSet()); + try { + arguments = findClasses(GenericArgumentType.class) + .stream() + .filter(argument -> !Modifier.isAbstract(argument.getModifiers())) + .collect(Collectors.toSet()); + } catch (IOException e) { + throw new RuntimeException(e); + } } return arguments; @@ -99,7 +97,7 @@ public static Set getFeatures() { return features; } - private static Set serviceLoad(Class clazz) throws IOException { + public static Set> findClasses(Class clazz) throws IOException { ClassLoader cl = ReflectionUtils.class.getClassLoader(); Enumeration serviceFiles = cl.getResources("META-INF/services/" + clazz.getName()); Set classNames = new HashSet<>(); @@ -109,11 +107,19 @@ private static Set serviceLoad(Class clazz) throws IOExcepti classNames.addAll(IOUtils.readLines(reader, "UTF-8")); } } - return classNames.stream() + //noinspection unchecked + return (Set>) classNames.stream() .filter(it -> !it.isEmpty() && !it.isBlank()) .map(ReflectionUtils::loadClass) .filter(Objects::nonNull) .filter(clazz::isAssignableFrom) + .map(clazz::cast) + .collect(Collectors.toSet()); + } + + private static Set serviceLoad(Class clazz) throws IOException { + return findClasses(clazz) + .stream() .map(it -> { try { return it.getDeclaredConstructor().newInstance();