diff --git a/build.gradle.kts b/build.gradle.kts index a4a92c8f..ab70bcde 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,6 +23,7 @@ java { repositories { mavenCentral() + mavenLocal() maven { url = uri("https://repo.papermc.io/repository/maven-public/") } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 77f6267b..452c2911 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ annotations = "24.1.0" # Cloud command system -cloud = "1.8.4" +cloud = "2.0.0-SNAPSHOT" # Gradle plugins shadow = "8.1.1" diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/CommandRegistry.java b/src/main/java/com/thevoxelbox/voxelsniper/command/CommandRegistry.java index cee9ca90..886fa606 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/CommandRegistry.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/CommandRegistry.java @@ -5,24 +5,20 @@ import cloud.commandframework.annotations.Argument; import cloud.commandframework.annotations.MethodCommandExecutionHandler; import cloud.commandframework.annotations.injection.ParameterInjectorRegistry; -import cloud.commandframework.arguments.CommandArgument; -import cloud.commandframework.arguments.parser.StandardParameters; -import cloud.commandframework.arguments.standard.EnumArgument; +import cloud.commandframework.arguments.standard.EnumParser; import cloud.commandframework.bukkit.BukkitCommandManager; import cloud.commandframework.bukkit.CloudBukkitCapabilities; import cloud.commandframework.captions.CaptionVariable; import cloud.commandframework.context.CommandContext; import cloud.commandframework.exceptions.ArgumentParseException; -import cloud.commandframework.exceptions.CommandExecutionException; import cloud.commandframework.exceptions.InvalidCommandSenderException; import cloud.commandframework.exceptions.InvalidSyntaxException; import cloud.commandframework.exceptions.NoPermissionException; +import cloud.commandframework.exceptions.handling.ExceptionHandler; import cloud.commandframework.exceptions.parsing.ParserException; import cloud.commandframework.execution.CommandExecutionCoordinator; import cloud.commandframework.execution.FilteringCommandSuggestionProcessor; import cloud.commandframework.keys.CloudKey; -import cloud.commandframework.keys.SimpleCloudKey; -import cloud.commandframework.meta.CommandMeta; import cloud.commandframework.paper.PaperCommandManager; import cloud.commandframework.services.types.ConsumerService; import com.fastasyncworldedit.core.configuration.Caption; @@ -59,19 +55,19 @@ public class CommandRegistry { - public static final CloudKey SNIPE_KEY = createTypeKey( + public static final CloudKey SNIPE_KEY = createCloudKey( "snipe", Snipe.class ); - public static final CloudKey PERFORMER_SNIPE_KEY = createTypeKey( + public static final CloudKey PERFORMER_SNIPE_KEY = createCloudKey( "snipe", PerformerSnipe.class ); - public static final CloudKey TOOLKIT_KEY = createTypeKey( + public static final CloudKey TOOLKIT_KEY = createCloudKey( "toolkit", Toolkit.class ); private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); private static final String NO_DESCRIPTION = "No Description."; - private static final CommandMeta.Key REQUIRE_TOOLKIT = createMetaKey( + private static final CloudKey REQUIRE_TOOLKIT = createCloudKey( "require-toolkit", Boolean.class ); @@ -138,18 +134,16 @@ private BukkitCommandManager createCommandManager() throws Exce // Handles post-processor. commandManager.registerCommandPostProcessor(context -> { // Ensures that we are working with a voxel sniper annotated command. - CommandContext commandContext = context.getCommandContext(); - Command command = context.getCommand(); - if (!(commandContext.getSender() instanceof Sniper sniper) - || !(command.getCommandExecutionHandler() instanceof MethodCommandExecutionHandler handler)) { + CommandContext commandContext = context.commandContext(); + Command command = context.command(); + if (!(commandContext.sender() instanceof Sniper sniper) + || !(command.commandExecutionHandler() instanceof MethodCommandExecutionHandler handler)) { return; } Toolkit toolkit; // Toolkit requirement relies on the custom annotation. - if (command.getCommandMeta() - .get(REQUIRE_TOOLKIT) - .orElse(false)) { + if (command.commandMeta().getOrDefault(REQUIRE_TOOLKIT, false)) { if ((toolkit = sniper.getCurrentToolkit()) == null) { sniper.print(Caption.of("voxelsniper.command.missing-toolkit")); ConsumerService.interrupt(); @@ -181,54 +175,49 @@ private BukkitCommandManager createCommandManager() throws Exce }); // Handles exceptions. - commandManager.registerExceptionHandler(InvalidSyntaxException.class, (commander, e) -> - commander.print(Caption.of( + commandManager.exceptionController().registerHandler(InvalidSyntaxException.class, ctx -> + ctx.context().sender().print(Caption.of( "voxelsniper.command.invalid-command-syntax", - e.getCorrectSyntax() - ))); - commandManager.registerExceptionHandler(InvalidCommandSenderException.class, (commander, e) -> - commander.print(Caption.of( + ctx.exception().getCorrectSyntax() + )) + ).registerHandler(InvalidCommandSenderException.class, ctx -> + ctx.context().sender().print(Caption.of( "voxelsniper.command.invalid-sender-type", - e.getRequiredSender().getSimpleName() - ))); - commandManager.registerExceptionHandler(NoPermissionException.class, (commander, e) -> - commander.print(Caption.of( + ctx.exception().getRequiredSender().getSimpleName() + )) + ).registerHandler(NoPermissionException.class, ctx -> + ctx.context().sender().print(Caption.of( "voxelsniper.command.missing-permission", - e.getMissingPermission() - ))); - commandManager.registerExceptionHandler(ArgumentParseException.class, (commander, e) -> { - Throwable t = e.getCause(); - - if (t instanceof VoxelCommandElementParseException ve) { - commander.print(ve.getErrorMessage()); - } else if (t instanceof EnumArgument.EnumParseException ee) { - commander.print(Caption.of( + ctx.exception().missingPermission() + )) + ).registerHandler( + ArgumentParseException.class, + ExceptionHandler.unwrappingHandler() + ).registerHandler(VoxelCommandElementParseException.class, ctx -> + ctx.context().sender().print(ctx.exception().getErrorMessage()) + ).registerHandler(EnumParser.EnumParseException.class, ctx -> + ctx.context().sender().print(Caption.of( "voxelsniper.command.invalid-enum", - ee.getInput(), + ctx.exception().getInput(), VoxelSniperText.formatList( - Arrays.stream(ee.getEnumClass().getEnumConstants()).toList(), + Arrays.stream(ctx.exception().getEnumClass().getEnumConstants()).toList(), (value, value2) -> Integer.compare(value.ordinal(), value2.ordinal()), value -> TextComponent.of(value.name().toLowerCase(Locale.ROOT)), "voxelsniper.command.invalid-enum" ) - )); - } else if (t instanceof ParserException pe) { - commander.print(Caption.of( - pe.errorCaption() - .getKey() + )) + ).registerHandler(ParserException.class, ctx -> + ctx.context().sender().print(Caption.of( + ctx.exception().errorCaption() + .key() .replace("argument.parse.failure.", "voxelsniper.command.invalid-"), - Arrays.stream(pe.captionVariables()) - .map(CaptionVariable::getValue) + Arrays.stream(ctx.exception().captionVariables()) + .map(CaptionVariable::value) .toArray(Object[]::new) - )); - } else { - commander.print(Caption.of("voxelsniper.error.unexpected")); - e.printStackTrace(); - } - }); - commandManager.registerExceptionHandler(CommandExecutionException.class, (commander, e) -> { - commander.print(Caption.of("voxelsniper.error.unexpected")); - e.printStackTrace(); + )) + ).registerHandler(Throwable.class, ctx -> { + ctx.context().sender().print(Caption.of("voxelsniper.error.unexpected")); + ctx.exception().printStackTrace(); }); return commandManager; @@ -238,11 +227,7 @@ private AnnotationParser createAnnotationParser(BukkitCommandMa // Creates the annotation parser. AnnotationParser annotationParser = new AnnotationParser<>( commandManager, - SniperCommander.class, - parserParameters -> CommandMeta.simple() - .with(CommandMeta.DESCRIPTION, parserParameters - .get(StandardParameters.DESCRIPTION, NO_DESCRIPTION)) - .build() + SniperCommander.class ); // Handles the custom annotations. @@ -290,7 +275,7 @@ private void handleDynamicRanges( MethodCommandExecutionHandler handler, Object instance ) { - SniperCommander commander = commandContext.getSender(); + SniperCommander commander = commandContext.sender(); MethodCommandExecutionHandler.CommandMethodContext methodContext = handler.context(); // Dynamic range is based on executor instance fields, we must postprocess them manually. @@ -310,9 +295,7 @@ private void handleDynamicRanges( argumentName = this.annotationParser.processString(argumentAnnotation.value()); } - CommandArgument argument = - (CommandArgument) methodContext.commandArguments().get(argumentName); - double number = commandContext.get(argument).doubleValue(); + double number = commandContext.get(argumentName).doubleValue(); DynamicRange dynamicRangeAnnotation = parameter.getAnnotation(DynamicRange.class); String min = dynamicRangeAnnotation.min(); @@ -444,12 +427,8 @@ public AnnotationParser getAnnotationParser() { return annotationParser; } - private static CloudKey createTypeKey(String id, Class clazz) { - return SimpleCloudKey.of("voxelsniper-" + id, TypeToken.get(clazz)); - } - - private static CommandMeta.Key createMetaKey(String id, Class clazz) { - return CommandMeta.Key.of(TypeToken.get(clazz), "voxelsniper-" + id); + private static CloudKey createCloudKey(String id, Class clazz) { + return CloudKey.of("voxelsniper-" + id, TypeToken.get(clazz)); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelMethodCommandExecutionHandler.java b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelMethodCommandExecutionHandler.java index a3841e81..6d25bb08 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelMethodCommandExecutionHandler.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelMethodCommandExecutionHandler.java @@ -8,6 +8,7 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.util.function.Function; +import java.util.stream.Collectors; public class VoxelMethodCommandExecutionHandler extends MethodCommandExecutionHandler { @@ -40,7 +41,7 @@ public void execute(@NonNull CommandContext commandContext) { commandContext, commandContext.flags(), super.parameters() - ) + ).stream().map(ParameterValue::value).collect(Collectors.toList()) ); } catch (final Error e) { throw e; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractFileArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractFileArgument.java index e2294f89..8948d78a 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractFileArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractFileArgument.java @@ -1,6 +1,7 @@ package com.thevoxelbox.voxelsniper.command.argument; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import cloud.commandframework.exceptions.parsing.NoInputProvidedException; import com.fastasyncworldedit.core.configuration.Caption; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; @@ -11,8 +12,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.List; -import java.util.Queue; import java.util.stream.Stream; public abstract class AbstractFileArgument implements VoxelCommandElement { @@ -41,29 +40,26 @@ public AbstractFileArgument(VoxelSniperPlugin plugin, Path rootPath, String exte } } - protected List suggestFiles(CommandContext commandContext, String input) { + protected Stream suggestFiles(CommandContext commandContext, String input) { Path inputPath = rootPath.resolve(input); try (Stream files = Files.list(Files.isDirectory(inputPath) ? inputPath : inputPath.getParent())) { return files.map(path -> path.getFileName().toString()) - .flatMap(path -> Stream.of(path, path.replace(extension, ""))) - .toList(); + .flatMap(path -> Stream.of(path, path.replace(extension, ""))); } catch (IOException e) { throw new RuntimeException(e); } } - protected File parseFile(CommandContext commandContext, Queue inputQueue) { - String input = inputQueue.peek(); - if (input == null) { + protected File parseFile(CommandContext commandContext, CommandInput input) { + if (input.peekString().isEmpty()) { throw new NoInputProvidedException(AbstractFileArgument.class, commandContext); } + final String fileName = input.readString(); try { - File file = rootPath.resolve(input.endsWith(extension) ? input : input + extension).toFile(); - inputQueue.remove(); - return file; + return rootPath.resolve(fileName.endsWith(extension) ? fileName : fileName + extension).toFile(); } catch (Exception e) { - throw new VoxelCommandElementParseException(input, Caption.of( + throw new VoxelCommandElementParseException(fileName, Caption.of( "voxelsniper.command.invalid-file", input )); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractPatternArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractPatternArgument.java index 2773673c..b722b2a6 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractPatternArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractPatternArgument.java @@ -1,6 +1,7 @@ package com.thevoxelbox.voxelsniper.command.argument; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import cloud.commandframework.exceptions.parsing.NoInputProvidedException; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.extension.input.InputParseException; @@ -16,7 +17,6 @@ import java.util.List; import java.util.Locale; -import java.util.Queue; public abstract class AbstractPatternArgument implements VoxelCommandElement { @@ -44,32 +44,31 @@ protected List suggestPatterns(CommandContext commandCo return factory.getSuggestions(input); } - protected BrushPattern parsePattern(CommandContext commandContext, Queue inputQueue) { - String input = inputQueue.peek(); - if (input == null) { + protected BrushPattern parsePattern(CommandContext commandContext, CommandInput input) { + if (input.peekString().isEmpty()) { throw new NoInputProvidedException(AbstractPatternArgument.class, commandContext); } - SniperCommander commander = commandContext.getSender(); + SniperCommander commander = commandContext.sender(); ParserContext parserContext = commander.createParserContext(); + String patternString = input.readString(); try { T pattern = factory.parseFromInput( - input.toLowerCase(Locale.ROOT), + patternString.toLowerCase(Locale.ROOT), parserContext ); CommandSender sender = commander.getCommandSender(); if (!sender.hasPermission("voxelsniper.ignorelimitations") - && config.getLitesniperRestrictedMaterials().contains(getPatternResource(input, pattern))) { - throw new VoxelCommandElementParseException(input, Caption.of( + && config.getLitesniperRestrictedMaterials().contains(getPatternResource(patternString, pattern))) { + throw new VoxelCommandElementParseException(patternString, Caption.of( "voxelsniper.command.not-allowed", input )); } - inputQueue.remove(); - return new BrushPattern(pattern, input); + return new BrushPattern(pattern, patternString); } catch (InputParseException e) { - throw new VoxelCommandElementParseException(input, Caption.of( + throw new VoxelCommandElementParseException(patternString, Caption.of( parseExceptionCaptionKey, input )); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractRegistryArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractRegistryArgument.java index 76e262b8..f7eddbbd 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractRegistryArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractRegistryArgument.java @@ -1,6 +1,7 @@ package com.thevoxelbox.voxelsniper.command.argument; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import cloud.commandframework.exceptions.parsing.NoInputProvidedException; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.registry.Keyed; @@ -9,9 +10,8 @@ import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; import com.thevoxelbox.voxelsniper.sniper.SniperCommander; -import java.util.List; import java.util.Locale; -import java.util.Queue; +import java.util.stream.Stream; public abstract class AbstractRegistryArgument implements VoxelCommandElement { @@ -33,17 +33,16 @@ public AbstractRegistryArgument(VoxelSniperPlugin plugin, NamespacedRegistry this.parseExceptionCaptionKey = parseExceptionCaptionKey; } - protected List suggestValues(CommandContext commandContext, String input) { - return registry.getSuggestions(input) - .toList(); + protected Stream suggestValues(CommandContext commandContext, String input) { + return registry.getSuggestions(input); } - protected T parseValue(CommandContext commandContext, Queue inputQueue) { - String input = inputQueue.peek(); - if (input == null) { + protected T parseValue(CommandContext commandContext, CommandInput commandInput) { + if (commandInput.peekString().isEmpty()) { throw new NoInputProvidedException(AbstractRegistryArgument.class, commandContext); } + final String input = commandInput.readString(); T value = registry.get(input.toLowerCase(Locale.ROOT)); if (value == null) { throw new VoxelCommandElementParseException(input, Caption.of( @@ -52,7 +51,6 @@ protected T parseValue(CommandContext commandContext, Queue { @@ -23,13 +23,13 @@ public BiomeTypeArgument(VoxelSniperPlugin plugin) { } @Suggestions("biome-type_suggestions") - public List suggestBiomeTypes(CommandContext commandContext, String input) { + public Stream suggestBiomeTypes(CommandContext commandContext, String input) { return super.suggestValues(commandContext, input); } @Parser(suggestions = "biome-type_suggestions") - public BiomeType parseBiomeType(CommandContext commandContext, Queue inputQueue) { - return super.parseValue(commandContext, inputQueue); + public BiomeType parseBiomeType(CommandContext commandContext, CommandInput commandInput) { + return super.parseValue(commandContext, commandInput); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockArgument.java index 73dd49da..fa128e32 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockArgument.java @@ -3,6 +3,7 @@ import cloud.commandframework.annotations.parsers.Parser; import cloud.commandframework.annotations.suggestions.Suggestions; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.world.block.BaseBlock; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; @@ -10,7 +11,6 @@ import com.thevoxelbox.voxelsniper.sniper.SniperCommander; import java.util.List; -import java.util.Queue; public class BlockArgument extends AbstractPatternArgument { @@ -30,8 +30,8 @@ public List suggestBlocks(CommandContext commandContext } @Parser(name = "block_parser", suggestions = "block_suggestions") - public BrushPattern parseBlock(CommandContext commandContext, Queue inputQueue) { - return super.parsePattern(commandContext, inputQueue); + public BrushPattern parseBlock(CommandContext commandContext, CommandInput commandInput) { + return super.parsePattern(commandContext, commandInput); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockTypeArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockTypeArgument.java index f286f89f..234c50c6 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockTypeArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockTypeArgument.java @@ -3,12 +3,14 @@ import cloud.commandframework.annotations.parsers.Parser; import cloud.commandframework.annotations.suggestions.Suggestions; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import com.sk89q.worldedit.world.block.BlockType; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; import com.thevoxelbox.voxelsniper.sniper.SniperCommander; import java.util.List; import java.util.Queue; +import java.util.stream.Stream; public class BlockTypeArgument extends AbstractRegistryArgument { @@ -23,13 +25,13 @@ public BlockTypeArgument(VoxelSniperPlugin plugin) { } @Suggestions("block-type_suggestions") - public List suggestBlockTypes(CommandContext commandContext, String input) { + public Stream suggestBlockTypes(CommandContext commandContext, String input) { return super.suggestValues(commandContext, input); } @Parser(suggestions = "block-type_suggestions") - public BlockType parseBlockType(CommandContext commandContext, Queue inputQueue) { - return super.parseValue(commandContext, inputQueue); + public BlockType parseBlockType(CommandContext commandContext, CommandInput commandInput) { + return super.parseValue(commandContext, commandInput); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BrushPropertiesArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BrushPropertiesArgument.java index 8f1294cf..049c2d12 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BrushPropertiesArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BrushPropertiesArgument.java @@ -3,6 +3,7 @@ import cloud.commandframework.annotations.parsers.Parser; import cloud.commandframework.annotations.suggestions.Suggestions; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import cloud.commandframework.exceptions.parsing.NoInputProvidedException; import com.fastasyncworldedit.core.configuration.Caption; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; @@ -15,6 +16,7 @@ import java.util.List; import java.util.Map; import java.util.Queue; +import java.util.stream.Stream; public class BrushPropertiesArgument implements VoxelCommandElement { @@ -33,26 +35,25 @@ public BrushPropertiesArgument(VoxelSniperPlugin plugin) { } @Suggestions("brush-properties_suggestions") - public List suggestBrushProperties(CommandContext commandContext, String input) { - SniperCommander commander = commandContext.getSender(); + public Stream suggestBrushProperties(CommandContext commandContext, String input) { + SniperCommander commander = commandContext.sender(); CommandSender sender = commander.getCommandSender(); return brushRegistry.getBrushesProperties().entrySet().stream() .filter(entry -> { String permission = entry.getValue().getPermission(); return permission == null || sender.hasPermission(permission); }) - .map(Map.Entry::getKey) - .toList(); + .map(Map.Entry::getKey); } @Parser(name = "brush-properties_parser", suggestions = "brush-properties_suggestions") - public BrushProperties parseBrushProperties(CommandContext commandContext, Queue inputQueue) { - String input = inputQueue.peek(); - if (input == null) { + public BrushProperties parseBrushProperties(CommandContext commandContext, CommandInput commandInput) { + if (commandInput.peekString().isEmpty()) { throw new NoInputProvidedException(BrushPropertiesArgument.class, commandContext); } - SniperCommander commander = commandContext.getSender(); + SniperCommander commander = commandContext.sender(); + String input = commandInput.readString(); BrushProperties properties = brushRegistry.getBrushProperties(input); if (properties == null) { throw new VoxelCommandElementParseException(input, Caption.of( @@ -69,7 +70,6 @@ public BrushProperties parseBrushProperties(CommandContext comm )); } - inputQueue.remove(); return properties; } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityClassArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityClassArgument.java index d263fca6..0c45d89c 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityClassArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityClassArgument.java @@ -3,6 +3,7 @@ import cloud.commandframework.annotations.parsers.Parser; import cloud.commandframework.annotations.suggestions.Suggestions; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import cloud.commandframework.exceptions.parsing.NoInputProvidedException; import com.fastasyncworldedit.core.configuration.Caption; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; @@ -14,7 +15,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Queue; public class EntityClassArgument implements VoxelCommandElement { @@ -57,12 +57,12 @@ public List suggestEntityClasses(CommandContext commandContext, } @Parser(name = "entity-class_parser", suggestions = "entity-class_suggestions") - public Class parseEntityClass(CommandContext commandContext, Queue inputQueue) { - String input = inputQueue.peek(); - if (input == null) { + public Class parseEntityClass(CommandContext commandContext, CommandInput commandInput) { + if (commandInput.peekString().isEmpty()) { throw new NoInputProvidedException(EntityClassArgument.class, commandContext); } + String input = commandInput.readString(); Class clazz = getEntityClass(input); if (clazz == null) { throw new VoxelCommandElementParseException(input, Caption.of( @@ -71,7 +71,6 @@ public Class parseEntityClass(CommandContext commandCo )); } - inputQueue.remove(); return clazz; } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityTypeArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityTypeArgument.java index 5fa8d4c9..8f840ec5 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityTypeArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityTypeArgument.java @@ -3,12 +3,12 @@ import cloud.commandframework.annotations.parsers.Parser; import cloud.commandframework.annotations.suggestions.Suggestions; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import com.sk89q.worldedit.world.entity.EntityType; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; import com.thevoxelbox.voxelsniper.sniper.SniperCommander; -import java.util.List; -import java.util.Queue; +import java.util.stream.Stream; public class EntityTypeArgument extends AbstractRegistryArgument { @@ -23,13 +23,13 @@ public EntityTypeArgument(VoxelSniperPlugin plugin) { } @Suggestions("entity-type_suggestions") - public List suggestEntityTypes(CommandContext commandContext, String input) { + public Stream suggestEntityTypes(CommandContext commandContext, String input) { return super.suggestValues(commandContext, input); } @Parser(suggestions = "entity-type_suggestions") - public EntityType parseEntityType(CommandContext commandContext, Queue inputQueue) { - return super.parseValue(commandContext, inputQueue); + public EntityType parseEntityType(CommandContext commandContext, CommandInput commandInput) { + return super.parseValue(commandContext, commandInput); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/PatternArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/PatternArgument.java index af7bccf4..c81ca251 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/PatternArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/PatternArgument.java @@ -3,13 +3,13 @@ import cloud.commandframework.annotations.parsers.Parser; import cloud.commandframework.annotations.suggestions.Suggestions; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import com.sk89q.worldedit.function.pattern.Pattern; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; import com.thevoxelbox.voxelsniper.brush.property.BrushPattern; import com.thevoxelbox.voxelsniper.sniper.SniperCommander; import java.util.List; -import java.util.Queue; public class PatternArgument extends AbstractPatternArgument { @@ -29,8 +29,8 @@ public List suggestPatterns(CommandContext commandConte } @Parser(name = "pattern_parser", suggestions = "pattern_suggestions") - public BrushPattern parsePattern(CommandContext commandContext, Queue inputQueue) { - return super.parsePattern(commandContext, inputQueue); + public BrushPattern parsePattern(CommandContext commandContext, CommandInput commandInput) { + return super.parsePattern(commandContext, commandInput); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/SignFileArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/SignFileArgument.java index 469a5015..e3a9f3db 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/SignFileArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/SignFileArgument.java @@ -3,12 +3,12 @@ import cloud.commandframework.annotations.parsers.Parser; import cloud.commandframework.annotations.suggestions.Suggestions; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; import com.thevoxelbox.voxelsniper.sniper.SniperCommander; import java.io.File; -import java.util.List; -import java.util.Queue; +import java.util.stream.Stream; public class SignFileArgument extends AbstractFileArgument { @@ -23,13 +23,13 @@ public SignFileArgument(VoxelSniperPlugin plugin) { } @Suggestions("sign-file_suggestions") - public List suggestSignFiles(CommandContext commandContext, String input) { + public Stream suggestSignFiles(CommandContext commandContext, String input) { return super.suggestFiles(commandContext, input); } @Parser(name = "sign-file_parser", suggestions = "sign-file_suggestions") - public File parseSignFile(CommandContext commandContext, Queue inputQueue) { - return super.parseFile(commandContext, inputQueue); + public File parseSignFile(CommandContext commandContext, CommandInput commandInput) { + return super.parseFile(commandContext, commandInput); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilFileArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilFileArgument.java index 0ecf3401..f0516339 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilFileArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilFileArgument.java @@ -3,12 +3,12 @@ import cloud.commandframework.annotations.parsers.Parser; import cloud.commandframework.annotations.suggestions.Suggestions; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; import com.thevoxelbox.voxelsniper.sniper.SniperCommander; import java.io.File; -import java.util.List; -import java.util.Queue; +import java.util.stream.Stream; public class StencilFileArgument extends AbstractFileArgument { @@ -23,13 +23,13 @@ public StencilFileArgument(VoxelSniperPlugin plugin) { } @Suggestions("stencil-file_suggestions") - public List suggestStencilFiles(CommandContext commandContext, String input) { + public Stream suggestStencilFiles(CommandContext commandContext, String input) { return super.suggestFiles(commandContext, input); } @Parser(name = "stencil-file_parser", suggestions = "stencil-file_suggestions") - public File parseStencilFile(CommandContext commandContext, Queue inputQueue) { - return super.parseFile(commandContext, inputQueue); + public File parseStencilFile(CommandContext commandContext, CommandInput commandInput) { + return super.parseFile(commandContext, commandInput); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilListFileArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilListFileArgument.java index bde34549..621837fe 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilListFileArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilListFileArgument.java @@ -3,12 +3,12 @@ import cloud.commandframework.annotations.parsers.Parser; import cloud.commandframework.annotations.suggestions.Suggestions; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; import com.thevoxelbox.voxelsniper.sniper.SniperCommander; import java.io.File; -import java.util.List; -import java.util.Queue; +import java.util.stream.Stream; public class StencilListFileArgument extends AbstractFileArgument { @@ -23,13 +23,13 @@ public StencilListFileArgument(VoxelSniperPlugin plugin) { } @Suggestions("stencil-list-file_suggestions") - public List suggestStencilListFiles(CommandContext commandContext, String input) { + public Stream suggestStencilListFiles(CommandContext commandContext, String input) { return super.suggestFiles(commandContext, input); } @Parser(name = "stencil-list-file_parser", suggestions = "stencil-list-file_suggestions") - public File parseStencilListFile(CommandContext commandContext, Queue inputQueue) { - return super.parseFile(commandContext, inputQueue); + public File parseStencilListFile(CommandContext commandContext, CommandInput commandInput) { + return super.parseFile(commandContext, commandInput); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/ToolkitArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/ToolkitArgument.java index e3222c7f..3442ea35 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/ToolkitArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/ToolkitArgument.java @@ -3,6 +3,7 @@ import cloud.commandframework.annotations.parsers.Parser; import cloud.commandframework.annotations.suggestions.Suggestions; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import cloud.commandframework.exceptions.parsing.NoInputProvidedException; import com.fastasyncworldedit.core.configuration.Caption; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; @@ -10,8 +11,7 @@ import com.thevoxelbox.voxelsniper.sniper.Sniper; import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; -import java.util.List; -import java.util.Queue; +import java.util.stream.Stream; public class ToolkitArgument implements VoxelCommandElement { @@ -28,22 +28,21 @@ public ToolkitArgument(VoxelSniperPlugin plugin) { } @Suggestions("toolkit_suggestions") - public List suggestToolkits(CommandContext commandContext, String input) { - Sniper sniper = commandContext.getSender(); + public Stream suggestToolkits(CommandContext commandContext, String input) { + Sniper sniper = commandContext.sender(); return sniper.getToolkits().stream() .filter(toolkit -> !toolkit.isDefault()) - .map(Toolkit::getToolkitName) - .toList(); + .map(Toolkit::getToolkitName); } @Parser(suggestions = "toolkit_suggestions") - public Toolkit parseToolkit(CommandContext commandContext, Queue inputQueue) { - String input = inputQueue.peek(); - if (input == null) { + public Toolkit parseToolkit(CommandContext commandContext, CommandInput commandInput) { + if (commandInput.peekString().isEmpty()) { throw new NoInputProvidedException(ToolkitArgument.class, commandContext); } - Sniper sniper = commandContext.getSender(); + String input = commandInput.readString(); + Sniper sniper = commandContext.sender(); Toolkit toolkit = sniper.getToolkit(input); if (toolkit == null) { throw new VoxelCommandElementParseException(input, Caption.of( @@ -52,7 +51,6 @@ public Toolkit parseToolkit(CommandContext commandContext, Queue )); } - inputQueue.remove(); return toolkit; } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/VoxelListBlocksArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/VoxelListBlocksArgument.java index 32a16dca..82ef0416 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/VoxelListBlocksArgument.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/VoxelListBlocksArgument.java @@ -3,6 +3,7 @@ import cloud.commandframework.annotations.parsers.Parser; import cloud.commandframework.annotations.suggestions.Suggestions; import cloud.commandframework.context.CommandContext; +import cloud.commandframework.context.CommandInput; import cloud.commandframework.exceptions.parsing.NoInputProvidedException; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.WorldEdit; @@ -14,9 +15,7 @@ import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; import com.thevoxelbox.voxelsniper.sniper.SniperCommander; -import java.util.List; import java.util.Locale; -import java.util.Queue; import java.util.stream.Stream; public class VoxelListBlocksArgument implements VoxelCommandElement { @@ -34,37 +33,36 @@ public VoxelListBlocksArgument(VoxelSniperPlugin plugin) { } @Suggestions("voxel-list-block_suggestions") - public List suggestVoxelListBlocks(CommandContext commandContext, String input) { + public Stream suggestVoxelListBlocks(CommandContext commandContext, String input) { return WorldEdit.getInstance().getBlockFactory() .getSuggestions(input.startsWith("-") ? input.substring(1) : input).stream() - .flatMap(id -> Stream.of(id, "-" + id)) - .toList(); + .flatMap(id -> Stream.of(id, "-" + id)); } @Parser(suggestions = "voxel-list-block_suggestions") - public BlockWrapper[] parseVoxelListBlock(CommandContext commandContext, Queue inputQueue) { - if (inputQueue.isEmpty()) { + public BlockWrapper[] parseVoxelListBlock(CommandContext commandContext, CommandInput commandInput) { + if (commandInput.isEmpty()) { throw new NoInputProvidedException(VoxelListBlocksArgument.class, commandContext); } - BlockWrapper[] blockWrappers = new BlockWrapper[inputQueue.size()]; + BlockWrapper[] blockWrappers = new BlockWrapper[commandInput.remainingTokens()]; int i = 0; - while (!inputQueue.isEmpty()) { - String input = inputQueue.peek(); - SniperCommander commander = commandContext.getSender(); + while (commandInput.hasRemainingInput()) { + SniperCommander commander = commandContext.sender(); ParserContext parserContext = commander.createParserContext(); - boolean remove = input.startsWith("-"); + boolean remove = commandInput.peekString().startsWith("-"); if (remove) { - input = input.substring(1); + commandInput.moveCursor(1); } + + String input = commandInput.readString(); try { BaseBlock baseBlock = WorldEdit.getInstance().getBlockFactory().parseFromInput( - input.toLowerCase(Locale.ROOT), + commandInput.readString().toLowerCase(Locale.ROOT), parserContext ); - inputQueue.remove(); blockWrappers[i++] = new BlockWrapper(baseBlock.toBlockState(), remove); } catch (InputParseException e) { throw new VoxelCommandElementParseException(input, Caption.of( diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushExecutor.java index 0e1ecbb6..331f46bd 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushExecutor.java @@ -1,6 +1,5 @@ package com.thevoxelbox.voxelsniper.command.executor; -import cloud.commandframework.annotations.Argument; import cloud.commandframework.annotations.CommandDescription; import cloud.commandframework.annotations.CommandMethod; import cloud.commandframework.annotations.CommandPermission; @@ -53,7 +52,7 @@ public void onBrush( public void onBrushSize( final @NotNull Sniper sniper, final @NotNull Toolkit toolkit, - final @Argument("size") @Range(min = "0", max = "500") int size + final @Range(min = "0", max = "500") int size ) { ToolkitProperties toolkitProperties = toolkit.getProperties(); Player player = sniper.getPlayer(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushToolkitExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushToolkitExecutor.java index 979ea381..70e0880b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushToolkitExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushToolkitExecutor.java @@ -32,7 +32,7 @@ public BrushToolkitExecutor(VoxelSniperPlugin plugin) { @CommandMethod("assign ") public void onBrushToolkitAssign( final @NotNull Sniper sniper, - final @NotNull @Argument("action") ToolAction action, + final @NotNull ToolAction action, final @NotNull @Argument("toolkit-name") String name ) { Player player = sniper.getPlayer(); @@ -63,7 +63,7 @@ public void onBrushToolkitAssign( @CommandMethod("remove ") public void onBrushToolkitRemove( final @NotNull Sniper sniper, - final @NotNull @Argument("toolkit") Toolkit toolkit + final @NotNull Toolkit toolkit ) { if (toolkit.isDefault()) { sniper.print(Caption.of("voxelsniper.command.toolkit.default-tool")); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/GotoExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/GotoExecutor.java index 2563dbf8..c4e9e114 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/GotoExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/GotoExecutor.java @@ -1,6 +1,5 @@ package com.thevoxelbox.voxelsniper.command.executor; -import cloud.commandframework.annotations.Argument; import cloud.commandframework.annotations.CommandDescription; import cloud.commandframework.annotations.CommandMethod; import cloud.commandframework.annotations.CommandPermission; @@ -27,8 +26,8 @@ public GotoExecutor(VoxelSniperPlugin plugin) { @CommandMethod(" ") public void onGoto( final @NotNull Sniper sniper, - final @Argument("x") int x, - final @Argument("z") int z + final int x, + final int z ) { Player player = sniper.getPlayer(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/PaintExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/PaintExecutor.java index 4156803a..4f982227 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/PaintExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/PaintExecutor.java @@ -1,6 +1,5 @@ package com.thevoxelbox.voxelsniper.command.executor; -import cloud.commandframework.annotations.Argument; import cloud.commandframework.annotations.CommandDescription; import cloud.commandframework.annotations.CommandMethod; import cloud.commandframework.annotations.CommandPermission; @@ -43,7 +42,7 @@ public void onPaintBack( @CommandMethod("") public void onPaintArt( final @NotNull Sniper sniper, - final @Nullable @Argument("art") Art art + final @Nullable Art art ) { Player player = sniper.getPlayer(); ArtHelper.paint(player, art); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelCenterExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelCenterExecutor.java index 171a94cb..3942f2fa 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelCenterExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelCenterExecutor.java @@ -1,6 +1,5 @@ package com.thevoxelbox.voxelsniper.command.executor; -import cloud.commandframework.annotations.Argument; import cloud.commandframework.annotations.CommandDescription; import cloud.commandframework.annotations.CommandMethod; import cloud.commandframework.annotations.CommandPermission; @@ -30,7 +29,7 @@ public VoxelCenterExecutor(VoxelSniperPlugin plugin) { public void onVoxelCenter( final @NotNull Sniper sniper, final @NotNull Toolkit toolkit, - final @Argument("center") int center + final int center ) { Player player = sniper.getPlayer(); ToolkitProperties toolkitProperties = toolkit.getProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelHeightExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelHeightExecutor.java index a7d7a989..11e62813 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelHeightExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelHeightExecutor.java @@ -1,6 +1,5 @@ package com.thevoxelbox.voxelsniper.command.executor; -import cloud.commandframework.annotations.Argument; import cloud.commandframework.annotations.CommandDescription; import cloud.commandframework.annotations.CommandMethod; import cloud.commandframework.annotations.CommandPermission; @@ -30,7 +29,7 @@ public VoxelHeightExecutor(VoxelSniperPlugin plugin) { public void onVoxelHeight( final @NotNull Sniper sniper, final @NotNull Toolkit toolkit, - final @Argument("height") int height + final int height ) { Player player = sniper.getPlayer(); ToolkitProperties toolkitProperties = toolkit.getProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelSniperExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelSniperExecutor.java index 428982b3..c8a57453 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelSniperExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelSniperExecutor.java @@ -1,6 +1,5 @@ package com.thevoxelbox.voxelsniper.command.executor; -import cloud.commandframework.annotations.Argument; import cloud.commandframework.annotations.CommandDescription; import cloud.commandframework.annotations.CommandMethod; import cloud.commandframework.annotations.CommandPermission; @@ -87,7 +86,7 @@ public void onVoxelSniperBrusheslong( public void onVoxelSniperRange( final @NotNull Sniper sniper, final @NotNull Toolkit toolkit, - final @Nullable @Argument("range") @Range(min = "1") Integer range + final @Nullable @Range(min = "1") Integer range ) { ToolkitProperties toolkitProperties = toolkit.getProperties(); toolkitProperties.setBlockTracerRange(range);