diff --git a/build.gradle.kts b/build.gradle.kts index 2f6f6c7f..af29f2aa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -36,6 +36,12 @@ dependencies { compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit") compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Core") + // Cloud command system + implementation(libs.cloudcore) + implementation(libs.cloudannotations) + implementation(libs.cloudbukkit) + implementation(libs.cloudpaper) + // Third party implementation("dev.notmyfault.serverlib:ServerLib") implementation("org.bstats:bstats-base") @@ -97,6 +103,8 @@ tasks { this.archiveClassifier.set(null as String?) this.archiveFileName.set("${project.name}-${project.version}.${this.archiveExtension.getOrElse("jar")}") this.destinationDirectory.set(rootProject.tasks.shadowJar.get().destinationDirectory.get()) + relocate("cloud.commandframework", "com.thevoxelbox.voxelsniper.cloud") + relocate("io.leangen.geantyref", "com.thevoxelbox.geantyref") relocate("org.incendo.serverlib", "com.thevoxelbox.voxelsniper.serverlib") relocate("org.bstats", "com.thevoxelbox.voxelsniper.metrics") relocate("io.papermc.lib", "com.thevoxelbox.voxelsniper.paperlib") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 03df2886..a7588780 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,6 +2,9 @@ # Annotations annotations = "24.0.1" +# Cloud command system +cloud = "1.8.4" + # Gradle plugins shadow = "8.1.1" pluginyml = "0.6.0" @@ -14,6 +17,12 @@ hangar = "0.1.0" # Annotations annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" } +# Cloud command system +cloudcore = { group = "cloud.commandframework", name = "cloud-core", version.ref = "cloud" } +cloudannotations = { group = "cloud.commandframework", name = "cloud-annotations", version.ref = "cloud" } +cloudbukkit = { group = "cloud.commandframework", name = "cloud-bukkit", version.ref = "cloud" } +cloudpaper = { group = "cloud.commandframework", name = "cloud-paper", version.ref = "cloud" } + [plugins] shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" } pluginyml = { id = "net.minecrell.plugin-yml.bukkit", version.ref = "pluginyml" } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/BrushRegistrar.java b/src/main/java/com/thevoxelbox/voxelsniper/BrushRegistrar.java index bbe6331d..8a02682d 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/BrushRegistrar.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/BrushRegistrar.java @@ -277,8 +277,8 @@ private void registerBlockResetBrush() { BrushProperties properties = BrushProperties.builder() .name("Block Reset") .permission("voxelsniper.brush.blockreset") - .alias("brb") - .alias("blockresetbrush") + .alias("br") + .alias("blockreset") .alias("block_reset") .brushPatternType(BrushPatternType.ANY) .creator(BlockResetBrush::new) @@ -290,8 +290,8 @@ private void registerBlockResetSurfaceBrush() { BrushProperties properties = BrushProperties.builder() .name("Block Reset Surface") .permission("voxelsniper.brush.blockresetsurface") - .alias("brbs") - .alias("blockresetbrushsurface") + .alias("brs") + .alias("blockresetsurface") .alias("block_reset_surface") .brushPatternType(BrushPatternType.ANY) .creator(BlockResetSurfaceBrush::new) @@ -429,8 +429,8 @@ private void registerDomeBrush() { BrushProperties properties = BrushProperties.builder() .name("Dome") .permission("voxelsniper.brush.dome") + .alias("do") .alias("dome") - .alias("domebrush") .brushPatternType(BrushPatternType.PATTERN) .creator(DomeBrush::new) .build(); @@ -441,6 +441,7 @@ private void registerDrainBrush() { BrushProperties properties = BrushProperties.builder() .name("Drain") .permission("voxelsniper.brush.drain") + .alias("dr") .alias("drain") .brushPatternType(BrushPatternType.ANY) .creator(DrainBrush::new) @@ -515,7 +516,9 @@ private void registerErodeBlendBrush() { .permission("voxelsniper.brush.erodeblend") .alias("eb") .alias("erodeblend") + .alias("erode_blend") .alias("erodeblendball") + .alias("erode_blend_ball") .brushPatternType(BrushPatternType.ANY) .creator(ErodeBlendBrush::new) .build(); @@ -604,6 +607,7 @@ private void registerJaggedLineBrush() { .permission("voxelsniper.brush.jaggedline") .alias("j") .alias("jagged") + .alias("jaggedline") .alias("jagged_line") .brushPatternType(BrushPatternType.PATTERN) .creator(JaggedLineBrush::new) @@ -723,7 +727,7 @@ private void registerRandomErodeBrush() { .permission("voxelsniper.brush.randomerode") .alias("re") .alias("randomerode") - .alias("randome_rode") + .alias("random_erode") .brushPatternType(BrushPatternType.ANY) .creator(RandomErodeBrush::new) .build(); @@ -734,8 +738,8 @@ private void registerRegenerateChunkBrush() { BrushProperties properties = BrushProperties.builder() .name("Regenerate Chunk") .permission("voxelsniper.brush.regeneratechunk") - .alias("gc") - .alias("generatechunk") + .alias("rc") + .alias("regeneratechunk") .alias("regenerate_chunk") .brushPatternType(BrushPatternType.ANY) .creator(RegenerateChunkBrush::new) @@ -760,6 +764,7 @@ private void registerRotation2DBrush() { .name("Rotation 2D") .permission("voxelsniper.brush.rot2d") .alias("rot2") + .alias("rot2d") .alias("rotation2d") .alias("rotation_2d") .brushPatternType(BrushPatternType.ANY) @@ -773,6 +778,7 @@ private void registerRotation2DVerticalBrush() { .name("Rotation 2D Vertical") .permission("voxelsniper.brush.rot2dvert") .alias("rot2v") + .alias("rot2dv") .alias("rotation2dvertical") .alias("rotation_2d_vertical") .brushPatternType(BrushPatternType.ANY) @@ -786,6 +792,7 @@ private void registerRotation3DBrush() { .name("Rotation 3D") .permission("voxelsniper.brush.rot3d") .alias("rot3") + .alias("rot3d") .alias("rotation3d") .alias("rotation_3d") .brushPatternType(BrushPatternType.ANY) @@ -942,7 +949,7 @@ private void registerSplatterBallBrush() { .name("Splatter Ball") .permission("voxelsniper.brush.splatterball") .alias("sb") - .alias("splatball") + .alias("splatterball") .alias("splatter_ball") .brushPatternType(BrushPatternType.PATTERN) .creator(SplatterBallBrush::new) @@ -955,7 +962,7 @@ private void registerSplatterDiscBrush() { .name("Splatter Disc") .permission("voxelsniper.brush.splatterdisc") .alias("sd") - .alias("splatdisc") + .alias("splatterdisc") .alias("splatter_disc") .brushPatternType(BrushPatternType.PATTERN) .creator(SplatterDiscBrush::new) @@ -994,7 +1001,7 @@ private void registerSplatterVoxelDiscBrush() { .name("Splatter Voxel Disc") .permission("voxelsniper.brush.splattervoxeldisc") .alias("svd") - .alias("splatvoxeldisc") + .alias("splattervoxeldisc") .alias("splatter_voxel_disc") .brushPatternType(BrushPatternType.PATTERN) .creator(SplatterVoxelDiscBrush::new) diff --git a/src/main/java/com/thevoxelbox/voxelsniper/CommandRegistrar.java b/src/main/java/com/thevoxelbox/voxelsniper/CommandRegistrar.java index 038f8297..8f30edfd 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/CommandRegistrar.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/CommandRegistrar.java @@ -1,6 +1,20 @@ package com.thevoxelbox.voxelsniper; +import com.thevoxelbox.voxelsniper.brush.Brush; +import com.thevoxelbox.voxelsniper.brush.property.BrushProperties; import com.thevoxelbox.voxelsniper.command.CommandRegistry; +import com.thevoxelbox.voxelsniper.command.argument.BiomeTypeArgument; +import com.thevoxelbox.voxelsniper.command.argument.BlockArgument; +import com.thevoxelbox.voxelsniper.command.argument.BlockTypeArgument; +import com.thevoxelbox.voxelsniper.command.argument.BrushPropertiesArgument; +import com.thevoxelbox.voxelsniper.command.argument.EntityClassArgument; +import com.thevoxelbox.voxelsniper.command.argument.EntityTypeArgument; +import com.thevoxelbox.voxelsniper.command.argument.PatternArgument; +import com.thevoxelbox.voxelsniper.command.argument.SignFileArgument; +import com.thevoxelbox.voxelsniper.command.argument.StencilFileArgument; +import com.thevoxelbox.voxelsniper.command.argument.StencilListFileArgument; +import com.thevoxelbox.voxelsniper.command.argument.ToolkitArgument; +import com.thevoxelbox.voxelsniper.command.argument.VoxelListBlocksArgument; import com.thevoxelbox.voxelsniper.command.executor.BrushExecutor; import com.thevoxelbox.voxelsniper.command.executor.BrushToolkitExecutor; import com.thevoxelbox.voxelsniper.command.executor.DefaultExecutor; @@ -11,14 +25,11 @@ import com.thevoxelbox.voxelsniper.command.executor.VoxelChunkExecutor; import com.thevoxelbox.voxelsniper.command.executor.VoxelExecutor; import com.thevoxelbox.voxelsniper.command.executor.VoxelHeightExecutor; -import com.thevoxelbox.voxelsniper.command.executor.VoxelInkExecutor; -import com.thevoxelbox.voxelsniper.command.executor.VoxelInkReplaceExecutor; import com.thevoxelbox.voxelsniper.command.executor.VoxelListExecutor; import com.thevoxelbox.voxelsniper.command.executor.VoxelReplaceExecutor; import com.thevoxelbox.voxelsniper.command.executor.VoxelSniperExecutor; -import com.thevoxelbox.voxelsniper.command.property.CommandProperties; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import com.thevoxelbox.voxelsniper.performer.Performer; +import com.thevoxelbox.voxelsniper.performer.property.PerformerProperties; public class CommandRegistrar { @@ -30,6 +41,86 @@ public CommandRegistrar(VoxelSniperPlugin plugin, CommandRegistry registry) { this.registry = registry; } + /** + * Register the suggestions and parsers into the command manager. + * + * @since TODO + */ + public void registerSuggestionsAndParsers() { + registerBiomeTypeArgument(); + registerBlockArgument(); + registerBlockTypeArgument(); + registerBrushPropertiesArgument(); + registerEntityClassArgument(); + registerEntityTypeArgument(); + registerPatternArgument(); + registerSignFileArgument(); + registerStencilFileArgument(); + registerStencilListFileArgument(); + registerVoxelListBlocksArgument(); + registerToolkitArgument(); + } + + private void registerBiomeTypeArgument() { + BiomeTypeArgument argument = new BiomeTypeArgument(plugin); + this.registry.register(argument); + } + + private void registerBlockArgument() { + BlockArgument argument = new BlockArgument(plugin); + this.registry.register(argument); + } + + private void registerBlockTypeArgument() { + BlockTypeArgument argument = new BlockTypeArgument(plugin); + this.registry.register(argument); + } + + private void registerBrushPropertiesArgument() { + BrushPropertiesArgument argument = new BrushPropertiesArgument(plugin); + this.registry.register(argument); + } + + private void registerEntityClassArgument() { + EntityClassArgument argument = new EntityClassArgument(plugin); + this.registry.register(argument); + } + + private void registerEntityTypeArgument() { + EntityTypeArgument argument = new EntityTypeArgument(plugin); + this.registry.register(argument); + } + + private void registerPatternArgument() { + PatternArgument argument = new PatternArgument(plugin); + this.registry.register(argument); + } + + private void registerSignFileArgument() { + SignFileArgument argument = new SignFileArgument(plugin); + this.registry.register(argument); + } + + private void registerStencilFileArgument() { + StencilFileArgument argument = new StencilFileArgument(plugin); + this.registry.register(argument); + } + + private void registerStencilListFileArgument() { + StencilListFileArgument argument = new StencilListFileArgument(plugin); + this.registry.register(argument); + } + + private void registerVoxelListBlocksArgument() { + VoxelListBlocksArgument argument = new VoxelListBlocksArgument(plugin); + this.registry.register(argument); + } + + private void registerToolkitArgument() { + ToolkitArgument argument = new ToolkitArgument(plugin); + this.registry.register(argument); + } + public void registerCommands() { registerBrushCommand(); registerBrushToolCommand(); @@ -37,8 +128,6 @@ public void registerCommands() { registerDefaultCommand(); registerGotoCommand(); registerVoxelHeightCommand(); - registerVoxelInkCommand(); - registerVoxelInkReplaceCommand(); registerVoxelListCommand(); registerPaintCommand(); registerPerformerCommand(); @@ -49,217 +138,85 @@ public void registerCommands() { } private void registerBrushCommand() { - CommandProperties properties = CommandProperties.builder() - .name("brush") - .description("Brush.") - .permission("voxelsniper.sniper") - .alias("b") - .usage("/b [brush-size]") - .usage("Example: /b 5 -- Sets a brush radius size of 5 (11 spaces across).") - .usage("Example: /b b cm -- Sets your brush to the Ball Brush with the combo-mat performer.") - .sender(Player.class) - .build(); + // Registers the main executor. BrushExecutor executor = new BrushExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); + + // Registers the brushes. + for (BrushProperties properties : this.plugin.getBrushRegistry().getUniqueBrushesProperties()) { + Brush brushExecutor = properties.getCreator().create(); + brushExecutor.setProperties(properties); + brushExecutor.loadProperties(); + this.registry.register(brushExecutor); + } } private void registerBrushToolCommand() { - CommandProperties properties = CommandProperties.builder() - .name("brush_toolkit") - .description("Brush Toolkit command.") - .permission("voxelsniper.sniper") - .alias("btool") - .usage("/btool -- Prints out command usage information.") - .sender(Player.class) - .build(); BrushToolkitExecutor executor = new BrushToolkitExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); } private void registerVoxelCenterCommand() { - CommandProperties properties = CommandProperties.builder() - .name("voxel_center") - .description("VoxelCenter. VoxelCentroid.") - .permission("voxelsniper.sniper") - .alias("vc") - .usage("/vc") - .usage("Example: /vc -1 -- Sets the Clone Cylinder's Y value for the base relative to the Clone Point.") - .sender(Player.class) - .build(); VoxelCenterExecutor executor = new VoxelCenterExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); } private void registerDefaultCommand() { - CommandProperties properties = CommandProperties.builder() - .name("default") - .description("FastAsyncVoxelSniper Default.") - .permission("voxelsniper.sniper") - .alias("d") - .usage("/d") - .usage("Example: /d -- Resets the brush settings to their default values.") - .sender(Player.class) - .build(); DefaultExecutor executor = new DefaultExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); } private void registerGotoCommand() { - CommandProperties properties = CommandProperties.builder() - .name("goto") - .description("Warps to the specified coordinates.") - .permission("voxelsniper.goto") - .usage("/goto [X] [Z]") - .usage("Example: /goto 100 -100 -- Takes the user to the coordinates X: 100, Z: -100. The Y-coordinate will always be 1 more than the Y-coordinate of the highest block at the X and Z-coordinates provided.") - .sender(Player.class) - .build(); GotoExecutor executor = new GotoExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); } private void registerVoxelHeightCommand() { - CommandProperties properties = CommandProperties.builder() - .name("voxel_height") - .description("VoxelHeight.") - .permission("voxelsniper.sniper") - .alias("vh") - .usage("/vh [voxel-height]") - .usage("Example: /vh -- Sets the brush height.") - .sender(Player.class) - .build(); VoxelHeightExecutor executor = new VoxelHeightExecutor(this.plugin); - this.registry.register(properties, executor); - } - - private void registerVoxelInkCommand() { - CommandProperties properties = CommandProperties.builder() - .name("voxel_ink") - .description("VoxelInk (Data Value).") - .permission("voxelsniper.sniper") - .alias("vi") - .usage("/vi [0-16]") - .usage("Example: /vi -- sets a data value of 6 (e.g. pink wool).") - .sender(Player.class) - .build(); - VoxelInkExecutor executor = new VoxelInkExecutor(this.plugin); - this.registry.register(properties, executor); - } - - private void registerVoxelInkReplaceCommand() { - CommandProperties properties = CommandProperties.builder() - .name("voxel_ink_replace") - .description("VoxelInkReplace.") - .permission("voxelsniper.sniper") - .alias("vir") - .usage("/vir [0-16]") - .usage("Example: /vir 12 -- Sets a replace ink brush to select data 6 blocks for replacement.") - .sender(Player.class) - .build(); - VoxelInkReplaceExecutor executor = new VoxelInkReplaceExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); } private void registerVoxelListCommand() { - CommandProperties properties = CommandProperties.builder() - .name("voxel_list") - .description("VoxelBlockExclusion list") - .permission("voxelsniper.sniper") - .alias("vl") - .usage("/vl") - .usage("Example: /vl 89 -5 -- Adds glowstone to the voxel list and removes planks from the voxel list.") - .sender(Player.class) - .build(); VoxelListExecutor executor = new VoxelListExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); } private void registerPaintCommand() { - CommandProperties properties = CommandProperties.builder() - .name("paint") - .description("Change the selected painting to another painting.") - .permission("voxelsniper.sniper") - .usage("/paint") - .usage("Example: /paint -- Cycles through paintings. You must be adjacent to the painting and aiming at it.") - .sender(Player.class) - .build(); PaintExecutor executor = new PaintExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); } private void registerPerformerCommand() { - CommandProperties properties = CommandProperties.builder() - .name("performer") - .description("FastAsyncVoxelSniper performer.") - .permission("voxelsniper.sniper") - .alias("p") - .alias("perf") - .usage("/p") - .usage("Example: /p -- Sets the performer of the current brush to \"m\".") - .usage("/p ") - .usage("Example: /p -- Sets the performer of the current brush to given performer.") - .sender(Player.class) - .build(); PerformerExecutor executor = new PerformerExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); + + // Registers the performers + for (PerformerProperties properties : this.plugin.getPerformerRegistry().getUniquePerformerProperties()) { + Performer performerExecutor = properties.getCreator().create(); + performerExecutor.setProperties(properties); + performerExecutor.loadProperties(); + this.registry.register(performerExecutor); + } } private void registerVoxelReplaceCommand() { - CommandProperties properties = CommandProperties.builder() - .name("voxel_replace") - .description("VoxelReplace.") - .permission("voxelsniper.sniper") - .alias("vr") - .usage("/vr [0-159]") - .usage("Example: /vr 12 -- Sets a replace brush to select sand blocks for replacement.") - .sender(Player.class) - .build(); VoxelReplaceExecutor executor = new VoxelReplaceExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); } private void registerVoxelSniperCommand() { - CommandProperties properties = CommandProperties.builder() - .name("voxel_sniper") - .description("FastAsyncVoxelSniper Settings.") - .permission("voxelsniper.sniper") - .alias("vs") - .alias("favs") - .alias("fastasyncvoxelsniper") - .usage("/vs") - .usage("/favs") - .usage("Example: /vs -- Returns the current brush settings.") - .sender(CommandSender.class) - .build(); VoxelSniperExecutor executor = new VoxelSniperExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); } private void registerVoxelCommand() { - CommandProperties properties = CommandProperties.builder() - .name("voxel") - .description("Voxel input.") - .permission("voxelsniper.sniper") - .alias("v") - .usage("/v [0-159]") - .usage("Example: /v 1 -- Loads the sniper with Stone blocks.") - .sender(Player.class) - .build(); VoxelExecutor executor = new VoxelExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); } private void registerVoxelChunkCommand() { - CommandProperties properties = CommandProperties.builder() - .name("voxel_chunk") - .description("Update the chunk you are standing in.") - .permission("voxelsniper.sniper") - .alias("vchunk") - .usage("/vchunk") - .usage("Example: /vchunk -- Loads the chunk you're standing in.") - .sender(Player.class) - .build(); VoxelChunkExecutor executor = new VoxelChunkExecutor(this.plugin); - this.registry.register(properties, executor); + this.registry.register(executor); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/FastAsyncVoxelSniper.java b/src/main/java/com/thevoxelbox/voxelsniper/FastAsyncVoxelSniper.java deleted file mode 100644 index 1aa2a3d7..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/FastAsyncVoxelSniper.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.thevoxelbox.voxelsniper; - -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.PluginCommand; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.Nullable; - -public class FastAsyncVoxelSniper { - - private final VoxelSniperPlugin plugin; - - public FastAsyncVoxelSniper(JavaPlugin plugin) { - this.plugin = (VoxelSniperPlugin) plugin; - try { - this.initFavs(); - } catch (Throwable ignore) { - } - } - - public void initFavs() { - setupCommand("/p", (sender, command, label, args) -> { - if (sender instanceof Player && sender.hasPermission("voxelsniper.sniper")) { - @Nullable PluginCommand cmd = plugin.getCommand("p"); - plugin.onCommand(sender, cmd, label, args); - } - return false; - }); - setupCommand("/d", (sender, command, label, args) -> { - if (sender instanceof Player && sender.hasPermission("voxelsniper.sniper")) { - @Nullable PluginCommand cmd = plugin.getCommand("d"); - plugin.onCommand(sender, cmd, label, args); - } - return false; - }); - } - - public void setupCommand(final String label, final CommandExecutor cmd) { - plugin.getCommand(label).setExecutor(cmd); - } - -} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperPlugin.java b/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperPlugin.java index 34093d7a..96a2a306 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperPlugin.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperPlugin.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.URLConnection; +import java.util.Comparator; public class VoxelSniperPlugin extends JavaPlugin { @@ -59,6 +60,7 @@ public class VoxelSniperPlugin extends JavaPlugin { private PerformerRegistry performerRegistry; private SniperRegistry sniperRegistry; private PatternParser patternParser; + private CommandRegistry commandRegistry; private double newVersion = 0; private double currentVersion = 0; @@ -76,9 +78,10 @@ public void onEnable() { this.sniperRegistry = new SniperRegistry(); this.patternParser = new PatternParser(WorldEdit.getInstance()); testRegistries(); + this.commandRegistry = new CommandRegistry(this); + prepareCommands(); loadCommands(); loadListeners(); - new FastAsyncVoxelSniper(this); // Enable metrics Metrics metrics = new Metrics(this, 6405); // Check if we are in a safe environment @@ -150,10 +153,42 @@ private PerformerRegistry loadPerformerRegistry() { return performerRegistry; } + private void testRegistries() { + // Load brushes and performers to ensure their configuration is up-to-date. + this.brushRegistry.getUniqueBrushesProperties().stream().sorted(Comparator.comparing(BrushProperties::getName)) + .forEachOrdered(properties -> { + Brush brush = properties.getCreator().create(); + brush.setProperties(properties); + brush.loadProperties(); + }); + this.performerRegistry.getUniquePerformerProperties().stream().sorted(Comparator.comparing(PerformerProperties::getName)) + .forEachOrdered(properties -> { + Performer performer = properties.getCreator().create(); + performer.setProperties(properties); + performer.loadProperties(); + }); + } + + private void prepareCommands() { + try { + commandRegistry.initialize(); + } catch (Exception e) { + LOGGER.warn("Unable to initialize the command system. FastAsyncVoxelSniper will be disabled!"); + getServer().getPluginManager().disablePlugin(plugin); + throw new RuntimeException(e); + } + } + private void loadCommands() { - CommandRegistry commandRegistry = new CommandRegistry(this); - CommandRegistrar commandRegistrar = new CommandRegistrar(this, commandRegistry); - commandRegistrar.registerCommands(); + try { + CommandRegistrar commandRegistrar = new CommandRegistrar(this, commandRegistry); + commandRegistrar.registerSuggestionsAndParsers(); + commandRegistrar.registerCommands(); + } catch (Exception e) { + LOGGER.warn("Unable to register the commands. FastAsyncVoxelSniper will be disabled!"); + getServer().getPluginManager().disablePlugin(plugin); + throw new RuntimeException(e); + } } private void loadListeners() { @@ -169,22 +204,6 @@ public void reload() { testRegistries(); } - private void testRegistries() { - // Load brushes and performers to ensure their configuration is up-to-date. - this.brushRegistry.getBrushesProperties().keySet().stream().sorted().forEachOrdered(key -> { - BrushProperties properties = this.brushRegistry.getBrushProperties(key); - Brush brush = properties.getCreator().create(); - brush.setProperties(properties); - brush.loadProperties(); - }); - this.performerRegistry.getPerformerProperties().keySet().stream().sorted().forEachOrdered(key -> { - PerformerProperties properties = this.performerRegistry.getPerformerProperties(key); - Performer performer = properties.getCreator().create(); - performer.setProperties(properties); - performer.loadProperties(); - }); - } - /** * Return the voxel sniper config. * @@ -201,7 +220,7 @@ public VoxelSniperConfig getVoxelSniperConfig() { * @since 2.7.0 */ public TranslationManager getTranslationManager() { - return translationManager.getValue(); + return this.translationManager.getValue(); } /** @@ -238,7 +257,17 @@ public SniperRegistry getSniperRegistry() { * @since 2.6.0 */ public PatternParser getPatternParser() { - return patternParser; + return this.patternParser; + } + + /** + * Return the command manager. + * + * @return the command manager + * @since TODO + */ + public CommandRegistry getCommandRegistry() { + return this.commandRegistry; } // Borrowed from Vault @@ -254,7 +283,7 @@ private double updateCheck(double currentVersion) { final String response = reader.readLine(); final JSONArray array = (JSONArray) JSONValue.parse(response); - if (array.size() == 0) { + if (array.isEmpty()) { LOGGER.warn("No files found, or Feed URL is bad."); return currentVersion; } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/Brush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/Brush.java index 2182d4d0..ab6cabce 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/Brush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/Brush.java @@ -3,28 +3,16 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; import com.thevoxelbox.voxelsniper.brush.property.BrushProperties; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolAction; -import java.util.List; - -public interface Brush { +public interface Brush extends VoxelCommandElement { /** - * Handles parameters passed to brushes. - * - * @param parameters Array of string containing parameters - * @param snipe Snipe - */ - void handleCommand(String[] parameters, Snipe snipe); - - /** - * Handles parameters completers passed to brushes. - * - * @param parameters Array of string containing parameters - * @param snipe Snipe + * Load brush properties. */ - List handleCompletions(String[] parameters, Snipe snipe); + void loadProperties(); /** * Perform brush action. @@ -72,9 +60,4 @@ public interface Brush { */ void setProperties(BrushProperties properties); - /** - * Load brush properties. - */ - void loadProperties(); - } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/BrushRegistry.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/BrushRegistry.java index e1c62903..0238f1bb 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/BrushRegistry.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/BrushRegistry.java @@ -5,20 +5,37 @@ import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; public class BrushRegistry { + private final Set uniqueBrushesProperties = new HashSet<>(); private final Map brushesProperties = new HashMap<>(); public void register(BrushProperties properties) { + // Registers unique brush properties. + uniqueBrushesProperties.add(properties); + + // Registers all aliases. List aliases = properties.getAliases(); for (String alias : aliases) { this.brushesProperties.put(alias, properties); } } + /** + * Return the unique brushes properties. + * + * @return the unique brushes properties + * @since TODO + */ + public Set getUniqueBrushesProperties() { + return uniqueBrushesProperties; + } + @Nullable public BrushProperties getBrushProperties(String alias) { return this.brushesProperties.get(alias); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/PerformerBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/PerformerBrush.java index 45066bb0..90c78cfd 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/PerformerBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/PerformerBrush.java @@ -1,14 +1,28 @@ package com.thevoxelbox.voxelsniper.brush; -import com.thevoxelbox.voxelsniper.performer.PerformerRegistry; +import com.thevoxelbox.voxelsniper.performer.Performer; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; public interface PerformerBrush extends Brush { - void handlePerformerCommand(String[] parameters, Snipe snipe, PerformerRegistry performerRegistry); - void initialize(Snipe snipe); void sendPerformerInfo(Snipe snipe); + /** + * Return the performer. + * + * @return the performer + * @since TODO + */ + Performer getPerformer(); + + /** + * Set the performer. + * + * @param performer the performer + * @since TODO + */ + void setPerformer(Performer performer); + } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/property/BrushProperties.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/property/BrushProperties.java index 0005c603..166cf8d7 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/property/BrushProperties.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/property/BrushProperties.java @@ -23,7 +23,10 @@ public class BrushProperties { * @param creator the creator */ BrushProperties( - String name, @Nullable String permission, List aliases, BrushPatternType brushPatternType, + String name, + @Nullable String permission, + List aliases, + BrushPatternType brushPatternType, BrushCreator creator ) { this.name = name; @@ -77,7 +80,7 @@ public List getAliases() { * @since 2.6.0 */ public BrushPatternType getBrushPatternType() { - return brushPatternType; + return this.brushPatternType; } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/property/BrushPropertiesBuilder.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/property/BrushPropertiesBuilder.java index 15a05d1e..cfb919f0 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/property/BrushPropertiesBuilder.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/property/BrushPropertiesBuilder.java @@ -85,7 +85,13 @@ public BrushProperties build() { if (this.creator == null) { throw new RuntimeException("Brush creator must be specified."); } - return new BrushProperties(this.name, this.permission, this.aliases, this.brushPatternType, this.creator); + return new BrushProperties( + this.name, + this.permission, + this.aliases, + this.brushPatternType, + this.creator + ); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/AbstractBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/AbstractBrush.java index b662e9f2..35697052 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/AbstractBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/AbstractBrush.java @@ -1,6 +1,5 @@ package com.thevoxelbox.voxelsniper.brush.type; -import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.bukkit.BukkitAdapter; @@ -14,6 +13,7 @@ import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.TreeGenerator; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.RegenOptions; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; @@ -26,17 +26,14 @@ import com.thevoxelbox.voxelsniper.sniper.Sniper; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolAction; -import com.thevoxelbox.voxelsniper.util.minecraft.Identifiers; import org.apache.logging.log4j.Logger; import org.bukkit.World; import java.io.File; import java.text.DecimalFormat; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; -import java.util.stream.Stream; public abstract class AbstractBrush implements Brush { @@ -44,48 +41,23 @@ public abstract class AbstractBrush implements Brush { protected static final VoxelSniperConfig CONFIG = PLUGIN.getVoxelSniperConfig(); protected static final File PLUGIN_DATA_FOLDER = PLUGIN.getDataFolder(); protected static final int CHUNK_SIZE = 16; - protected static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat(".##"); + protected static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##"); private static final Logger LOGGER = LogManagerCompat.getLogger(); + private BrushProperties properties; private EditSession editSession; private BlockVector3 targetBlock; private BlockVector3 lastBlock; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + protected void onBrushCommand(Snipe snipe) { Sniper sniper = snipe.getSniper(); - sniper.print(Caption.of("voxelsniper.command.no-parameters")); - } - - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return sortCompletions(Stream.empty(), parameter, 0); - } - return Collections.emptyList(); + sniper.sendInfo(true); } - /** - * Sort and return all possible completions that match given parameter. - * - * @param completions Completions - * @param parameter Given parameter - * @param index Parameter index - * @return Sorted completions. - */ - public List sortCompletions(Stream completions, String parameter, int index) { - // The first brush parameter may be info. - // Removing MINECRAFT_IDENTIFIER permits completing whether minecraft:XXXX or XXXX. - String parameterLowered = (parameter.startsWith(Identifiers.MINECRAFT_IDENTIFIER) - ? parameter.substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH) - : parameter) - .toLowerCase(Locale.ROOT); - return (index == 0 ? Stream.concat(completions, Stream.of("info")) : completions) - .filter(completion -> completion.toLowerCase(Locale.ROOT).startsWith(parameterLowered)) - .sorted() - .toList(); + protected void onBrushInfoCommand(Snipe snipe, Component component) { + Sniper sniper = snipe.getSniper(); + sniper.print(component); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BiomeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BiomeBrush.java index 6a9941cd..308b3b4f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BiomeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BiomeBrush.java @@ -1,28 +1,29 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; import com.thevoxelbox.voxelsniper.util.minecraft.Identifiers; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b biome|bio") +@CommandPermission("voxelsniper.brush.biome") public class BiomeBrush extends AbstractBrush { private static final BiomeType DEFAULT_BIOME_TYPE = BiomeTypes.PLAINS; - private static final List BIOMES = BiomeTypes.values().stream() - .map(biomeType -> biomeType.getId().substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH)) - .toList(); - private BiomeType biomeType; @Override @@ -30,50 +31,47 @@ public void loadProperties() { this.biomeType = (BiomeType) getRegistryProperty("default-biome-type", BiomeType.REGISTRY, DEFAULT_BIOME_TYPE); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.biome.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("list")) { - messenger.sendMessage(VoxelSniperText.formatListWithCurrent( - BiomeTypes.values(), - (type, type2) -> type.getId().compareTo(type2.getId()), - type -> TextComponent.of(type.getId().substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH)), - type -> type, - this.biomeType, - "voxelsniper.brush.biome" - )); - } else { - BiomeType biomeType = BiomeTypes.get(firstParameter); + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.biome.info")); + } - if (biomeType != null) { - this.biomeType = biomeType; - messenger.sendMessage(Caption.of("voxelsniper.brush.biome.set-biome", this.biomeType.getId())); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-biome", firstParameter)); - } - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("list") + public void onBrushList( + final @NotNull Snipe snipe + ) { + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(VoxelSniperText.formatListWithCurrent( + BiomeTypes.values(), + (type, type2) -> type.getId().compareTo(type2.getId()), + type -> TextComponent.of(type.getId().substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH)), + type -> type, + this.biomeType, + "voxelsniper.brush.biome" + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.concat( - BIOMES.stream(), - Stream.of("list") - ), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("") + public void onBrushBiometype( + final @NotNull Snipe snipe, + final @NotNull @Argument("biome-type") BiomeType biomeType + ) { + this.biomeType = biomeType; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.biome.set-biome", + this.biomeType.getId() + )); } @Override @@ -127,7 +125,10 @@ private void biome(Snipe snipe) { public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() - .message(Caption.of("voxelsniper.brush.biome.set-biome", this.biomeType.getId())) + .message(Caption.of( + "voxelsniper.brush.biome.set-biome", + this.biomeType.getId() + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BlockResetBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BlockResetBrush.java index d4616aec..c284b37d 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BlockResetBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BlockResetBrush.java @@ -1,14 +1,21 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.MaterialSet; import com.thevoxelbox.voxelsniper.util.material.MaterialSets; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b block_reset|blockreset|br") +@CommandPermission("voxelsniper.brush.blockreset") public class BlockResetBrush extends AbstractBrush { private static final MaterialSet DENIED_UPDATES = MaterialSet.builder() @@ -25,6 +32,13 @@ public class BlockResetBrush extends AbstractBrush { .add(BlockTypes.COMPARATOR) .build(); + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { applyBrush(snipe); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BlockResetSurfaceBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BlockResetSurfaceBrush.java index 44214496..81dc95de 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BlockResetSurfaceBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/BlockResetSurfaceBrush.java @@ -1,13 +1,17 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.MaterialSet; import com.thevoxelbox.voxelsniper.util.material.MaterialSets; +import org.jetbrains.annotations.NotNull; /** * This brush only looks for solid blocks, and then changes those plus any air blocks touching them. If it works, this brush should be faster than the original @@ -22,6 +26,9 @@ * of a 3d checkerboard of stone and air every other block, this brush should only be about 1.5x slower than the original brush. Savings increase for larger * brushes. */ +@RequireToolkit +@CommandMethod(value = "brush|b block_reset_surface|blockresetsurface|brs") +@CommandPermission("voxelsniper.brush.blockresetsurface") public class BlockResetSurfaceBrush extends AbstractBrush { private static final MaterialSet DENIED_UPDATES = MaterialSet.builder() @@ -39,6 +46,13 @@ public class BlockResetSurfaceBrush extends AbstractBrush { .add(BlockTypes.COMPARATOR) .build(); + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { applyBrush(snipe); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CleanSnowBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CleanSnowBrush.java index deb95bcc..4f52449c 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CleanSnowBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CleanSnowBrush.java @@ -1,55 +1,53 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.math.MathHelper; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b clean_snow|cleansnow|cls") +@CommandPermission("voxelsniper.brush.cleansnow") public class CleanSnowBrush extends AbstractBrush { - private double trueCircle; + private boolean trueCircle; - @Override - public final void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.clean-snow.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("true")) { - this.trueCircle = 0.5; - messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(true))); - } else if (firstParameter.equalsIgnoreCase("false")) { - this.trueCircle = 0; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.parameter.true-circle", - VoxelSniperText.getStatus(false) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.clean-snow.info")); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("true", "false"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("") + public void onBrushTruecircle( + final @NotNull Snipe snipe, + final @Argument("true-circle") @Liberal boolean trueCircle + ) { + this.trueCircle = trueCircle; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )); } @Override @@ -65,7 +63,7 @@ public void handleGunpowderAction(Snipe snipe) { private void cleanSnow(Snipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); int brushSize = toolkitProperties.getBrushSize(); - double brushSizeSquared = Math.pow(brushSize + this.trueCircle, 2); + double brushSizeSquared = Math.pow(brushSize + (this.trueCircle ? 0.5 : 0), 2); for (int y = (brushSize + 1) * 2; y >= 0; y--) { double ySquared = MathHelper.square(y - brushSize); for (int x = (brushSize + 1) * 2; x >= 0; x--) { @@ -107,7 +105,10 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .brushSizeMessage() - .message(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(this.trueCircle == 0.5))) + .message(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CometBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CometBrush.java index 3159ef49..1c35e6b2 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CometBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CometBrush.java @@ -1,9 +1,14 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.util.TaskManager; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.formatting.text.Component; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.Sniper; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; @@ -12,57 +17,55 @@ import org.bukkit.entity.Player; import org.bukkit.entity.SmallFireball; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b comet|meteor|com|met") +@CommandPermission("voxelsniper.brush.comet") public class CometBrush extends AbstractBrush { private boolean useBigBalls; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.comet.info")); + } + + @CommandMethod("") + public void onBrushBigballs( + final @NotNull Snipe snipe, + final @Argument("use-big-balls") @Liberal boolean useBigBalls + ) { + this.useBigBalls = useBigBalls; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.comet.set-size", + this.getStatus(this.useBigBalls) + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.comet.info")); - } else { - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("balls")) { - String newBallSize = parameters[1]; - if (newBallSize.equalsIgnoreCase("big")) { - this.useBigBalls = true; - messenger.sendMessage(Caption.of("voxelsniper.brush.comet.set-size", getStatus(true))); - } else if (newBallSize.equalsIgnoreCase("small")) { - this.useBigBalls = false; - messenger.sendMessage(Caption.of("voxelsniper.brush.comet.set-size", getStatus(false))); - } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.biome.invalid-size", newBallSize)); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("balls big") + public void onBrushBallsBig( + final @NotNull Snipe snipe + ) { + this.onBrushBigballs(snipe, true); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("balls"), parameter, 0); - } - if (parameters.length == 2) { - String firstParameter = parameters[0]; - if (firstParameter.equalsIgnoreCase("balls")) { - String parameter = parameters[1]; - return super.sortCompletions(Stream.of("big", "small"), parameter, 1); - } - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("balls small") + public void onBrushBallsSmall( + final @NotNull Snipe snipe + ) { + this.onBrushBigballs(snipe, false); } @Override @@ -103,7 +106,10 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .patternMessage() - .message(Caption.of("voxelsniper.brush.comet.set-size", getStatus(this.useBigBalls))) + .message(Caption.of( + "voxelsniper.brush.comet.set-size", + this.getStatus(this.useBigBalls) + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CopyPastaBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CopyPastaBrush.java index 8da6f195..4d0c93f3 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CopyPastaBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/CopyPastaBrush.java @@ -1,17 +1,21 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.material.Materials; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b copy_pasta|copypasta|cp") +@CommandPermission("voxelsniper.brush.copypasta") public class CopyPastaBrush extends AbstractBrush { private static final int BLOCK_LIMIT = 10000; @@ -34,41 +38,69 @@ public void loadProperties() { this.blockLimit = getIntegerProperty("block-limit", BLOCK_LIMIT); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.copy-pasta.info")); + } + + @CommandMethod("air") + public void onBrushAir( + final @NotNull Snipe snipe + ) { + this.pasteAir = !this.pasteAir; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.copy-pasta.set-paste-air", + VoxelSniperText.getStatus(this.pasteAir) + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.copy-pasta.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("air")) { - this.pasteAir = !this.pasteAir; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.copy-pasta.set-paste-air", - VoxelSniperText.getStatus(this.pasteAir) - )); - } else if (Stream.of("0", "90", "180", "270") - .anyMatch(firstParameter::equalsIgnoreCase)) { - this.pivot = Integer.parseInt(firstParameter); - messenger.sendMessage(Caption.of("voxelsniper.brush.copy-pasta.set-pivot", this.pivot)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + private void onBrushPivotCommand(Snipe snipe, int pivot) { + this.pivot = pivot; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.copy-pasta.set-pivot", + this.pivot + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("air", "90", "180", "270", "0"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("0") + public void onBrush0( + final @NotNull Snipe snipe + ) { + this.onBrushPivotCommand(snipe, 0); + } + + @CommandMethod("90") + public void onBrush90( + final @NotNull Snipe snipe + ) { + this.onBrushPivotCommand(snipe, 90); + } + + @CommandMethod("180") + public void onBrush180( + final @NotNull Snipe snipe + ) { + this.onBrushPivotCommand(snipe, 180); + } + + @CommandMethod("270") + public void onBrush270( + final @NotNull Snipe snipe + ) { + this.onBrushPivotCommand(snipe, 270); } @Override @@ -190,8 +222,14 @@ private void doPasta(Snipe snipe) { public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() - .message(Caption.of("voxelsniper.brush.copy-pasta.set-paste-air", VoxelSniperText.getStatus(this.pasteAir))) - .message(Caption.of("voxelsniper.brush.copy-pasta.set-pivot", this.pivot)) + .message(Caption.of( + "voxelsniper.brush.copy-pasta.set-paste-air", + VoxelSniperText.getStatus(this.pasteAir) + )) + .message(Caption.of( + "voxelsniper.brush.copy-pasta.set-pivot", + this.pivot + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/DomeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/DomeBrush.java index c987dea5..35de15b8 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/DomeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/DomeBrush.java @@ -1,19 +1,33 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import org.bukkit.util.NumberConversions; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; +@RequireToolkit +@CommandMethod(value = "brush|b dome|do") +@CommandPermission("voxelsniper.brush.dome") public class DomeBrush extends AbstractBrush { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { BlockVector3 targetBlock = getTargetBlock(); @@ -31,7 +45,7 @@ private void generateDome(Snipe snipe, BlockVector3 block) { int voxelHeight = toolkitProperties.getVoxelHeight(); if (voxelHeight == 0) { SnipeMessenger messenger = snipe.createMessenger(); - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-voxel-height", 0)); + messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-voxel-height", voxelHeight)); return; } int absoluteHeight = Math.abs(voxelHeight); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/DrainBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/DrainBrush.java index 12dabf9e..918c270c 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/DrainBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/DrainBrush.java @@ -1,66 +1,69 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.Materials; import com.thevoxelbox.voxelsniper.util.math.MathHelper; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b drain|dr") +@CommandPermission("voxelsniper.brush.drain") public class DrainBrush extends AbstractBrush { - private double trueCircle; + private boolean trueCircle; private boolean disc; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.drain.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("true")) { - this.trueCircle = 0.5; - messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(true))); - } else if (firstParameter.equalsIgnoreCase("false")) { - this.trueCircle = 0; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.parameter.true-circle", - VoxelSniperText.getStatus(false) - )); - } else if (firstParameter.equalsIgnoreCase("d")) { - if (this.disc) { - this.disc = false; - messenger.sendMessage(Caption.of("voxelsniper.brush.drain.disc", VoxelSniperText.getStatus(false))); - } else { - this.disc = true; - messenger.sendMessage(Caption.of("voxelsniper.brush.drain.disc", VoxelSniperText.getStatus(true))); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.drain.info")); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("true", "false", "d"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("") + public void onBrushTruecircle( + final @NotNull Snipe snipe, + final @Argument("true-circle") @Liberal boolean trueCircle + ) { + this.trueCircle = trueCircle; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )); + } + + @CommandMethod("d") + public void onBrushD( + final @NotNull Snipe snipe + ) { + this.disc = !this.disc; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.drain.disc", + VoxelSniperText.getStatus(this.disc) + )); } @Override @@ -76,7 +79,7 @@ public void handleGunpowderAction(Snipe snipe) { private void drain(Snipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); int brushSize = toolkitProperties.getBrushSize(); - double brushSizeSquared = Math.pow(brushSize + this.trueCircle, 2); + double brushSizeSquared = Math.pow(brushSize + (this.trueCircle ? 0.5 : 0), 2); BlockVector3 targetBlock = getTargetBlock(); int targetBlockX = targetBlock.getX(); int targetBlockY = targetBlock.getY(); @@ -138,8 +141,14 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .brushSizeMessage() - .message(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(this.trueCircle == 0.5))) - .message(Caption.of("voxelsniper.brush.drain.disc", VoxelSniperText.getStatus(this.disc))) + .message(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )) + .message(Caption.of( + "voxelsniper.brush.drain.disc", + VoxelSniperText.getStatus(this.disc) + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/EraserBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/EraserBrush.java index 955574a6..20f58ef0 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/EraserBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/EraserBrush.java @@ -1,14 +1,21 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.MaterialSet; import com.thevoxelbox.voxelsniper.util.material.MaterialSets; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b eraser|erase") +@CommandPermission("voxelsniper.brush.eraser") public class EraserBrush extends AbstractBrush { private static final MaterialSet EXCLUSIVE_MATERIALS = MaterialSet.builder() @@ -26,6 +33,13 @@ public class EraserBrush extends AbstractBrush { .with(MaterialSets.LIQUIDS) .build(); + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { doErase(snipe, false); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ErodeBlendBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ErodeBlendBrush.java index dc218a79..2274f860 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ErodeBlendBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ErodeBlendBrush.java @@ -1,14 +1,20 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Range; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; import com.thevoxelbox.voxelsniper.brush.type.blend.BlendBallBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolAction; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b erode_blend|erode_blend_ball|erodeblend|erodeblendball|eb") +@CommandPermission("voxelsniper.brush.erodeblend") public class ErodeBlendBrush extends AbstractBrush { private final BlendBallBrush blendBall; @@ -19,27 +25,68 @@ public ErodeBlendBrush() { this.erode = new ErodeBrush(); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("water")) { - this.blendBall.handleCommand(parameters, snipe); - } else { - this.erode.handleCommand(parameters, snipe); - } + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + this.blendBall.onBrush(snipe); + this.erode.onBrush(snipe); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.concat( - this.blendBall.handleCompletions(parameters, snipe).stream(), - this.erode.handleCompletions(parameters, snipe).stream() - ), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + this.blendBall.onBrushInfo(snipe); + this.erode.onBrushInfo(snipe); + } + + @CommandMethod("water") + public void onBrushWater( + final @NotNull Snipe snipe + ) { + this.blendBall.onBrushWater(snipe); + } + + @CommandMethod("") + public void onBrushPreset( + final @NotNull Snipe snipe, + + final @Argument("preset") ErodeBrush.Preset preset + ) { + this.erode.onBrushPreset(snipe, preset); + } + + @CommandMethod("e ") + public void onBrushErosionfaces( + final @NotNull Snipe snipe, + final @Argument("erosion-faces") @Range(min = "0") int erosionFaces + ) { + this.erode.onBrushErosionfaces(snipe, erosionFaces); + } + + @CommandMethod("E ") + public void onBrushErosionrecursion( + final @NotNull Snipe snipe, + final @Argument("erosion-recursions") @Range(min = "0") int erosionRecursions + ) { + this.erode.onBrushErosionrecursion(snipe, erosionRecursions); + } + + @CommandMethod("f ") + public void onBrushFillfaces( + final @NotNull Snipe snipe, + final @Argument("fill-faces") @Range(min = "0") int fillFaces + ) { + this.erode.onBrushFillfaces(snipe, fillFaces); + } + + @CommandMethod("F ") + public void onBrushFillrecursion( + final @NotNull Snipe snipe, + final @Argument("fill-recursions") @Range(min = "0") int fillRecursions + ) { + this.erode.onBrushFillrecursion(snipe, fillRecursions); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ErodeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ErodeBrush.java index ddd2a499..d4c44855 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ErodeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ErodeBrush.java @@ -1,5 +1,9 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; @@ -8,13 +12,14 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.Vectors; import com.thevoxelbox.voxelsniper.util.material.Materials; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.Serial; @@ -25,8 +30,10 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Stream; +@RequireToolkit +@CommandMethod(value = "brush|b erode|e") +@CommandPermission("voxelsniper.brush.erode") public class ErodeBrush extends AbstractBrush { private static final List FACES_TO_CHECK = Arrays.asList( @@ -40,120 +47,108 @@ public class ErodeBrush extends AbstractBrush { private ErosionPreset currentPreset = Preset.DEFAULT.getPreset(); - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.erode.info")); + } + + @CommandMethod("") + public void onBrushPreset( + final @NotNull Snipe snipe, + final @NotNull @Argument("preset") Preset preset + ) { + this.currentPreset = preset.getPreset(); + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.erode.info")); - } else { - Preset preset = Preset.getPreset(firstParameter); - if (preset != null) { - try { - this.currentPreset = preset.getPreset(); - messenger.sendMessage(Caption.of("voxelsniper.brush.erode.set-preset", preset.getFullName())); - return; - } catch (IllegalArgumentException exception) { - messenger.sendMessage(Caption.of("voxelsniper.brush.erode.invalid-preset", preset.getFullName())); - return; - } - } + messenger.sendMessage(Caption.of( + "voxelsniper.brush.erode.set-preset", + preset.getFullName() + )); + } - ErosionPreset currentPresetBackup = this.currentPreset; - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("f")) { - Integer fillFaces = NumericParser.parseInteger(parameters[1]); - if (fillFaces != null) { - this.currentPreset = new ErosionPreset( - this.currentPreset.getErosionFaces(), - this.currentPreset.getErosionRecursions(), - fillFaces, - this.currentPreset.getFillRecursions() - ); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("e")) { - Integer erosionFaces = NumericParser.parseInteger(parameters[1]); - if (erosionFaces != null) { - this.currentPreset = new ErosionPreset( - erosionFaces, - this.currentPreset.getErosionRecursions(), - this.currentPreset.getFillFaces(), - this.currentPreset.getFillRecursions() - ); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("F")) { - Integer fillRecursion = NumericParser.parseInteger(parameters[1]); - if (fillRecursion != null) { - this.currentPreset = new ErosionPreset( - this.currentPreset.getErosionFaces(), - this.currentPreset.getErosionRecursions(), - this.currentPreset.getFillFaces(), - fillRecursion - ); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("E")) { - Integer erosionRecursion = NumericParser.parseInteger(parameters[1]); - if (erosionRecursion != null) { - this.currentPreset = new ErosionPreset( - this.currentPreset.getErosionFaces(), - erosionRecursion, - this.currentPreset.getFillFaces(), - this.currentPreset.getFillRecursions() - ); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - return; - } + @CommandMethod("e ") + public void onBrushErosionfaces( + final @NotNull Snipe snipe, + final @Argument("erosion-faces") @Range(min = "0") int erosionFaces + ) { + this.currentPreset = new ErosionPreset( + erosionFaces, + this.currentPreset.getErosionRecursions(), + this.currentPreset.getFillFaces(), + this.currentPreset.getFillRecursions() + ); - if (!this.currentPreset.equals(currentPresetBackup)) { - if (this.currentPreset.getErosionFaces() != currentPresetBackup.getErosionFaces()) { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.erode.set-erosion-faces", - this.currentPreset.getErosionFaces() - )); - } - if (this.currentPreset.getFillFaces() != currentPresetBackup.getFillFaces()) { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.erode.set-fill-faces", - this.currentPreset.getFillFaces() - )); - } - if (this.currentPreset.getErosionRecursions() != currentPresetBackup.getErosionRecursions()) { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.erode.set-erosion-recursions", - this.currentPreset.getErosionRecursions() - )); - } - if (this.currentPreset.getFillRecursions() != currentPresetBackup.getFillRecursions()) { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.erode.set-fill-recursions", - this.currentPreset.getFillRecursions() - )); - } - } - } + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.erode.set-erosion-faces", + this.currentPreset.getErosionFaces() + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("f", "e", "F", "E", "default", "melt", "fill", "smooth", "lift", "floatclean"), - parameter, 0 - ); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("E ") + public void onBrushErosionrecursion( + final @NotNull Snipe snipe, + final @Argument("erosion-recursions") @Range(min = "0") int erosionRecursions + ) { + this.currentPreset = new ErosionPreset( + this.currentPreset.getErosionFaces(), + erosionRecursions, + this.currentPreset.getFillFaces(), + this.currentPreset.getFillRecursions() + ); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.erode.set-erosion-recursions", + this.currentPreset.getErosionRecursions() + )); + } + + @CommandMethod("f ") + public void onBrushFillfaces( + final @NotNull Snipe snipe, + final @Argument("fill-faces") @Range(min = "0") int fillFaces + ) { + this.currentPreset = new ErosionPreset( + this.currentPreset.getErosionFaces(), + this.currentPreset.getErosionRecursions(), + fillFaces, + this.currentPreset.getFillRecursions() + ); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.erode.set-fill-faces", + this.currentPreset.getFillFaces() + )); + } + + @CommandMethod("F ") + public void onBrushFillrecursion( + final @NotNull Snipe snipe, + final @Argument("fill-recursions") @Range(min = "0") int fillRecursions + ) { + this.currentPreset = new ErosionPreset( + this.currentPreset.getErosionFaces(), + this.currentPreset.getErosionRecursions(), + this.currentPreset.getFillFaces(), + fillRecursions + ); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.erode.set-fill-recursions", + this.currentPreset.getFillRecursions() + )); } @Override @@ -285,14 +280,26 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .brushSizeMessage() - .message(Caption.of("voxelsniper.brush.erode.set-erosion-faces", this.currentPreset.getErosionFaces())) - .message(Caption.of("voxelsniper.brush.erode.set-fill-faces", this.currentPreset.getFillFaces())) - .message(Caption.of("voxelsniper.brush.erode.set-erosion-recursions", this.currentPreset.getErosionRecursions())) - .message(Caption.of("voxelsniper.brush.erode.set-fill-recursions", this.currentPreset.getFillRecursions())) + .message(Caption.of( + "voxelsniper.brush.erode.set-erosion-faces", + this.currentPreset.getErosionFaces() + )) + .message(Caption.of( + "voxelsniper.brush.erode.set-erosion-recursions", + this.currentPreset.getErosionRecursions() + )) + .message(Caption.of( + "voxelsniper.brush.erode.set-fill-faces", + this.currentPreset.getFillFaces() + )) + .message(Caption.of( + "voxelsniper.brush.erode.set-fill-recursions", + this.currentPreset.getFillRecursions() + )) .send(); } - private enum Preset { + public enum Preset { DEFAULT("default", new ErosionPreset(0, 1, 0, 1)), MELT("melt", new ErosionPreset(2, 1, 5, 1)), @@ -431,7 +438,7 @@ public boolean isLiquid() { } - private record ErosionPreset(int erosionFaces, int erosionRecursions, int fillFaces, int fillRecursion) implements + protected record ErosionPreset(int erosionFaces, int erosionRecursions, int fillFaces, int fillRecursions) implements Serializable { @Serial @@ -439,13 +446,13 @@ private record ErosionPreset(int erosionFaces, int erosionRecursions, int fillFa @Override public int hashCode() { - return Objects.hash(this.erosionFaces, this.erosionRecursions, this.fillFaces, this.fillRecursion); + return Objects.hash(this.erosionFaces, this.erosionRecursions, this.fillFaces, this.fillRecursions); } @Override public boolean equals(Object obj) { if (obj instanceof ErosionPreset other) { - return this.erosionFaces == other.erosionFaces && this.erosionRecursions == other.erosionRecursions && this.fillFaces == other.fillFaces && this.fillRecursion == other.fillRecursion; + return this.erosionFaces == other.erosionFaces && this.erosionRecursions == other.erosionRecursions && this.fillFaces == other.fillFaces && this.fillRecursions == other.fillRecursions; } return false; } @@ -475,11 +482,11 @@ public int getFillFaces() { * Returns the fill recursion */ public int getFillRecursions() { - return this.fillRecursion; + return this.fillRecursions; } public ErosionPreset getInverted() { - return new ErosionPreset(this.fillFaces, this.fillRecursion, this.erosionFaces, this.erosionRecursions); + return new ErosionPreset(this.fillFaces, this.fillRecursions, this.erosionFaces, this.erosionRecursions); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ExtrudeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ExtrudeBrush.java index bf9ea5f9..d8ed4630 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ExtrudeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ExtrudeBrush.java @@ -1,62 +1,60 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.block.BlockState; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b extrude|ex") +@CommandPermission("voxelsniper.brush.extrude") public class ExtrudeBrush extends AbstractBrush { - private double trueCircle; + private boolean trueCircle; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.extrude.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("true")) { - this.trueCircle = 0.5; - messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(true))); - } else if (firstParameter.equalsIgnoreCase("false")) { - this.trueCircle = 0; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.parameter.true-circle", - VoxelSniperText.getStatus(false) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("true", "false"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.extrude.info")); + } + + @CommandMethod("") + public void onBrushTruecircle( + final @NotNull Snipe snipe, + final @Argument("true-circle") @Liberal boolean trueCircle + ) { + this.trueCircle = trueCircle; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )); } private void extrudeUpOrDown(Snipe snipe, boolean isUp) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); int brushSize = toolkitProperties.getBrushSize(); - double brushSizeSquared = Math.pow(brushSize + this.trueCircle, 2); + double brushSizeSquared = Math.pow(brushSize + (this.trueCircle ? 0.5 : 0), 2); for (int x = -brushSize; x <= brushSize; x++) { double xSquared = Math.pow(x, 2); for (int z = -brushSize; z <= brushSize; z++) { @@ -88,7 +86,7 @@ private void extrudeUpOrDown(Snipe snipe, boolean isUp) { private void extrudeNorthOrSouth(Snipe snipe, boolean isSouth) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); int brushSize = toolkitProperties.getBrushSize(); - double brushSizeSquared = Math.pow(brushSize + this.trueCircle, 2); + double brushSizeSquared = Math.pow(brushSize + (this.trueCircle ? 0.5 : 0), 2); for (int x = -brushSize; x <= brushSize; x++) { double xSquared = Math.pow(x, 2); for (int y = -brushSize; y <= brushSize; y++) { @@ -121,7 +119,7 @@ private void extrudeNorthOrSouth(Snipe snipe, boolean isSouth) { private void extrudeEastOrWest(Snipe snipe, boolean isEast) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); int brushSize = toolkitProperties.getBrushSize(); - double brushSizeSquared = Math.pow(brushSize + this.trueCircle, 2); + double brushSizeSquared = Math.pow(brushSize + (this.trueCircle ? 0.5 : 0), 2); for (int y = -brushSize; y <= brushSize; y++) { double ySquared = Math.pow(y, 2); for (int z = -brushSize; z <= brushSize; z++) { @@ -204,7 +202,10 @@ public void sendInfo(Snipe snipe) { .brushSizeMessage() .voxelHeightMessage() .voxelListMessage() - .message(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(this.trueCircle == 0.5))) + .message(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/FlatOceanBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/FlatOceanBrush.java index e9e75cf8..b00beca9 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/FlatOceanBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/FlatOceanBrush.java @@ -1,16 +1,20 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b flat_ocean|flatocean|fo") +@CommandPermission("voxelsniper.brush.flatocean") public class FlatOceanBrush extends AbstractBrush { private static final int DEFAULT_WATER_LEVEL = 29; @@ -25,58 +29,56 @@ public void loadProperties() { this.floorLevel = getIntegerProperty("default-floor-level", DEFAULT_FLOOR_LEVEL); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.flat-ocean.info")); + } + + @CommandMethod("yo ") + public void onBrushYo( + final @NotNull Snipe snipe, + final @Argument("water-level") int waterLevel + ) { + this.waterLevel = waterLevel < this.floorLevel ? this.floorLevel + 1 : waterLevel; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.flat-ocean.info")); - } else { - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("yo")) { - Integer newWaterLevel = NumericParser.parseInteger(parameters[1]); - if (newWaterLevel != null) { - if (newWaterLevel < this.floorLevel) { - newWaterLevel = this.floorLevel + 1; - } - this.waterLevel = newWaterLevel; - messenger.sendMessage(Caption.of("voxelsniper.brush.flat-ocean.set-water-level", this.waterLevel)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("yl")) { - EditSession editSession = getEditSession(); - Integer newFloorLevel = NumericParser.parseInteger(parameters[1]); - if (newFloorLevel != null) { - if (newFloorLevel > this.waterLevel) { - newFloorLevel = this.waterLevel - 1; - if (newFloorLevel <= editSession.getMinY()) { - newFloorLevel = editSession.getMinY() + 1; - this.waterLevel = editSession.getMinY() + 2; - } - } - this.floorLevel = newFloorLevel; - messenger.sendMessage(Caption.of("voxelsniper.brush.flat-ocean.set-ocean-level", this.floorLevel)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(Caption.of( + "voxelsniper.brush.flat-ocean.set-water-level", + this.waterLevel + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("yo", "yl"), parameter, 0); + @CommandMethod("yl ") + public void onBrushYl( + final @NotNull Snipe snipe, + final @Argument("floor-level") int floorLevel + ) { + int newFloorLevel = floorLevel; + if (newFloorLevel > this.waterLevel) { + EditSession editSession = this.getEditSession(); + newFloorLevel = this.waterLevel - 1; + + if (newFloorLevel <= editSession.getMinY()) { + newFloorLevel = editSession.getMinY() + 1; + this.waterLevel = editSession.getMinY() + 2; + } } - return super.handleCompletions(parameters, snipe); + this.floorLevel = newFloorLevel; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.flat-ocean.set-ocean-level", + this.floorLevel + )); } @Override @@ -132,8 +134,14 @@ private void flatOcean(int chunkX, int chunkZ) { public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() - .message(Caption.of("voxelsniper.brush.flat-ocean.set-water-level", this.waterLevel)) - .message(Caption.of("voxelsniper.brush.flat-ocean.set-ocean-level", this.floorLevel)) + .message(Caption.of( + "voxelsniper.brush.flat-ocean.set-water-level", + this.waterLevel + )) + .message(Caption.of( + "voxelsniper.brush.flat-ocean.set-ocean-level", + this.floorLevel + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/GenerateTreeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/GenerateTreeBrush.java index e53a95aa..0229c550 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/GenerateTreeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/GenerateTreeBrush.java @@ -1,5 +1,10 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.registry.state.PropertyKey; import com.sk89q.worldedit.math.BlockVector3; @@ -7,19 +12,23 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.material.MaterialSet; import com.thevoxelbox.voxelsniper.util.material.MaterialSets; -import com.thevoxelbox.voxelsniper.util.minecraft.Identifiers; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; +import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; import java.util.Random; -import java.util.stream.Stream; // Proposal: Use /v and /vr for leave and wood material // or two more parameters -- Monofraps +@RequireToolkit +@CommandMethod(value = "brush|b generate_tree|generatetree|gt") +@CommandPermission("voxelsniper.brush.generatetree") public class GenerateTreeBrush extends AbstractBrush { private static final BlockType DEFAULT_LEAF_TYPE = BlockTypes.OAK_LEAVES; @@ -44,14 +53,6 @@ public class GenerateTreeBrush extends AbstractBrush { .add(BlockTypes.SNOW) .build(); - private static final List LEAVES = BlockCategories.LEAVES.getAll().stream() - .map(leafType -> leafType.getId().substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH)) - .toList(); - - private static final List LOGS = BlockCategories.LOGS.getAll().stream() - .map(logType -> logType.getId().substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH)) - .toList(); - // Tree variables. private final Random randGenerator = new Random(); private final List branchBlocksLocation = new ArrayList<>(); @@ -97,212 +98,224 @@ private void resetValues() { this.nodeMax = getIntegerProperty("default-node-max", DEFAULT_NODE_MAX); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.generate-tree.info")); + } + + @CommandMethod("default") + public void onBrushDefault( + final @NotNull Snipe snipe + ) { + this.resetValues(); + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.generate-tree.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("default")) { // Default settings. - // ------- - // Presets - // ------- - resetValues(); - messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.reset")); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("lt")) { // Leaf Type - BlockType leafType = BlockTypes.get(parameters[1]); - if (leafType != null) { - this.leafType = leafType; - messenger.sendMessage(Caption.of("voxelsniper.brush.generate-tree.set-leaf-type", this.leafType.getId())); - } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.generate-tree.invalid-leaf-type", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("wt")) { // Wood Type - BlockType woodType = BlockTypes.get(parameters[1]); - if (woodType != null) { - this.woodType = woodType; - messenger.sendMessage(Caption.of("voxelsniper.brush.generate-tree.set-wood-type", this.woodType.getId())); - } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.generate-tree.invalid-wood-type", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("tt")) { // Tree Thickness - Integer thickness = NumericParser.parseInteger(parameters[1]); - if (thickness != null) { - this.thickness = thickness; - messenger.sendMessage(Caption.of("voxelsniper.brush.generate-tree.set-thickness", this.thickness)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("rf")) { // Root Float - this.rootFloat = Boolean.parseBoolean(parameters[1]); - messenger.sendMessage(Caption.of("voxelsniper.brush.generate-tree.set-floating-roots", this.rootFloat)); - } else if (firstParameter.equalsIgnoreCase("sh")) { // Starting Height - Integer startHeight = NumericParser.parseInteger(parameters[1]); - if (startHeight != null) { - this.startHeight = startHeight; - messenger.sendMessage(Caption.of("voxelsniper.brush.generate-tree.set-start-height", this.startHeight)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("rl")) { // Root Length - Integer rootLength = NumericParser.parseInteger(parameters[1]); - if (rootLength != null) { - this.rootLength = rootLength; - messenger.sendMessage(Caption.of("voxelsniper.brush.generate-tree.set-root-length", this.rootLength)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("ts")) { // Trunk Slope Chance - Integer slopeChance = NumericParser.parseInteger(parameters[1]); - if (slopeChance != null && slopeChance >= 0 && slopeChance <= 100) { - this.slopeChance = slopeChance; - messenger.sendMessage(Caption.of("voxelsniper.brush.generate-tree.set-trunk-slope", this.slopeChance)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("bl")) { // Branch Length - Integer branchLenght = NumericParser.parseInteger(parameters[1]); - if (branchLenght != null) { - this.branchLength = branchLenght; - messenger.sendMessage(Caption.of("voxelsniper.brush.generate-tree.set-branch-length", this.branchLength)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("minr")) { // Minimum Roots - Integer minRoots = NumericParser.parseInteger(parameters[1]); - if (minRoots != null) { - this.minRoots = minRoots; - if (this.minRoots > this.maxRoots) { - this.minRoots = this.maxRoots; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.generate-tree.invalid-minimum-roots", - this.minRoots - )); - } else { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.generate-tree.set-minimum-roots", - this.minRoots - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("maxr")) { // Maximum Roots - Integer maxRoots = NumericParser.parseInteger(parameters[1]); - if (maxRoots != null) { - this.maxRoots = maxRoots; - if (this.minRoots > this.maxRoots) { - this.maxRoots = this.minRoots; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.generate-tree.invalid-maximum-roots", - this.maxRoots - )); - } else { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.generate-tree.set-maximum-roots", - this.maxRoots - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("minh")) { // Height Minimum - Integer heightMinimum = NumericParser.parseInteger(parameters[1]); - if (heightMinimum != null) { - this.heightMin = heightMinimum; - if (this.heightMin > this.heightMax) { - this.heightMin = this.heightMax; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.generate-tree.invalid-minimum-height", - this.heightMin - )); - } else { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.generate-tree.set-minimum-height", - this.heightMin - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("maxh")) { // Height Maximum - Integer heightMaximum = NumericParser.parseInteger(parameters[1]); - if (heightMaximum != null) { - this.heightMax = heightMaximum; - if (this.heightMin > this.heightMax) { - this.heightMax = this.heightMin; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.generate-tree.invalid-maximum-height", - this.heightMax - )); - } else { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.generate-tree.set-maximum-height", - this.heightMax - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("minl")) { // Leaf Node Min Size - Integer nodeMin = NumericParser.parseInteger(parameters[1]); - if (nodeMin != null) { - this.nodeMin = nodeMin; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.generate-tree.set-minimum-leaf-thickness", - this.nodeMin - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("maxl")) { // Leaf Node Max Size - Integer nodeMax = NumericParser.parseInteger(parameters[1]); - if (nodeMax != null) { - this.nodeMax = nodeMax; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.generate-tree.set-maximum-leaf-thickness", - this.nodeMax - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.reset")); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of( - "lt", "wt", "tt", "rf", "sh", "rl", "ts", "bl", - "minr", "maxr", "minh", "maxh", "minl", "maxl", "default" - ), parameter, 0); - } - if (parameters.length == 2) { - String firstParameter = parameters[0]; - String parameter = parameters[1]; - if (firstParameter.equalsIgnoreCase("lt")) { - return super.sortCompletions(LEAVES.stream(), parameter, 1); - } else if (firstParameter.equalsIgnoreCase("wt")) { - return super.sortCompletions(LOGS.stream(), parameter, 1); - } else if (firstParameter.equalsIgnoreCase("rf")) { - return super.sortCompletions(Stream.of("true", "false"), parameter, 1); - } - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("lt ") + public void onBrushLt( + final @NotNull Snipe snipe, + final @NotNull @Argument("leaf-type") BlockType leafType + ) { + this.leafType = leafType; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-leaf-type", + this.leafType.getId() + )); + } + + @CommandMethod("wt ") + public void onBrushWt( + final @NotNull Snipe snipe, + final @NotNull @Argument("wood-type") BlockType woodType + ) { + this.woodType = woodType; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-wood-type", + this.woodType.getId() + )); + } + + @CommandMethod("tt ") + public void onBrushTt( + final @NotNull Snipe snipe, + final @Argument("thickness") @Range(min = "0") int thickness + ) { + this.thickness = thickness; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-thickness", + this.thickness + )); + } + + @CommandMethod("rf ") + public void onBrushRf( + final @NotNull Snipe snipe, + final @Argument("root-float") @Liberal boolean rootFloat + ) { + this.rootFloat = rootFloat; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-floating-roots", + VoxelSniperText.getStatus(this.rootFloat) + )); + } + + @CommandMethod("sh ") + public void onBrushSh( + final @NotNull Snipe snipe, + final @Argument("start-height") int startHeight + ) { + this.startHeight = startHeight; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-start-height", + this.startHeight + )); + } + + @CommandMethod("rl ") + public void onBrushRl( + final @NotNull Snipe snipe, + final @Argument("root-length") @Range(min = "0") int rootLength + ) { + this.rootLength = rootLength; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-root-length", + this.rootLength + )); + } + + @CommandMethod("ts ") + public void onBrushTs( + final @NotNull Snipe snipe, + final @Argument("slope-chance") @Range(min = "0", max = "100") int slopeChance + ) { + this.slopeChance = slopeChance; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-trunk-slope", + this.slopeChance + )); + } + + @CommandMethod("bl ") + public void onBrushBl( + final @NotNull Snipe snipe, + final @Argument("branch-length") @Range(min = "0") int branchLength + ) { + this.branchLength = branchLength; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-branch-length", + this.branchLength + )); + } + + @CommandMethod("minr ") + public void onBrushMinr( + final @NotNull Snipe snipe, + final @Argument("min-roots") @DynamicRange(min = "0", max = "maxRoots") int minRoots + ) { + this.minRoots = minRoots; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-minimum-roots", + this.minRoots + )); + } + + @CommandMethod("maxr ") + public void onBrushMaxr( + final @NotNull Snipe snipe, + final @Argument("max-roots") @DynamicRange(min = "minRoots") int maxRoots + ) { + this.maxRoots = maxRoots; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-maximum-roots", + this.maxRoots + )); + } + + @CommandMethod("minh ") + public void onBrushMinh( + final @NotNull Snipe snipe, + final @Argument("height-min") @DynamicRange(min = "0", max = "heightMax") int heightMin + ) { + this.heightMin = heightMin; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-minimum-height", + this.heightMin + )); + } + + @CommandMethod("maxh ") + public void onBrushMaxh( + final @NotNull Snipe snipe, + final @Argument("height-max") @DynamicRange(min = "heightMin") int heightMax + ) { + this.heightMax = heightMax; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-maximum-height", + this.heightMax + )); + } + + @CommandMethod("minl ") + public void onBrushMinl( + final @NotNull Snipe snipe, + final @Argument("node-min") @DynamicRange(min = "0", max = "nodeMax") int nodeMin + ) { + this.nodeMin = nodeMin; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-minimum-leaf-thickness", + this.nodeMin + )); + } + + @CommandMethod("maxl ") + public void onBrushMaxl( + final @NotNull Snipe snipe, + final @Argument("node-max") @DynamicRange(min = "nodeMin") int nodeMax + ) { + this.nodeMax = nodeMax; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.generate-tree.set-maximum-leaf-thickness", + this.nodeMax + )); } @Override @@ -608,20 +621,62 @@ private void generateTrunk() { public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() - .message(Caption.of("voxelsniper.brush.generate-tree.set-leaf-type", this.leafType.getId())) - .message(Caption.of("voxelsniper.brush.generate-tree.set-wood-type", this.woodType.getId())) - .message(Caption.of("voxelsniper.brush.generate-tree.set-thickness", this.thickness)) - .message(Caption.of("voxelsniper.brush.generate-tree.set-floating-roots", this.rootFloat)) - .message(Caption.of("voxelsniper.brush.generate-tree.set-start-height", this.startHeight)) - .message(Caption.of("voxelsniper.brush.generate-tree.set-root-length", this.rootLength)) - .message(Caption.of("voxelsniper.brush.generate-tree.set-trunk-slope", this.slopeChance)) - .message(Caption.of("voxelsniper.brush.generate-tree.set-branch-length", this.branchLength)) - .message(Caption.of("voxelsniper.brush.generate-tree.set-minimum-roots", this.minRoots)) - .message(Caption.of("voxelsniper.brush.generate-tree.set-maximum-roots", this.maxRoots)) - .message(Caption.of("voxelsniper.brush.generate-tree.set-minimum-height", this.heightMin)) - .message(Caption.of("voxelsniper.brush.generate-tree.set-maximum-height", this.heightMax)) - .message(Caption.of("voxelsniper.brush.generate-tree.set-minimum-leaf-thickness", this.nodeMin)) - .message(Caption.of("voxelsniper.brush.generate-tree.set-maximum-leaf-thickness", this.nodeMax)) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-leaf-type", + this.leafType.getId() + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-wood-type", + this.woodType.getId() + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-thickness", + this.thickness + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-floating-roots", + this.rootFloat + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-start-height", + this.startHeight + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-root-length", + this.rootLength + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-trunk-slope", + this.slopeChance + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-branch-length", + this.branchLength + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-minimum-roots", + this.minRoots + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-maximum-roots", + this.maxRoots + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-minimum-height", + this.heightMin + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-maximum-height", + this.heightMax + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-minimum-leaf-thickness", + this.nodeMin + )) + .message(Caption.of( + "voxelsniper.brush.generate-tree.set-maximum-leaf-thickness", + this.nodeMax + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/HeatRayBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/HeatRayBrush.java index 040a329b..8c27be08 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/HeatRayBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/HeatRayBrush.java @@ -1,11 +1,17 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; @@ -13,14 +19,16 @@ import com.thevoxelbox.voxelsniper.util.material.MaterialSet; import com.thevoxelbox.voxelsniper.util.material.MaterialSets; import com.thevoxelbox.voxelsniper.util.material.Materials; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; +import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; import org.bukkit.util.Vector; import org.bukkit.util.noise.PerlinNoiseGenerator; +import org.jetbrains.annotations.NotNull; -import java.util.List; import java.util.Random; -import java.util.stream.Stream; +@RequireToolkit +@CommandMethod(value = "brush|b heat_ray|heatray|hr") +@CommandPermission("voxelsniper.brush.heatray") public class HeatRayBrush extends AbstractBrush { private static final double REQUIRED_OBSIDIAN_DENSITY = 0.6; @@ -48,11 +56,11 @@ public class HeatRayBrush extends AbstractBrush { .with(BlockCategories.WOODEN_FENCES) .with(BlockCategories.FENCE_GATES) .with(BlockCategories.SNOW) + .with(BlockCategories.FIRE) .with(MaterialSets.TORCHES) .with(MaterialSets.FLORA) .add(BlockTypes.SPONGE) .add(BlockTypes.COBWEB) - .add(BlockTypes.FIRE) .add(BlockTypes.LADDER) .build(); @@ -61,6 +69,7 @@ public class HeatRayBrush extends AbstractBrush { private double requiredFireDensity; private double requiredAirDensity; + private boolean soulFire; private int octaves; private double frequency; private double amplitude; @@ -77,55 +86,74 @@ public void loadProperties() { this.amplitude = getDoubleProperty("default-amplitude", DEFAULT_AMPLITUDE); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.heat-ray.info")); + } + + @CommandMethod("") + public void onBrushSoulfire( + final @NotNull Snipe snipe, + final @Argument("soul-fire") @Liberal boolean soulFire + ) { + this.soulFire = soulFire; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.heat-ray.set-soul-fire", + VoxelSniperText.getStatus(this.soulFire) + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.heat-ray.info")); - } else { - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("oct")) { - Integer octaves = NumericParser.parseInteger(parameters[1]); - if (octaves != null) { - this.octaves = octaves; - messenger.sendMessage(Caption.of("voxelsniper.brush.heat-ray.set-octaves", this.octaves)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("amp")) { - Double amplitude = NumericParser.parseDouble(parameters[1]); - if (amplitude != null) { - this.amplitude = amplitude; - messenger.sendMessage(Caption.of("voxelsniper.brush.heat-ray.set-amplitude", this.amplitude)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("freq")) { - Double frequency = NumericParser.parseDouble(parameters[1]); - if (frequency != null) { - this.frequency = frequency; - messenger.sendMessage(Caption.of("voxelsniper.brush.heat-ray.set-frequency", this.frequency)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("oct ") + public void onBrushOct( + final @NotNull Snipe snipe, + final @Argument("octaves") @Range(min = "0") int octaves + ) { + this.octaves = octaves; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.heat-ray.set-octaves", + this.octaves + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("oct", "amp", "freq"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("amp ") + public void onBrushAmp( + final @NotNull Snipe snipe, + final @Argument("amplitude") double amplitude + ) { + this.amplitude = amplitude; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.heat-ray.set-amplitude", + this.amplitude + )); + } + + @CommandMethod("freq ") + public void onBrushFreq( + final @NotNull Snipe snipe, + final @Argument("frequency") double frequency + ) { + this.frequency = frequency; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.heat-ray.set-frequency", + this.frequency + )); } @Override @@ -139,7 +167,7 @@ public void handleGunpowderAction(Snipe snipe) { } /** - * Heat Ray executer. + * Heat Ray executor. */ public void heatRay(Snipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); @@ -148,6 +176,7 @@ public void heatRay(Snipe snipe) { Vector targetBlockVector = Vectors.toBukkit(targetBlock); Vector currentLocation = new Vector(); int brushSize = toolkitProperties.getBrushSize(); + BlockType fire = soulFire ? BlockTypes.SOUL_FIRE : BlockTypes.FIRE; for (int z = brushSize; z >= -brushSize; z--) { for (int x = brushSize; x >= -brushSize; x--) { for (int y = brushSize; y >= -brushSize; y--) { @@ -179,7 +208,7 @@ public void heatRay(Snipe snipe) { currentLocation.getBlockX(), currentLocation.getBlockY(), currentLocation.getBlockZ(), - BlockTypes.FIRE + fire ); continue; } @@ -235,12 +264,12 @@ public void heatRay(Snipe snipe) { ); } } else if (fireDensity >= this.requiredFireDensity) { - if (currentBlockType != BlockTypes.FIRE) { + if (currentBlockType != fire) { setBlock( currentLocation.getBlockX(), currentLocation.getBlockY(), currentLocation.getBlockZ(), - BlockTypes.FIRE + fire ); } } else if (airDensity >= this.requiredAirDensity) { @@ -263,9 +292,22 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .brushSizeMessage() - .message(Caption.of("voxelsniper.brush.heat-ray.set-octaves", this.octaves)) - .message(Caption.of("voxelsniper.brush.heat-ray.set-amplitude", this.amplitude)) - .message(Caption.of("voxelsniper.brush.heat-ray.set-frequency", this.frequency)) + .message(Caption.of( + "voxelsniper.brush.heat-ray.set-soul-fire", + VoxelSniperText.getStatus(this.soulFire) + )) + .message(Caption.of( + "voxelsniper.brush.heat-ray.set-octaves", + this.octaves + )) + .message(Caption.of( + "voxelsniper.brush.heat-ray.set-amplitude", + this.amplitude + )) + .message(Caption.of( + "voxelsniper.brush.heat-ray.set-frequency", + this.frequency + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/JockeyBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/JockeyBrush.java index 6bee123d..ab9ff6af 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/JockeyBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/JockeyBrush.java @@ -1,10 +1,15 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.Fawe; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.Sniper; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; @@ -16,11 +21,14 @@ import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.plugin.PluginManager; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.stream.Stream; +@RequireToolkit +@CommandMethod(value = "brush|b jockey") +@CommandPermission("voxelsniper.brush.jockey") public class JockeyBrush extends AbstractBrush { private static final int ENTITY_STACK_LIMIT = 50; @@ -40,44 +48,60 @@ public void loadProperties() { this.jockeyType = (JockeyType) getEnumProperty("default-jockey-type", JockeyType.class, DEFAULT_JOCKEY_TYPE); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.jockey.info")); + } + + @CommandMethod("t ") + public void onBrushT( + final @NotNull Snipe snipe, + final @NotNull @Argument("jockey-type") JockeyType jockeyType + ) { + this.jockeyType = jockeyType; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - boolean stack = false; - boolean playerOnly = false; - boolean inverse = false; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.jockey.set-mode", + this.jockeyType.getFullName() + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.jockey.info")); - } else { - if (parameters.length == 4) { - playerOnly = Boolean.parseBoolean(parameters[1]); - inverse = Boolean.parseBoolean(parameters[2]); - stack = Boolean.parseBoolean(parameters[3]); + @CommandMethod(" ") + public void onBrushJockeytype( + final @NotNull Snipe snipe, + final @Argument("player-only") @Liberal boolean playerOnly, + final @Argument("inverse") @Liberal boolean inverse, + final @Argument("stack") @Liberal boolean stack + ) { + if (inverse) { + if (playerOnly) { + this.onBrushT(snipe, JockeyType.INVERT_PLAYER_ONLY); } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - return; + this.onBrushT(snipe, JockeyType.INVERT_ALL_ENTITIES); } - } - if (inverse) { - this.jockeyType = playerOnly ? JockeyType.INVERT_PLAYER_ONLY : JockeyType.INVERT_ALL_ENTITIES; } else if (stack) { - this.jockeyType = playerOnly ? JockeyType.STACK_PLAYER_ONLY : JockeyType.STACK_ALL_ENTITIES; + if (playerOnly) { + this.onBrushT(snipe, JockeyType.STACK_PLAYER_ONLY); + } else { + this.onBrushT(snipe, JockeyType.STACK_ALL_ENTITIES); + } } else { - this.jockeyType = playerOnly ? JockeyType.NORMAL_PLAYER_ONLY : JockeyType.NORMAL_ALL_ENTITIES; - } - messenger.sendMessage(Caption.of("voxelsniper.brush.jockey.set-mode", this.jockeyType.getFullName())); - } - - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length <= 3) { - int index = parameters.length - 1; - String parameter = parameters[index]; - return super.sortCompletions(Stream.of("true", "false"), parameter, index); + if (playerOnly) { + this.onBrushT(snipe, JockeyType.NORMAL_PLAYER_ONLY); + } else { + this.onBrushT(snipe, JockeyType.NORMAL_ALL_ENTITIES); + } } - return super.handleCompletions(parameters, snipe); } @Override @@ -198,14 +222,17 @@ private void stack(Snipe snipe) { public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() - .message(Caption.of("voxelsniper.brush.jockey.set-mode", this.jockeyType.getFullName())) + .message(Caption.of( + "voxelsniper.brush.jockey.set-mode", + this.jockeyType.getFullName() + )) .send(); } /** * Available types of jockey modes. */ - private enum JockeyType { + public enum JockeyType { NORMAL_ALL_ENTITIES("normal-all-entities"), NORMAL_PLAYER_ONLY("normal-player-only"), diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/LightningBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/LightningBrush.java index 0f749018..f23fca84 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/LightningBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/LightningBrush.java @@ -1,14 +1,28 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.util.TaskManager; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import org.bukkit.World; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b lightning|light") +@CommandPermission("voxelsniper.brush.lightning") public class LightningBrush extends AbstractBrush { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { BlockVector3 targetBlock = getTargetBlock(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/MoveBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/MoveBrush.java index 4373e47a..cfac2a79 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/MoveBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/MoveBrush.java @@ -1,21 +1,27 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -import java.util.stream.Stream; /** * Moves a selection blockPositionY a certain amount. */ +@RequireToolkit +@CommandMethod(value = "brush|b move|mv") +@CommandPermission("voxelsniper.brush.move") public class MoveBrush extends AbstractBrush { private static final int MAX_BLOCK_COUNT = 5000000; @@ -37,66 +43,83 @@ public void loadProperties() { this.maxBlockCount = getIntegerProperty("max-block-count", MAX_BLOCK_COUNT); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.move.info")); + } + + @CommandMethod("reset") + public void onBrushReset( + final @NotNull Snipe snipe + ) { + this.moveDirections[0] = 0; + this.moveDirections[1] = 0; + this.moveDirections[2] = 0; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.move.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("reset")) { - this.moveDirections[0] = 0; - this.moveDirections[1] = 0; - this.moveDirections[2] = 0; - messenger.sendMessage(Caption.of("voxelsniper.brush.move.set-x", this.moveDirections[0])); - messenger.sendMessage(Caption.of("voxelsniper.brush.move.set-y", this.moveDirections[1])); - messenger.sendMessage(Caption.of("voxelsniper.brush.move.set-z", this.moveDirections[2])); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("x")) { - Integer moveDirection = NumericParser.parseInteger(parameters[1]); - if (moveDirection != null) { - this.moveDirections[0] = moveDirection; - messenger.sendMessage(Caption.of("voxelsniper.brush.move.set-x", this.moveDirections[0])); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("y")) { - Integer moveDirection = NumericParser.parseInteger(parameters[1]); - if (moveDirection != null) { - this.moveDirections[1] = moveDirection; - messenger.sendMessage(Caption.of("voxelsniper.brush.move.set-y", this.moveDirections[1])); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("z")) { - Integer moveDirection = NumericParser.parseInteger(parameters[1]); - if (moveDirection != null) { - this.moveDirections[2] = moveDirection; - messenger.sendMessage(Caption.of("voxelsniper.brush.move.set-z", this.moveDirections[2])); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(Caption.of( + "voxelsniper.brush.move.set-x", + this.moveDirections[0] + )); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.move.set-y", + this.moveDirections[1] + )); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.move.set-z", + this.moveDirections[2] + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("x", "y", "z", "reset"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("x ") + public void onBrushX( + final @NotNull Snipe snipe, + final @Argument("x-direction") int xDirection + ) { + this.moveDirections[0] = xDirection; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.move.set-x", + this.moveDirections[0] + )); + } + + @CommandMethod("y ") + public void onBrushY( + final @NotNull Snipe snipe, + final @Argument("y-direction") int yDirection + ) { + this.moveDirections[1] = yDirection; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.move.set-y", + this.moveDirections[1] + )); + } + + @CommandMethod("z ") + public void onBrushZ( + final @NotNull Snipe snipe, + final @Argument("z-direction") int zDirection + ) { + this.moveDirections[2] = zDirection; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.move.set-z", + this.moveDirections[2] + )); } @Override @@ -112,7 +135,7 @@ public void handleArrowAction(Snipe snipe) { this.moveSelection(snipe, this.selection, this.moveDirections); this.selection = null; } - } catch (RuntimeException exception) { + } catch (RuntimeException e) { messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-selection", this.selection.maxBlockCount)); } } @@ -130,7 +153,7 @@ public void handleGunpowderAction(Snipe snipe) { this.moveSelection(snipe, this.selection, this.moveDirections); this.selection = null; } - } catch (RuntimeException exception) { + } catch (RuntimeException e) { messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-selection", this.selection.maxBlockCount)); } } @@ -151,7 +174,7 @@ private void moveSelection(Snipe snipe, Selection selection, int[] direction) { newSelection.setLocation2(movedLocation2, selection.getWorld2()); try { newSelection.calculateRegion(); - } catch (RuntimeException exception) { + } catch (RuntimeException e) { messenger.sendMessage(Caption.of("voxelsniper.brush.move.invalid-new-selection")); } locations.forEach(block -> setBlock(block.getX(), block.getY(), block.getZ(), BlockTypes.AIR)); @@ -170,9 +193,18 @@ private void moveSelection(Snipe snipe, Selection selection, int[] direction) { public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() - .message(Caption.of("voxelsniper.brush.move.set-x", this.moveDirections[0])) - .message(Caption.of("voxelsniper.brush.move.set-y", this.moveDirections[1])) - .message(Caption.of("voxelsniper.brush.move.set-z", this.moveDirections[2])) + .message(Caption.of( + "voxelsniper.brush.move.set-x", + this.moveDirections[0] + )) + .message(Caption.of( + "voxelsniper.brush.move.set-y", + this.moveDirections[1] + )) + .message(Caption.of( + "voxelsniper.brush.move.set-z", + this.moveDirections[2] + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/OceanBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/OceanBrush.java index 9623fa57..c7ea1833 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/OceanBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/OceanBrush.java @@ -1,5 +1,9 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; @@ -7,17 +11,19 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.MaterialSet; import com.thevoxelbox.voxelsniper.util.material.MaterialSets; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b ocean|o") +@CommandPermission("voxelsniper.brush.ocean") public class OceanBrush extends AbstractBrush { private static final int WATER_LEVEL_MIN = 12; @@ -57,52 +63,46 @@ public void loadProperties() { this.waterLevel = getIntegerProperty("default-water-lever", DEFAULT_WATER_LEVEL); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.ocean.info")); + } + + @CommandMethod("wlevel ") + public void onBrushWlevel( + final @NotNull Snipe snipe, + final @Argument("water-level") @DynamicRange(min = "waterLevelMin") int waterLevel + ) { + this.waterLevel = waterLevel; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.ocean.info")); - } else { - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("wlevel")) { - Integer waterLevel = NumericParser.parseInteger(parameters[1]); - if (waterLevel != null && waterLevel > this.waterLevelMin) { - this.waterLevel = waterLevel; - messenger.sendMessage(Caption.of("voxelsniper.brush.ocean.set-water-level", this.waterLevel)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", this.waterLevelMin)); - } - } else if (firstParameter.equalsIgnoreCase("cfloor")) { - this.coverFloor = Boolean.parseBoolean(parameters[1]); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.ocean.set-floor-cover", - VoxelSniperText.getStatus(this.coverFloor) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(Caption.of( + "voxelsniper.brush.ocean.set-water-level", + this.waterLevel + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("wlevel", "cfloor"), parameter, 0); - } - if (parameters.length == 2) { - String firstParameter = parameters[0]; - if (firstParameter.equalsIgnoreCase("cfloor")) { - String parameter = parameters[1]; - return super.sortCompletions(Stream.of("true", "false"), parameter, 1); - } - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("cfloor ") + public void onBrushCfloor( + final @NotNull Snipe snipe, + final @Argument("cover-floor") @Liberal boolean coverFloor + ) { + this.coverFloor = coverFloor; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.ocean.set-floor-cover", + VoxelSniperText.getStatus(this.coverFloor) + )); } @Override @@ -122,10 +122,10 @@ private void oceanator(ToolkitProperties toolkitProperties) { int targetBlockX = targetBlock.getX(); int targetBlockZ = targetBlock.getZ(); int brushSize = toolkitProperties.getBrushSize(); - int minX = (int) Math.floor(targetBlockX - brushSize); - int minZ = (int) Math.floor(targetBlockZ - brushSize); - int maxX = (int) Math.floor(targetBlockX + brushSize); - int maxZ = (int) Math.floor(targetBlockZ + brushSize); + int minX = targetBlockX - brushSize; + int minZ = targetBlockZ - brushSize; + int maxX = targetBlockX + brushSize; + int maxZ = targetBlockZ + brushSize; for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { int currentHeight = getHeight(x, z); @@ -175,7 +175,10 @@ private int getHeight(int bx, int bz) { public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() - .message(Caption.of("voxelsniper.brush.ocean.set-water-level", this.waterLevel)) + .message(Caption.of( + "voxelsniper.brush.ocean.set-water-level", + this.waterLevel + )) .message(Caption.of( "voxelsniper.brush.ocean.set-floor-cover", VoxelSniperText.getStatus(this.coverFloor) diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/PaintingBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/PaintingBrush.java index b9f78c1a..7b091bdd 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/PaintingBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/PaintingBrush.java @@ -1,15 +1,29 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.Sniper; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.util.ArtHelper; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; /** * Painting scrolling Brush. */ +@RequireToolkit +@CommandMethod(value = "brush|b painting|paint") +@CommandPermission("voxelsniper.brush.painting") public class PaintingBrush extends AbstractBrush { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + /** * Scroll painting forward. * diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/PullBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/PullBrush.java index 868d8210..390ac2ab 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/PullBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/PullBrush.java @@ -1,19 +1,26 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.Materials; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; +import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.Set; +@RequireToolkit +@CommandMethod(value = "brush|b pull") +@CommandPermission("voxelsniper.brush.pull") public class PullBrush extends AbstractBrush { private static final int DEFAULT_PINCH = 1; @@ -31,28 +38,38 @@ public void loadProperties() { this.bubble = getIntegerProperty("default-bubble", DEFAULT_BUBBLE); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.pull.info")); + } + + @CommandMethod(" ") + public void onBrushPinchbubble( + final @NotNull Snipe snipe, + final @Argument("pinch") double pinch, + final @Argument("bubble") double bubble + ) { + this.pinch = 1 - pinch; + this.bubble = bubble; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.pull.info")); - } else { - if (parameters.length == 1) { - Double pinch = NumericParser.parseDouble(firstParameter); - Double bubble = NumericParser.parseDouble(firstParameter); - if (pinch != null && bubble != null) { - this.pinch = 1 - pinch; - this.bubble = bubble; - messenger.sendMessage(Caption.of("voxelsniper.brush.pull.set-pinch", this.pinch)); - messenger.sendMessage(Caption.of("voxelsniper.brush.pull.set-bubble", this.bubble)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[0])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(Caption.of( + "voxelsniper.brush.pull.set-pinch", + this.pinch + )); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.pull.set-bubble", + this.bubble + )); } @Override @@ -234,8 +251,14 @@ public void sendInfo(Snipe snipe) { .brushNameMessage() .brushSizeMessage() .voxelHeightMessage() - .message(Caption.of("voxelsniper.brush.pull.set-pinch", -this.pinch + 1)) - .message(Caption.of("voxelsniper.brush.pull.set-bubble", this.bubble)) + .message(Caption.of( + "voxelsniper.brush.pull.set-pinch", + -this.pinch + 1 + )) + .message(Caption.of( + "voxelsniper.brush.pull.set-bubble", + this.bubble + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RandomErodeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RandomErodeBrush.java index 5ef250d0..18a91875 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RandomErodeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RandomErodeBrush.java @@ -1,15 +1,22 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.Materials; +import org.jetbrains.annotations.NotNull; import java.util.Random; +@RequireToolkit +@CommandMethod(value = "brush|b random_erode|randomerode|re") +@CommandPermission("voxelsniper.brush.randomerode") public class RandomErodeBrush extends AbstractBrush { private static final double TRUE_CIRCLE = 0.5; @@ -17,24 +24,31 @@ public class RandomErodeBrush extends AbstractBrush { private final Random generator = new Random(); private BlockWrapper[][][] snap; private int brushSize; - private int erodeFace; - private int fillFace; - private int erodeRecursion; - private int fillRecursion; + private int erodeFaces; + private int fillFaces; + private int erodeRecursions; + private int fillRecursions; + + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } @Override public void handleArrowAction(Snipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); this.brushSize = toolkitProperties.getBrushSize(); this.snap = new BlockWrapper[0][0][0]; - this.erodeFace = this.generator.nextInt(5) + 1; - this.fillFace = this.generator.nextInt(3) + 3; - this.erodeRecursion = this.generator.nextInt(3); - this.fillRecursion = this.generator.nextInt(3); - if (this.fillRecursion == 0 && this.erodeRecursion == 0) { // if they are both zero, it will lead to a null pointer exception. Still want to give them a + this.erodeFaces = this.generator.nextInt(5) + 1; + this.fillFaces = this.generator.nextInt(3) + 3; + this.erodeRecursions = this.generator.nextInt(3); + this.fillRecursions = this.generator.nextInt(3); + if (this.fillRecursions == 0 && this.erodeRecursions == 0) { // if they are both zero, it will lead to a null pointer exception. Still want to give them a // chance to be zero though, for more interestingness -Gav - this.erodeRecursion = this.generator.nextInt(2) + 1; - this.fillRecursion = this.generator.nextInt(2) + 1; + this.erodeRecursions = this.generator.nextInt(2) + 1; + this.fillRecursions = this.generator.nextInt(2) + 1; } randomErosion(snipe); } @@ -44,14 +58,14 @@ public void handleGunpowderAction(Snipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); this.brushSize = toolkitProperties.getBrushSize(); this.snap = new BlockWrapper[0][0][0]; - this.erodeFace = this.generator.nextInt(3) + 3; - this.fillFace = this.generator.nextInt(5) + 1; - this.erodeRecursion = this.generator.nextInt(3); - this.fillRecursion = this.generator.nextInt(3); - if (this.fillRecursion == 0 && this.erodeRecursion == 0) { // if they are both zero, it will lead to a null pointer exception. Still want to give them a + this.erodeFaces = this.generator.nextInt(3) + 3; + this.fillFaces = this.generator.nextInt(5) + 1; + this.erodeRecursions = this.generator.nextInt(3); + this.fillRecursions = this.generator.nextInt(3); + if (this.fillRecursions == 0 && this.erodeRecursions == 0) { // if they are both zero, it will lead to a null pointer exception. Still want to give them a // chance to be zero though, for more interestingness -Gav - this.erodeRecursion = this.generator.nextInt(2) + 1; - this.fillRecursion = this.generator.nextInt(2) + 1; + this.erodeRecursions = this.generator.nextInt(2) + 1; + this.fillRecursions = this.generator.nextInt(2) + 1; } randomFilling(snipe); } @@ -77,7 +91,7 @@ private boolean erode(int x, int y, int z) { if (!this.snap[x][y][z - 1].isSolid()) { i++; } - return (i >= this.erodeFace); + return (i >= this.erodeFaces); } else { return false; } @@ -118,7 +132,7 @@ private boolean fill(int x, int y, int z) { this.snap[x][y][z].setType(getBlockType(block.getX(), block.getY(), block.getZ())); d++; } - return (d >= this.fillFace); + return (d >= this.fillFaces); } } @@ -147,8 +161,8 @@ private void setSnap(int brushSize, BlockVector3 targetBlock) { @SuppressWarnings("unused") private void randomErosion(Snipe snipe) { - if (this.erodeFace >= 0 && this.erodeFace <= 6) { - for (int currentErodeRecursion = 0; currentErodeRecursion < this.erodeRecursion; currentErodeRecursion++) { + if (this.erodeFaces >= 0 && this.erodeFaces <= 6) { + for (int currentErodeRecursion = 0; currentErodeRecursion < this.erodeRecursions; currentErodeRecursion++) { getMatrix(); double brushSizeSquared = Math.pow(this.brushSize + TRUE_CIRCLE, 2); for (int z = 1; z < this.snap.length - 1; z++) { @@ -167,9 +181,9 @@ private void randomErosion(Snipe snipe) { } } } - if (this.fillFace >= 0 && this.fillFace <= 6) { + if (this.fillFaces >= 0 && this.fillFaces <= 6) { double brushSizeSquared = Math.pow(this.brushSize + 0.5, 2); - for (int currentFillRecursion = 0; currentFillRecursion < this.fillRecursion; currentFillRecursion++) { + for (int currentFillRecursion = 0; currentFillRecursion < this.fillRecursions; currentFillRecursion++) { this.getMatrix(); for (int z = 1; z < this.snap.length - 1; z++) { double zSquared = Math.pow(z - (this.brushSize + 1), 2); @@ -191,9 +205,9 @@ private void randomErosion(Snipe snipe) { @SuppressWarnings("unused") private void randomFilling(Snipe snipe) { - if (this.fillFace >= 0 && this.fillFace <= 6) { + if (this.fillFaces >= 0 && this.fillFaces <= 6) { double bSquared = Math.pow(this.brushSize + 0.5, 2); - for (int currentFillRecursion = 0; currentFillRecursion < this.fillRecursion; currentFillRecursion++) { + for (int currentFillRecursion = 0; currentFillRecursion < this.fillRecursions; currentFillRecursion++) { this.getMatrix(); for (int z = 1; z < this.snap.length - 1; z++) { double zSquared = Math.pow(z - (this.brushSize + 1), 2); @@ -211,9 +225,9 @@ private void randomFilling(Snipe snipe) { } } } - if (this.erodeFace >= 0 && this.erodeFace <= 6) { + if (this.erodeFaces >= 0 && this.erodeFaces <= 6) { double bSquared = Math.pow(this.brushSize + TRUE_CIRCLE, 2); - for (int currentErodeRecursion = 0; currentErodeRecursion < this.erodeRecursion; currentErodeRecursion++) { + for (int currentErodeRecursion = 0; currentErodeRecursion < this.erodeRecursions; currentErodeRecursion++) { this.getMatrix(); for (int z = 1; z < this.snap.length - 1; z++) { double zSquared = Math.pow(z - (this.brushSize + 1), 2); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RegenerateChunkBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RegenerateChunkBrush.java index 77bae9ef..9fd991e6 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RegenerateChunkBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RegenerateChunkBrush.java @@ -1,21 +1,28 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; import com.thevoxelbox.voxelsniper.util.minecraft.Identifiers; +import org.jetbrains.annotations.NotNull; import java.util.List; -import java.util.stream.Stream; /** * Regenerates the target chunk. */ +@RequireToolkit +@CommandMethod(value = "brush|b regenerate_chunk|regeneratechunk|rc") +@CommandPermission("voxelsniper.brush.ellipsoid") public class RegenerateChunkBrush extends AbstractBrush { private static final String DEFAULT_BIOME = "default"; @@ -26,57 +33,60 @@ public class RegenerateChunkBrush extends AbstractBrush { private BiomeType biomeType = null; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.regenerate-chunk.info")); + } + + @CommandMethod("list") + public void onBrushList( + final @NotNull Snipe snipe + ) { SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(VoxelSniperText.formatListWithCurrent( + BiomeTypes.values(), + (type, type2) -> type.getId().compareTo(type2.getId()), + type -> TextComponent.of(type.getId().substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH)), + type -> type, + this.biomeType, + "voxelsniper.brush.biome" + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.regenerate-chunk.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("list")) { - messenger.sendMessage(VoxelSniperText.formatListWithCurrent( - BiomeTypes.values(), - (type, type2) -> type.getId().compareTo(type2.getId()), - type -> TextComponent.of(type.getId().substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH)), - type -> type, - this.biomeType, - "voxelsniper.brush.regenerate-chunk" - )); - } else { - if (firstParameter.equals(DEFAULT_BIOME)) { - this.biomeType = null; - } else { - BiomeType biomeType = BiomeTypes.get(firstParameter); - if (biomeType != null) { - this.biomeType = biomeType; - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-biome", firstParameter)); - } - } - messenger.sendMessage(Caption.of( - "voxelsniper.brush.regenerate-chunk.set-biome", - (this.biomeType == null ? Caption.of("voxelsniper.brush.regenerate-chunk.default-biome") : - this.biomeType.getId()) - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("default") + public void onBrushDefault( + final @NotNull Snipe snipe + ) { + this.biomeType = null; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.regenerate-chunk.set-biome", + Caption.of("voxelsniper.brush.regenerate-chunk.default-biome") + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.concat( - Stream.of("list", DEFAULT_BIOME), - BIOMES.stream() - ), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("") + public void onBrushBiometype( + final @NotNull Snipe snipe, + final @NotNull @Argument("biome-type") BiomeType biomeType + ) { + this.biomeType = biomeType; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.regenerate-chunk.set-biome", + this.biomeType.getId() + )); } @Override @@ -97,16 +107,27 @@ private void generateChunk(Snipe snipe) { SnipeMessenger messenger = snipe.createMessenger(); messenger.sendMessage(Caption.of( "voxelsniper.brush.regenerate-chunk.generate", - (this.biomeType == null ? Caption.of("voxelsniper.brush.regenerate-chunk.default-biome") : - this.biomeType.getId()), + (this.biomeType == null + ? Caption.of("voxelsniper.brush.regenerate-chunk.default-biome") + : this.biomeType.getId()), chunkX, chunkY, chunkZ )); if (regenerateChunk(chunkX, chunkZ, this.biomeType)) { - messenger.sendMessage(Caption.of("voxelsniper.brush.regenerate-chunk.generated", chunkX, chunkY, chunkZ)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.regenerate-chunk.generated", + chunkX, + chunkY, + chunkZ + )); } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.regenerate-chunk.generate-failed", chunkX, chunkY, chunkZ)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.regenerate-chunk.generate-failed", + chunkX, + chunkY, + chunkZ + )); } } @@ -117,8 +138,9 @@ public void sendInfo(Snipe snipe) { .message(Caption.of("voxelsniper.brush.regenerate-chunk.warning")) .message(Caption.of( "voxelsniper.brush.regenerate-chunk.set-biome", - (this.biomeType == null ? Caption.of("voxelsniper.brush.regenerate-chunk.default-biome") : - this.biomeType.getId()) + (this.biomeType == null + ? Caption.of("voxelsniper.brush.regenerate-chunk.default-biome") + : this.biomeType.getId()) )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RulerBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RulerBrush.java index bebe3bfe..871bbcf3 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RulerBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/RulerBrush.java @@ -1,15 +1,19 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b ruler|r") +@CommandPermission("voxelsniper.brush.ruler") public class RulerBrush extends AbstractBrush { private static final int DEFAULT_X_OFFSET = 0; @@ -23,46 +27,56 @@ public class RulerBrush extends AbstractBrush { private int yOffset = DEFAULT_Y_OFFSET; private int zOffset = DEFAULT_Z_OFFSET; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.ruler.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("ruler")) { - this.zOffset = 0; - this.yOffset = 0; - this.xOffset = 0; - messenger.sendMessage(Caption.of("voxelsniper.brush.ruler.ruler-mode")); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 3) { - Integer xOffset = NumericParser.parseInteger(parameters[0]); - Integer yOffset = NumericParser.parseInteger(parameters[1]); - Integer zOffset = NumericParser.parseInteger(parameters[2]); - this.xOffset = xOffset == null ? 0 : xOffset; - this.yOffset = yOffset == null ? 0 : yOffset; - this.zOffset = zOffset == null ? 0 : zOffset; - messenger.sendMessage(Caption.of("voxelsniper.brush.ruler.set-x-offset", this.xOffset)); - messenger.sendMessage(Caption.of("voxelsniper.brush.ruler.set-y-offset", this.yOffset)); - messenger.sendMessage(Caption.of("voxelsniper.brush.ruler.set-z-offset", this.zOffset)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.ruler.info")); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("ruler"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("ruler") + public void onBrushRuler( + final @NotNull Snipe snipe + ) { + this.xOffset = 0; + this.yOffset = 0; + this.zOffset = 0; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of("voxelsniper.brush.ruler.ruler-mode")); + } + + @CommandMethod(" ") + public void onBrushOffsets( + final @NotNull Snipe snipe, + final @Argument("x-offset") int xOffset, + final @Argument("y-offset") int yOffset, + final @Argument("z-offset") int zOffset + ) { + this.xOffset = xOffset; + this.yOffset = yOffset; + this.zOffset = zOffset; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.ruler.set-x-offset", + this.xOffset + )); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.ruler.set-y-offset", + this.yOffset + )); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.ruler.set-z-offset", + this.zOffset + )); } @Override @@ -99,9 +113,9 @@ public void handleGunpowderAction(Snipe snipe) { .subtract(this.coordinates) .length() * 100) / 100.0; double blockDistance = Math.round((Math.abs(Math.max(Math.max( - Math.abs(targetBlock.getX() - this.coordinates.getX()), - Math.abs(targetBlock.getY() - this.coordinates.getY()) - ), Math.abs(targetBlock.getZ() - this.coordinates.getZ()))) + 1) * 100) / 100.0; + Math.abs((double) targetBlock.getX() - this.coordinates.getX()), + Math.abs((double) targetBlock.getY() - this.coordinates.getY()) + ), Math.abs((double) targetBlock.getZ() - this.coordinates.getZ()))) + 1) * 100) / 100.0; messenger.sendMessage(Caption.of("voxelsniper.brush.ruler.euclidean-distance", distance)); messenger.sendMessage(Caption.of("voxelsniper.brush.ruler.block-distance", blockDistance)); } @@ -111,9 +125,18 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .patternMessage() - .message(Caption.of("voxelsniper.brush.ruler.set-x-offset", this.xOffset)) - .message(Caption.of("voxelsniper.brush.ruler.set-y-offset", this.yOffset)) - .message(Caption.of("voxelsniper.brush.ruler.set-z-offset", this.zOffset)) + .message(Caption.of( + "voxelsniper.brush.ruler.set-x-offset", + this.xOffset + )) + .message(Caption.of( + "voxelsniper.brush.ruler.set-y-offset", + this.yOffset + )) + .message(Caption.of( + "voxelsniper.brush.ruler.set-z-offset", + this.zOffset + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ScannerBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ScannerBrush.java index 70f6be81..d0236f95 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ScannerBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/ScannerBrush.java @@ -1,18 +1,23 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.block.BlockType; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b scanner|sc") +@CommandPermission("voxelsniper.brush.scanner") public class ScannerBrush extends AbstractBrush { private static final int DEPTH_MIN = 1; @@ -34,39 +39,32 @@ public void loadProperties() { this.depth = getIntegerProperty("default-depth", DEFAULT_DEPTH); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.scanner.info")); - } else { - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("d")) { - Integer depth = NumericParser.parseInteger(parameters[1]); - if (depth != null) { - this.depth = depth < this.depthMin ? this.depthMin : Math.min(depth, this.depthMax); - messenger.sendMessage(Caption.of("voxelsniper.brush.scanner.set-depth", this.depth)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("d"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.scanner.info")); + } + + @CommandMethod("d ") + public void onBrushD( + final @NotNull Snipe snipe, + final @Argument("depth") @DynamicRange(min = "depthMin", max = "depthMax") int depth + ) { + this.depth = depth; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.scanner.set-depth", + this.depth + )); } @Override @@ -154,7 +152,10 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .patternMessage() - .message(Caption.of("voxelsniper.brush.scanner.set-depth", this.depth)) + .message(Caption.of( + "voxelsniper.brush.scanner.set-depth", + this.depth + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SignOverwriteBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SignOverwriteBrush.java index cec1394f..cb889ba4 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SignOverwriteBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SignOverwriteBrush.java @@ -1,5 +1,11 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Greedy; +import cloud.commandframework.annotations.specifier.Liberal; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Capability; @@ -17,12 +23,13 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockType; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; import org.bukkit.ChatColor; +import org.jetbrains.annotations.NotNull; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -32,9 +39,10 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; -import java.util.Locale; -import java.util.stream.Stream; +@RequireToolkit +@CommandMethod(value = "brush|b sign_overwrite|signoverwrite|sio") +@CommandPermission("voxelsniper.brush.signoverwrite") public class SignOverwriteBrush extends AbstractBrush { private static final Side DEFAULT_SIDE = Side.FRONT; @@ -59,178 +67,165 @@ public SignOverwriteBrush() { @Override public void loadProperties() { - File dataFolder = new File(PLUGIN_DATA_FOLDER, "/signs"); - dataFolder.mkdirs(); - this.side = (Side) getEnumProperty("default-side", Side.class, DEFAULT_SIDE); } - @SuppressWarnings("deprecation") // Paper deprecation - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.sign-overwrite.info")); + } + + @CommandMethod("list") + public void onBrushList( + final @NotNull Snipe snipe + ) { SnipeMessenger messenger = snipe.createMessenger(); - ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); - String firstParameter = parameters[0]; - boolean textChanged = false; + messenger.sendMessage(VoxelSniperText.formatListWithCurrent( + Arrays.stream(Side.values()).toList(), + (side, side2) -> side.getName().compareTo(side2.getName()), + Side::getFullName, + side -> side, + this.side, + "voxelsniper.brush.sign-overwrite" + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("list")) { - messenger.sendMessage(VoxelSniperText.formatListWithCurrent( - Arrays.stream(Side.values()).toList(), - (side, side2) -> side.getName().compareTo(side2.getName()), - Side::getFullName, - side -> side, - this.side, - "voxelsniper.brush.sign-overwrite" - )); - } else if (firstParameter.equalsIgnoreCase("clear") || firstParameter.equalsIgnoreCase("c")) { - clearBuffer(); - messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.cleared")); - } else if (firstParameter.equalsIgnoreCase("clearall") || firstParameter.equalsIgnoreCase("ca")) { - clearBuffer(); - resetStates(); - messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.cleared-reset")); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - if (firstParameter.equalsIgnoreCase("side")) { - if (!isHangingSignsSupported()) { - messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.legacy-side")); - return; - } - if (parameters.length != 2) { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - return; - } + @CommandMethod("clear|c") + public void onBrushClear( + final @NotNull Snipe snipe + ) { + this.clearBuffer(); - String secondParameter = parameters[1]; - try { - this.side = Side.valueOf(secondParameter.toUpperCase(Locale.ROOT)); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.sign-overwrite.set-side", - this.side.getFullName() - )); - } catch (IllegalArgumentException exception) { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.sign-overwrite.invalid-side", - secondParameter - )); - } - } else if (Stream.of("1", "2", "3", "4") - .anyMatch(firstParameter::equalsIgnoreCase)) { - String secondParameter = parameters[1]; - Integer lineNumber = NumericParser.parseInteger(firstParameter); - if (lineNumber == null) { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", firstParameter)); - return; - } - int lineIndex = lineNumber - 1; - - if (secondParameter.equalsIgnoreCase("set")) { - if (parameters.length < 3) { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - return; - } - - StringBuilder newTextBuilder = new StringBuilder(); - // Go through the end of the array. - for (int index = 2; index < parameters.length; index++) { - String word = parameters[index]; - newTextBuilder.append(word); - - if (index < parameters.length - 1) { - newTextBuilder.append(" "); - } - } - - TextComponent formattedText = LegacyComponentSerializer.legacy() - .deserialize(newTextBuilder.toString(), LEGACY_AMPERSAND); - // Check the line length and cut the text if needed. - // There is no plain text serializer available yet, rely on legacy chat color stripping for now. - if (ChatColor.stripColor(toLegacyText(formattedText)).length() > MAX_SIGN_LINE_LENGTH) { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.sign-overwrite.invalid-length", - lineNumber, - MAX_SIGN_LINE_LENGTH - )); - formattedText = LegacyComponentSerializer.legacy() - .deserialize(newTextBuilder.substring(0, MAX_SIGN_LINE_LENGTH), LEGACY_AMPERSAND); - } - - this.signTextLines[lineIndex] = formattedText; - messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.set-line", lineNumber, formattedText)); - } else if (secondParameter.equalsIgnoreCase("toggle")) { - this.signLinesEnabled[lineIndex] = !this.signLinesEnabled[lineIndex]; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.sign-overwrite.line-status", - VoxelSniperText.getStatus(this.signLinesEnabled[lineIndex]) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (firstParameter.equalsIgnoreCase("multiple") || firstParameter.equalsIgnoreCase("m")) { - this.rangedMode = Boolean.parseBoolean(parameters[1]); - - messenger.sendMessage(Caption.of( - "voxelsniper.brush.sign-overwrite.set-ranged-mode", - VoxelSniperText.getStatus(this.rangedMode) - )); - if (this.rangedMode) { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.sign-overwrite.brush-size", - toolkitProperties.getBrushSize() - )); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.sign-overwrite.brush-height", - toolkitProperties.getVoxelHeight() - )); - } - } else if (firstParameter.equalsIgnoreCase("save") || firstParameter.equalsIgnoreCase("s")) { - String fileName = parameters[1]; - saveBufferToFile(snipe, fileName); - } else if (firstParameter.equalsIgnoreCase("open") || firstParameter.equalsIgnoreCase("o")) { - String fileName = parameters[1]; - textChanged = loadBufferFromFile(snipe, fileName); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.cleared")); + } + + @CommandMethod("clearall|ca") + public void onBrushClearall( + final @NotNull Snipe snipe + ) { + this.clearBuffer(); + this.resetStates(); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.cleared-reset")); + } + + @CommandMethod("side ") + public void onBrushSide( + final @NotNull Snipe snipe, + final @NotNull @Argument("side") Side side + ) { + SnipeMessenger messenger = snipe.createMessenger(); + if (!isHangingSignsSupported()) { + messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.legacy-side")); + return; } + this.side = side; - if (textChanged) { - displayBuffer(snipe); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.sign-overwrite.set-side", + this.side.getFullName() + )); + } + + @SuppressWarnings("deprecation") // Paper deprecation + @CommandMethod(" set ") + public void onBrushLineSet( + final @NotNull Snipe snipe, + final @Argument("line") @Range(min = "1", max = "4") int line, + final @NotNull @Argument("text") @Greedy String text + ) { + SnipeMessenger messenger = snipe.createMessenger(); + TextComponent formattedText = LegacyComponentSerializer.legacy().deserialize(text, LEGACY_AMPERSAND); + int lineIndex = line - 1; + + // Checks the line length and cut the text if needed. + // There is no plain text serializer available yet, rely on legacy chat color stripping for now. + if (ChatColor.stripColor(toLegacyText(formattedText)).length() > MAX_SIGN_LINE_LENGTH) { + messenger.sendMessage(Caption.of( + "voxelsniper.brush.sign-overwrite.invalid-length", + line, + MAX_SIGN_LINE_LENGTH + )); + formattedText = LegacyComponentSerializer.legacy() + .deserialize(text.substring(0, MAX_SIGN_LINE_LENGTH), LEGACY_AMPERSAND); } + + this.signTextLines[lineIndex] = formattedText; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.sign-overwrite.set-line", + line, + formattedText + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of( - "list", "side", "1", "2", "3", "4", - "clear", "c", "clearall", "ca", - "multiple", "m", "save", "s", "open", "o" - ), parameter, 0); + @CommandMethod(" toggle") + public void onBrushLineToggle( + final @NotNull Snipe snipe, + final @Argument("line") @Range(min = "1", max = "4") int line + ) { + int lineIndex = line - 1; + this.signLinesEnabled[lineIndex] = !this.signLinesEnabled[lineIndex]; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.sign-overwrite.line-status", + line, + VoxelSniperText.getStatus(this.signLinesEnabled[lineIndex]) + )); + } + + @CommandMethod("multiple|m ") + public void onBrushMultiple( + final @NotNull Snipe snipe, + final @Argument("ranged-mode") @Liberal boolean rangedMode + ) { + this.rangedMode = rangedMode; + + SnipeMessenger messenger = snipe.createMessenger(); + ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.sign-overwrite.set-ranged-mode", + VoxelSniperText.getStatus(this.rangedMode) + )); + if (this.rangedMode) { + messenger.sendMessage(Caption.of( + "voxelsniper.brush.sign-overwrite.brush-size", + toolkitProperties.getBrushSize() + )); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.sign-overwrite.brush-height", + toolkitProperties.getVoxelHeight() + )); } - if (parameters.length == 2) { - String firstParameter = parameters[0]; - if (firstParameter.equalsIgnoreCase("side")) { - String parameter = parameters[1]; - return super.sortCompletions(SIDES.stream(), parameter, 1); - } else if (Stream.of("1", "2", "3", "4") - .anyMatch(firstParameter::equalsIgnoreCase)) { - String parameter = parameters[1]; - return super.sortCompletions(Stream.of("set", "toggle"), parameter, 1); - } else if (firstParameter.equalsIgnoreCase("multiple")) { - String parameter = parameters[1]; - return super.sortCompletions(Stream.of("on", "off"), parameter, 1); - } + } + + @CommandMethod("save|s ") + public void onBrushSave( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "sign", parserName = "sign-file_parser") File sign + ) { + this.saveBufferToFile(snipe, sign); + } + + @CommandMethod("open|o ") + public void onBrushOpen( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "sign", parserName = "sign-file_parser") File sign + ) { + if (this.loadBufferFromFile(snipe, sign)) { + this.displayBuffer(snipe); } - return super.handleCompletions(parameters, snipe); } @Override @@ -299,7 +294,7 @@ private void setSignText(int x, int y, int z, BaseBlock block) { ListBinaryTag messages = text.getList("messages"); for (int i = 0; i < this.signTextLines.length; i++) { if (this.signLinesEnabled[i]) { - messages = messages.set(i, StringBinaryTag.of(toJson(this.signTextLines[i])), ignored -> { + messages = messages.set(i, StringBinaryTag.stringBinaryTag(toJson(this.signTextLines[i])), ignored -> { }); } } @@ -380,13 +375,8 @@ private void displayBuffer(Snipe snipe) { /** * Saves the buffer to file. */ - private void saveBufferToFile(Snipe snipe, String fileName) { + private void saveBufferToFile(Snipe snipe, File store) { SnipeMessenger messenger = snipe.createMessenger(); - File store = new File(PLUGIN_DATA_FOLDER, "/signs/" + fileName + ".vsign"); - if (store.exists()) { - messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.file-exists")); - return; - } try { store.createNewFile(); FileWriter outFile = new FileWriter(store); @@ -398,9 +388,9 @@ private void saveBufferToFile(Snipe snipe, String fileName) { outStream.close(); outFile.close(); messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.file-saved")); - } catch (IOException exception) { - messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.file-save-failed", exception.getMessage())); - exception.printStackTrace(); + } catch (IOException e) { + messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.file-save-failed", e.getMessage())); + e.printStackTrace(); } } @@ -409,9 +399,8 @@ private void saveBufferToFile(Snipe snipe, String fileName) { * * @return {@code true} if file has been loaded successfully, {@code false} otherwise */ - private boolean loadBufferFromFile(Snipe snipe, String fileName) { + private boolean loadBufferFromFile(Snipe snipe, File store) { SnipeMessenger messenger = snipe.createMessenger(); - File store = new File(PLUGIN_DATA_FOLDER, "/signs/" + fileName + ".vsign"); if (!store.exists()) { messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.file-missing")); return false; @@ -427,9 +416,9 @@ private boolean loadBufferFromFile(Snipe snipe, String fileName) { inFile.close(); messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.file-loaded")); return true; - } catch (IOException exception) { - messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.file-load-failed", exception.getMessage())); - exception.printStackTrace(); + } catch (IOException e) { + messenger.sendMessage(Caption.of("voxelsniper.brush.sign-overwrite.file-load-failed", e.getMessage())); + e.printStackTrace(); return false; } } @@ -495,7 +484,7 @@ public void sendInfo(Snipe snipe) { /** * Available types of sides. */ - private enum Side { + public enum Side { FRONT("front", "front_text"), BACK("back", "back_text"); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SnowConeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SnowConeBrush.java index 58c85e06..18e37163 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SnowConeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SnowConeBrush.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.registry.state.PropertyKey; import com.sk89q.worldedit.math.BlockVector3; @@ -7,12 +9,24 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.material.Materials; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b snow_cone|snowcone|snow") +@CommandPermission("voxelsniper.brush.snowcone") public class SnowConeBrush extends AbstractBrush { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SpiralStaircaseBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SpiralStaircaseBrush.java index 0c8a1452..80aa8d82 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SpiralStaircaseBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/SpiralStaircaseBrush.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.registry.state.PropertyKey; import com.sk89q.worldedit.math.BlockVector3; @@ -7,14 +9,16 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.Materials; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b spiral_staircase|spiralstaircase|sstair") +@CommandPermission("voxelsniper.brush.spiralstaircase") public class SpiralStaircaseBrush extends AbstractBrush { private static final String DEFAULT_SDIRECT = "c"; @@ -29,43 +33,80 @@ public void loadProperties() { this.sopen = getStringProperty("default-sopen", DEFAULT_SOPEN); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.spiral-staircase.info")); + } + + private void onBrushSdirectCommand(Snipe snipe, String sdirect) { + this.sdirect = sdirect; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.spiral-staircase.set-turns", + this.sdirect + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.spiral-staircase.info")); - } else { - if (parameters.length == 1) { - if (Stream.of("c", "cc") - .anyMatch(firstParameter::equalsIgnoreCase)) { - this.sdirect = firstParameter; - messenger.sendMessage(Caption.of("voxelsniper.brush.spiral-staircase.set-turns", this.sdirect)); - } else if (Stream.of("n", "e", "s", "w") - .anyMatch(firstParameter::equalsIgnoreCase)) { - this.sopen = firstParameter; - messenger.sendMessage(Caption.of("voxelsniper.brush.spiral-staircase.set-opens", this.sopen)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("c") + public void onBrushC( + final @NotNull Snipe snipe + ) { + this.onBrushSdirectCommand(snipe, "c"); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of( - "c", "cc", - "n", "e", "s", "w" - ), parameter, 0 - ); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("cc") + public void onBrushCc( + final @NotNull Snipe snipe + ) { + this.onBrushSdirectCommand(snipe, "cc"); + } + + private void onBrushSopenCommand(Snipe snipe, String sopen) { + this.sopen = sopen; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.spiral-staircase.set-opens", + this.sopen + )); + } + + @CommandMethod("n") + public void onBrushN( + final @NotNull Snipe snipe + ) { + this.onBrushSopenCommand(snipe, "n"); + } + + @CommandMethod("e") + public void onBrushE( + final @NotNull Snipe snipe + ) { + this.onBrushSopenCommand(snipe, "e"); + } + + @CommandMethod("s") + public void onBrushS( + final @NotNull Snipe snipe + ) { + this.onBrushSopenCommand(snipe, "s"); + } + + @CommandMethod("w") + public void onBrushW( + final @NotNull Snipe snipe + ) { + this.onBrushSopenCommand(snipe, "w"); } @Override @@ -350,15 +391,24 @@ public void sendInfo(Snipe snipe) { .brushSizeMessage() .patternMessage() .voxelHeightMessage() - .message(Caption.of("voxelsniper.brush.spiral-staircase.set-type", getStairType(snipe).getFullName())) - .message(Caption.of("voxelsniper.brush.spiral-staircase.set-turns", this.sdirect)) - .message(Caption.of("voxelsniper.brush.spiral-staircase.set-opens", this.sopen)) + .message(Caption.of( + "voxelsniper.brush.spiral-staircase.set-type", + getStairType(snipe).getFullName() + )) + .message(Caption.of( + "voxelsniper.brush.spiral-staircase.set-turns", + this.sdirect + )) + .message(Caption.of( + "voxelsniper.brush.spiral-staircase.set-opens", + this.sopen + )) .send(); } - private enum StairType { + public enum StairType { BLOCK("block"), - STEP("ttep"), + STEP("step"), STAIR("stair"); private final String name; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/TreeSnipeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/TreeSnipeBrush.java index bccb83d9..60505b40 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/TreeSnipeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/TreeSnipeBrush.java @@ -1,5 +1,8 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; @@ -7,22 +10,23 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.material.Materials; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; import java.util.stream.IntStream; -import java.util.stream.Stream; +@RequireToolkit +@CommandMethod(value = "brush|b tree_snipe|treesnipe|tree|t") +@CommandPermission("voxelsniper.brush.treesnipe") public class TreeSnipeBrush extends AbstractBrush { private static final TreeGenerator.TreeType DEFAULT_TREE_TYPE = TreeGenerator.TreeType.TREE; - private static final List TREES = new ArrayList<>(TreeGenerator.TreeType.getPrimaryAliases()); - private TreeGenerator.TreeType treeType; @Override @@ -32,50 +36,47 @@ public void loadProperties() { ); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.tree-snipe.info")); + } + + @CommandMethod("list") + public void onBrushList( + final @NotNull Snipe snipe + ) { SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.tree-sniper.inf")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("list")) { - messenger.sendMessage(VoxelSniperText.formatListWithCurrent( - List.of(TreeGenerator.TreeType.values()), - (type, type2) -> type.lookupKeys.get(0).compareTo(type2.lookupKeys.get(0)), - type -> TextComponent.of(type.lookupKeys.get(0)), - type -> type, - this.treeType, - "voxelsniper.brush.tree-sniper" - )); - } else { - TreeGenerator.TreeType treeType = TreeGenerator.TreeType.lookup(firstParameter); - - if (treeType != null) { - this.treeType = treeType; - messenger.sendMessage(Caption.of("voxelsniper.brush.tree-sniper.set-tree", this.treeType.getName())); - } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.tree-sniper.invalid-tree", firstParameter)); - } - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(VoxelSniperText.formatListWithCurrent( + List.of(TreeGenerator.TreeType.values()), + (type, type2) -> type.lookupKeys.get(0).compareTo(type2.lookupKeys.get(0)), + type -> TextComponent.of(type.lookupKeys.get(0)), + type -> type, + this.treeType, + "voxelsniper.brush.tree-snipe" + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.concat( - TREES.stream(), - Stream.of("list") - ), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("") + public void onBrushTreetype( + final @NotNull Snipe snipe, + final @NotNull @Argument("tree-type") TreeGenerator.TreeType treeType + ) { + this.treeType = treeType; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.tree-snipe.set-tree", + this.treeType.getName() + )); } @Override @@ -94,7 +95,7 @@ private void single(Snipe snipe, BlockVector3 targetBlock) { setBlock(targetBlock.getX(), targetBlock.getY() - 1, targetBlock.getZ(), BlockTypes.GRASS_BLOCK); if (!generateTree(targetBlock, this.treeType)) { SnipeMessenger messenger = snipe.createMessenger(); - messenger.sendMessage(Caption.of("voxelsniper.brush.tree-sniper.generate-failed")); + messenger.sendMessage(Caption.of("voxelsniper.brush.tree-snipe.generate-failed")); } setBlockData(targetBlock.getX(), targetBlock.getY() - 1, targetBlock.getZ(), currentBlockData); } @@ -112,7 +113,10 @@ private int getYOffset() { public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() - .message(Caption.of("voxelsniper.brush.tree-sniper.set-tree", this.treeType.getName())) + .message(Caption.of( + "voxelsniper.brush.tree-snipe.set-tree", + this.treeType.getName() + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/VoltmeterBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/VoltmeterBrush.java index 45ac61ea..f4e16e3b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/VoltmeterBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/VoltmeterBrush.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.util.TaskManager; import com.sk89q.worldedit.bukkit.BukkitAdapter; @@ -7,15 +9,27 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b voltmeter|volt") +@CommandPermission("voxelsniper.brush.voltmeter") public class VoltmeterBrush extends AbstractBrush { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { volt(snipe); @@ -36,7 +50,10 @@ private void data(Snipe snipe) { return; } int power = blockData.getState(powerProperty); - messenger.sendMessage(Caption.of("voxelsniper.brush.voltmeter.data", power)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.voltmeter.data", + power + )); } private void volt(Snipe snipe) { diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/WarpBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/WarpBrush.java index c155eac1..e2e2f6af 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/WarpBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/WarpBrush.java @@ -1,16 +1,30 @@ package com.thevoxelbox.voxelsniper.brush.type; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.Fawe; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.Sniper; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b warp|world") +@CommandPermission("voxelsniper.brush.warp") public class WarpBrush extends AbstractBrush { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { Sniper sniper = snipe.getSniper(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/AbstractBlendBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/AbstractBlendBrush.java index aeef6f6d..89b0ac82 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/AbstractBlendBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/AbstractBlendBrush.java @@ -10,36 +10,22 @@ import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.material.Materials; -import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.stream.Stream; public abstract class AbstractBlendBrush extends AbstractBrush { private boolean airExcluded = true; private boolean waterExcluded = true; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("water")) { - this.waterExcluded = !this.waterExcluded; - messenger.sendMessage(Caption.of("voxelsniper.brush.blend.set-water-mode", getStatus(this.waterExcluded))); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } + protected void onBrushWaterCommand(Snipe snipe) { + this.waterExcluded = !this.waterExcluded; - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("water"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.blend.set-water-mode", + getStatus(this.waterExcluded) + )); } @Override @@ -93,7 +79,10 @@ public void sendInfo(Snipe snipe) { .brushNameMessage() .brushSizeMessage() .patternMessage() - .message(Caption.of("voxelsniper.brush.blend.set-water-mode", getStatus(this.waterExcluded))) + .message(Caption.of( + "voxelsniper.brush.blend.set-water-mode", + getStatus(this.waterExcluded) + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendBallBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendBallBrush.java index 356402d7..6ffc05fb 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendBallBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendBallBrush.java @@ -1,31 +1,46 @@ package com.thevoxelbox.voxelsniper.brush.type.blend; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; -import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.math.MathHelper; import com.thevoxelbox.voxelsniper.util.painter.Painters; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +@RequireToolkit +@CommandMethod(value = "brush|b blend_ball|blendball|bb") +@CommandPermission("voxelsniper.brush.blendball") public class BlendBallBrush extends AbstractBlendBrush { - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.blend-ball.info")); - return; - } - super.handleCommand(parameters, snipe); + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.blend-ball.info")); + } + + @CommandMethod("water") + public void onBrushWater( + final @NotNull Snipe snipe + ) { + super.onBrushWaterCommand(snipe); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendDiscBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendDiscBrush.java index f8edc7ca..8aee8946 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendDiscBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendDiscBrush.java @@ -1,31 +1,46 @@ package com.thevoxelbox.voxelsniper.brush.type.blend; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; -import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.math.MathHelper; import com.thevoxelbox.voxelsniper.util.painter.Painters; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +@RequireToolkit +@CommandMethod(value = "brush|b blend_disc|blenddisc|bd") +@CommandPermission("voxelsniper.brush.blenddisc") public class BlendDiscBrush extends AbstractBlendBrush { - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.blend-disc.info")); - return; - } - super.handleCommand(parameters, snipe); + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.blend-disc.info")); + } + + @CommandMethod("water") + public void onBrushWater( + final @NotNull Snipe snipe + ) { + super.onBrushWaterCommand(snipe); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendVoxelBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendVoxelBrush.java index 2e2fc689..7f18d2c6 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendVoxelBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendVoxelBrush.java @@ -1,31 +1,46 @@ package com.thevoxelbox.voxelsniper.brush.type.blend; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; -import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.math.MathHelper; import com.thevoxelbox.voxelsniper.util.painter.Painters; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +@RequireToolkit +@CommandMethod(value = "brush|b blend_voxel|blendvoxel|bv") +@CommandPermission("voxelsniper.brush.blendvoxel") public class BlendVoxelBrush extends AbstractBlendBrush { - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.blend-voxel.info")); - return; - } - super.handleCommand(parameters, snipe); + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.blend-voxel.info")); + } + + @CommandMethod("water") + public void onBrushWater( + final @NotNull Snipe snipe + ) { + super.onBrushWaterCommand(snipe); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendVoxelDiscBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendVoxelDiscBrush.java index 2d79aa61..311e7013 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendVoxelDiscBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/blend/BlendVoxelDiscBrush.java @@ -1,31 +1,46 @@ package com.thevoxelbox.voxelsniper.brush.type.blend; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; -import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.math.MathHelper; import com.thevoxelbox.voxelsniper.util.painter.Painters; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +@RequireToolkit +@CommandMethod(value = "brush|b blend_voxel_disc|blendvoxeldisc|bvd") +@CommandPermission("voxelsniper.brush.blendvoxeldisc") public class BlendVoxelDiscBrush extends AbstractBlendBrush { - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.blend-voxel-disc.info")); - return; - } - super.handleCommand(parameters, snipe); + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.blend-voxel-disc.info")); + } + + @CommandMethod("water") + public void onBrushWater( + final @NotNull Snipe snipe + ) { + super.onBrushWaterCommand(snipe); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/canyon/CanyonBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/canyon/CanyonBrush.java index 57aa3ff2..c0b113f9 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/canyon/CanyonBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/canyon/CanyonBrush.java @@ -1,18 +1,23 @@ package com.thevoxelbox.voxelsniper.brush.type.canyon; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b canyon|ca") +@CommandPermission("voxelsniper.brush.canyon") public class CanyonBrush extends AbstractBrush { private static final int SHIFT_LEVEL_MIN = -54; @@ -33,53 +38,32 @@ public void loadProperties() { this.yLevel = getIntegerProperty("default-y-level", DEFAULT_Y_LEVEL); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.canyon.info")); - } else { - if (parameters.length == 2) { - - if (firstParameter.equalsIgnoreCase("y")) { - Integer yLevel = NumericParser.parseInteger(parameters[1]); - if (yLevel != null) { - if (yLevel < this.shiftLevelMin) { - yLevel = this.shiftLevelMin; - messenger.sendMessage(Caption.of( - "voxelsniper.error.invalid-number-greater-equal", - this.shiftLevelMin - )); - } else if (yLevel > this.shiftLevelMax) { - yLevel = this.shiftLevelMax; - messenger.sendMessage(Caption.of( - "voxelsniper.error.invalid-number-lower-equal", - this.shiftLevelMax - )); - } - this.yLevel = yLevel; - messenger.sendMessage(Caption.of("voxelsniper.brush.canyon.set-shift-level", this.yLevel)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("y"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.canyon.info")); + } + + @CommandMethod("y ") + public void onBrushY( + final @NotNull Snipe snipe, + final @Argument("y-level") @DynamicRange(min = "shiftLevelMin", max = "shiftLevelMax") int yLevel + ) { + this.yLevel = yLevel; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.canyon.set-shift-level", + this.yLevel + )); } @Override @@ -125,7 +109,10 @@ protected void canyon(int chunkX, int chunkZ) { public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() - .message(Caption.of("voxelsniper.brush.canyon.set-shift-level", this.yLevel)) + .message(Caption.of( + "voxelsniper.brush.canyon.set-shift-level", + this.yLevel + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/canyon/CanyonSelectionBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/canyon/CanyonSelectionBrush.java index 1a1d5122..0d370284 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/canyon/CanyonSelectionBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/canyon/CanyonSelectionBrush.java @@ -1,16 +1,47 @@ package com.thevoxelbox.voxelsniper.brush.type.canyon; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b canyon_selection|canyonselection|cas") +@CommandPermission("voxelsniper.brush.canyonselection") public class CanyonSelectionBrush extends CanyonBrush { private boolean first = true; private int fx; private int fz; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrush(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfo(snipe); + } + + @CommandMethod("y ") + public void onBrushY( + final @NotNull Snipe snipe, + final @Argument("y-level") @DynamicRange(min = "shiftLevelMin", max = "shiftLevelMax") int yLevel + ) { + super.onBrushY(snipe, yLevel); + } + @Override public void handleArrowAction(Snipe snipe) { execute(snipe); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/entity/EntityBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/entity/EntityBrush.java index 3f948efb..814962ee 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/entity/EntityBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/entity/EntityBrush.java @@ -1,5 +1,8 @@ package com.thevoxelbox.voxelsniper.brush.type.entity; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.util.TaskManager; import com.sk89q.worldedit.EditSession; @@ -9,24 +12,22 @@ import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityTypes; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; import com.thevoxelbox.voxelsniper.util.minecraft.Identifiers; import org.bukkit.World; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b entity|en") +@CommandPermission("voxelsniper.brush.entity") public class EntityBrush extends AbstractBrush { private static final EntityType DEFAULT_ENTITY_TYPE = EntityTypes.ZOMBIE; - private static final List ENTITIES = EntityType.REGISTRY.values().stream() - .map(entityType -> entityType.getId().substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH)) - .toList(); - private EntityType entityType; @Override @@ -34,50 +35,47 @@ public void loadProperties() { this.entityType = (EntityType) getRegistryProperty("default-entity-type", EntityType.REGISTRY, DEFAULT_ENTITY_TYPE); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.entity.info")); + } + + @CommandMethod("list") + public void onBrushList( + final @NotNull Snipe snipe + ) { SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.entity.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("list")) { - messenger.sendMessage(VoxelSniperText.formatListWithCurrent( - EntityType.REGISTRY.values(), - (type, type2) -> type.getId().compareTo(type2.getId()), - type -> TextComponent.of(type.getId().substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH)), - type -> type, - this.entityType, - "voxelsniper.brush.entity" - )); - } else { - EntityType currentEntity = EntityTypes.get(firstParameter); - - if (currentEntity != null) { - this.entityType = currentEntity; - messenger.sendMessage(Caption.of("voxelsniper.brush.entity.set-entity-type", this.entityType.getName())); - } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.entity.invalid-entity-type", firstParameter)); - } - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(VoxelSniperText.formatListWithCurrent( + EntityType.REGISTRY.values(), + (type, type2) -> type.getId().compareTo(type2.getId()), + type -> TextComponent.of(type.getId().substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH)), + type -> type, + this.entityType, + "voxelsniper.brush.entity" + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.concat( - ENTITIES.stream(), - Stream.of("list") - ), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("") + public void onBrushEntitytype( + final @NotNull Snipe snipe, + final @NotNull @Argument("entity-type") EntityType entityType + ) { + this.entityType = entityType; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.entity.set-entity-type", + this.entityType.getName() + )); } @Override @@ -113,7 +111,7 @@ private void spawn(Snipe snipe) { break; } } - } catch (RuntimeException exception) { + } catch (RuntimeException e) { messenger.sendMessage(Caption.of("voxelsniper.brush.entity.cannot-spawn")); } return null; @@ -123,7 +121,10 @@ private void spawn(Snipe snipe) { @Override public void sendInfo(Snipe snipe) { snipe.createMessageSender() - .message(Caption.of("voxelsniper.brush.entity.set-entity-type", this.entityType.getName())) + .message(Caption.of( + "voxelsniper.brush.entity.set-entity-type", + this.entityType.getName() + )) .brushSizeMessage() .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/entity/EntityRemovalBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/entity/EntityRemovalBrush.java index 0f249e2c..f2d07e95 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/entity/EntityRemovalBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/entity/EntityRemovalBrush.java @@ -1,53 +1,41 @@ package com.thevoxelbox.voxelsniper.brush.type.entity; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.util.TaskManager; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.EntityClassArgument; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; import org.bukkit.World; import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.stream.Stream; +@RequireToolkit +@CommandMethod(value = "brush|b entity_removal|entityremoval|er") +@CommandPermission("voxelsniper.brush.entityremoval") public class EntityRemovalBrush extends AbstractBrush { - private static final List DEFAULT_EXEMPTIONS = Arrays.asList("org.bukkit.entity.Player", - "org.bukkit.entity.Hanging", "org.bukkit.entity.NPC" + private static final List DEFAULT_EXEMPTIONS = Arrays.asList( + "org.bukkit.entity.Player", + "org.bukkit.entity.Hanging", + "org.bukkit.entity.NPC" ); - private static final List ENTITY_CLASSES = Arrays.stream(EntityType.values()) - .map(EntityType::getEntityClass) - .flatMap(entityClass -> getEntityClassHierarchy(entityClass).stream()) - .distinct() - .map(Class::getCanonicalName) - .toList(); - private List exemptions; - private static List> getEntityClassHierarchy(Class entityClass) { - List> entityClassHierarchy = new ArrayList<>(10); - entityClassHierarchy.add(Entity.class); - Class currentClass = entityClass; - - while (currentClass != null && !currentClass.equals(Entity.class)) { - entityClassHierarchy.add(currentClass); - entityClassHierarchy.addAll(Arrays.asList(currentClass.getInterfaces())); - - currentClass = currentClass.getSuperclass(); - } - return entityClassHierarchy; - } - @SuppressWarnings("unchecked") @Override public void loadProperties() { @@ -56,67 +44,59 @@ public void loadProperties() { ); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.entity.removal")); + } + + @CommandMethod("list") + public void onBrushList( + final @NotNull Snipe snipe + ) { SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.entity.removal")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("list")) { - messenger.sendMessage(VoxelSniperText.formatList( - ENTITY_CLASSES, - String::compareTo, - TextComponent::of, - "voxelsniper.brush.entity-removal" - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("+")) { - String exemptionToAdd = parameters[1]; - if (isEntityClass(exemptionToAdd)) { - this.exemptions.add(exemptionToAdd); - messenger.sendMessage(Caption.of("voxelsniper.brush.entity-removal.add-entity-class", exemptionToAdd)); - } else { - messenger.sendMessage(Caption.of( - "voxelsniper.brush.entity-removal.invalid-entity-class", - exemptionToAdd - )); - } - } else if (firstParameter.equalsIgnoreCase("-")) { - String exemptionToRemove = parameters[1]; - this.exemptions.remove(exemptionToRemove); - messenger.sendMessage(Caption.of("voxelsniper.brush.entity-removal.remove-entity-class", exemptionToRemove)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(VoxelSniperText.formatList( + EntityClassArgument.ENTITY_CLASSES, + String::compareTo, + TextComponent::of, + "voxelsniper.brush.entity-removal" + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("+", "-", "list"), parameter, 0); - } - if (parameters.length == 2) { - String firstParameter = parameters[0]; - if (firstParameter.equalsIgnoreCase("+")) { - String parameter = parameters[1]; - return super.sortCompletions(ENTITY_CLASSES.stream(), parameter, 1); - } else if (firstParameter.equalsIgnoreCase("-")) { - String parameter = parameters[1]; - return super.sortCompletions(this.exemptions.stream(), parameter, 1); - } - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("add ") + public void onBrushPlus( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "entity-class", parserName = "entity-class_parser") Class entityClass + ) { + this.exemptions.add(entityClass.getCanonicalName()); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.entity-removal.add-entity-class", + entityClass + )); + } + + @CommandMethod("remove ") + public void onBrushMinus( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "entity-class", parserName = "entity-class_parser") Class entityClass + ) { + this.exemptions.remove(entityClass.getCanonicalName()); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.entity-removal.remove-entity-class", + entityClass + )); } @Override @@ -165,18 +145,9 @@ private int removeEntities(int chunkX, int chunkZ) { }); } - private boolean isEntityClass(String path) { - try { - Class clazz = Class.forName(path); - return Entity.class.isAssignableFrom(clazz); - } catch (ClassNotFoundException e) { - return false; - } - } - private boolean isEntityClassInExemptionList(Class entityClass) { - // Create a list of superclasses and interfaces implemented by the current entity type - List> entityClassHierarchy = getEntityClassHierarchy(entityClass); + // Creates a list of superclasses and interfaces implemented by the current entity type. + List> entityClassHierarchy = EntityClassArgument.getEntityClassHierarchy(entityClass); return this.exemptions.stream() .anyMatch(exemption -> entityClassHierarchy.stream() .map(Class::getCanonicalName) diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/AbstractPerformerBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/AbstractPerformerBrush.java index f4750669..6154c6c5 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/AbstractPerformerBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/AbstractPerformerBrush.java @@ -4,13 +4,11 @@ import com.thevoxelbox.voxelsniper.brush.PerformerBrush; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; import com.thevoxelbox.voxelsniper.performer.Performer; -import com.thevoxelbox.voxelsniper.performer.PerformerRegistry; import com.thevoxelbox.voxelsniper.performer.property.PerformerCreator; import com.thevoxelbox.voxelsniper.performer.property.PerformerProperties; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; -import java.util.Arrays; import java.util.Random; public abstract class AbstractPerformerBrush extends AbstractBrush implements PerformerBrush { @@ -62,28 +60,6 @@ public void loadProperties() { this.splatterRecursions = getIntegerProperty("default-splatter-recursions", DEFAULT_SPLATTER_RECURSIONS); } - @Override - public void handlePerformerCommand(String[] parameters, Snipe snipe, PerformerRegistry performerRegistry) { - String parameter = parameters[0]; - PerformerProperties performerProperties = performerRegistry.getPerformerProperties(parameter); - if (performerProperties == null) { - super.handleCommand(parameters, snipe); - return; - } - this.performerProperties = performerProperties; - PerformerCreator performerCreator = this.performerProperties.getCreator(); - this.performer = performerCreator.create(); - this.performer.setProperties(this.performerProperties); - this.performer.loadProperties(); - sendInfo(snipe); - PerformerSnipe performerSnipe = new PerformerSnipe(snipe, this.performerProperties, this.performer); - this.performer.sendInfo(performerSnipe); - if (parameters.length > 1) { - String[] additionalArguments = Arrays.copyOfRange(parameters, 1, parameters.length); - super.handleCommand(additionalArguments, snipe); - } - } - @Override public void initialize(Snipe snipe) { PerformerSnipe performerSnipe = new PerformerSnipe(snipe, this.performerProperties, this.performer); @@ -96,8 +72,15 @@ public void sendPerformerInfo(Snipe snipe) { this.performer.sendInfo(performerSnipe); } + @Override public Performer getPerformer() { return this.performer; } + @Override + public void setPerformer(Performer performer) { + this.performer = performer; + this.performerProperties = performer.getProperties(); + } + } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/BallBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/BallBrush.java index 2f531b6a..91e57cd8 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/BallBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/BallBrush.java @@ -1,20 +1,26 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; import com.thevoxelbox.voxelsniper.util.painter.Painters; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; /** * A brush that creates a solid ball. */ +@RequireToolkit +@CommandMethod(value = "brush|b ball|b") +@CommandPermission("voxelsniper.brush.ball") public class BallBrush extends AbstractPerformerBrush { private boolean trueCircle; @@ -23,40 +29,32 @@ public class BallBrush extends AbstractPerformerBrush { public void loadProperties() { } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.ball.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("true")) { - this.trueCircle = true; - messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(true))); - } else if (firstParameter.equalsIgnoreCase("false")) { - this.trueCircle = false; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.parameter.true-circle", - VoxelSniperText.getStatus(false) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.ball.info")); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("true", "false"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("") + public void onBrushTruecircle( + final @NotNull Snipe snipe, + final @Argument("true-circle") @Liberal boolean trueCircle + ) { + this.trueCircle = trueCircle; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )); } @Override @@ -90,7 +88,10 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .brushSizeMessage() - .message(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(this.trueCircle))) + .message(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/BlobBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/BlobBrush.java index 22d08485..b9679bce 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/BlobBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/BlobBrush.java @@ -1,15 +1,20 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b blob|splatblob") +@CommandPermission("voxelsniper.brush.blob") public class BlobBrush extends AbstractPerformerBrush { @Override @@ -20,46 +25,34 @@ public void loadProperties() { this.growthPercent = getIntegerProperty("default-growth-percent", DEFAULT_GROWTH_PERCENT); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.blob.info", this.growthPercentMin, - this.growthPercentMax, DEFAULT_GROWTH_PERCENT - )); - } else { - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("g")) { - Integer growthPercent = NumericParser.parseInteger(parameters[1]); - if (growthPercent != null && growthPercent >= super.growthPercentMin && growthPercent <= super.growthPercentMax) { - this.growthPercent = growthPercent; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.blob.set-growth-percent", - DECIMAL_FORMAT.format(this.growthPercent / 100) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.growthPercentMin, this.growthPercentMax - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.blob.info", + this.growthPercentMin, this.growthPercentMax, DEFAULT_GROWTH_PERCENT + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("g"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("g ") + public void onBrushG( + final @NotNull Snipe snipe, + final @Argument("growth-percent") @DynamicRange(min = "growthPercentMin", max = "growthPercentMax") int growthPercent + ) { + this.growthPercent = growthPercent; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.blob.set-growth-percent", + DECIMAL_FORMAT.format(this.growthPercent / 100) + )); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/CheckerVoxelDiscBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/CheckerVoxelDiscBrush.java index 400dd53e..e260d7b7 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/CheckerVoxelDiscBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/CheckerVoxelDiscBrush.java @@ -1,15 +1,21 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b checker_voxel_disc|checkervoxeldisc|cvd") +@CommandPermission("voxelsniper.brush.checkervoxeldisc") public class CheckerVoxelDiscBrush extends AbstractPerformerBrush { private boolean useWorldCoordinates = true; @@ -18,39 +24,32 @@ public class CheckerVoxelDiscBrush extends AbstractPerformerBrush { public void loadProperties() { } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.checker-voxel-disc.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("true")) { - this.useWorldCoordinates = true; - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.checker-voxel-disc" + - ".set-using-world-coordinates", VoxelSniperText.getStatus(true))); - } else if (firstParameter.equalsIgnoreCase("false")) { - this.useWorldCoordinates = false; - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.checker-voxel-disc" + - ".set-using-world-coordinates", VoxelSniperText.getStatus(false))); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.checker-voxel-disc.info")); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("true", "false"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("") + public void onBrushUseworldcoordinates( + final @NotNull Snipe snipe, + final @Argument("use-world-coordinates") @Liberal boolean useWorldCoordinates + ) { + this.useWorldCoordinates = useWorldCoordinates; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.checker-voxel-disc.set-using-world-coordinates", + VoxelSniperText.getStatus(this.useWorldCoordinates) + )); } @Override @@ -89,8 +88,10 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .brushSizeMessage() - .message(Caption.of("voxelsniper.performer-brush.checker-voxel-disc" + - ".set-using-world-coordinates", VoxelSniperText.getStatus(this.useWorldCoordinates))) + .message(Caption.of( + "voxelsniper.performer-brush.checker-voxel-disc.set-using-world-coordinates", + VoxelSniperText.getStatus(this.useWorldCoordinates) + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/CylinderBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/CylinderBrush.java index e57fbb0d..a3d3c51b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/CylinderBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/CylinderBrush.java @@ -1,86 +1,86 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b cylinder|c") +@CommandPermission("voxelsniper.brush.cylinder") public class CylinderBrush extends AbstractPerformerBrush { - private double trueCircle; + private boolean trueCircle; @Override public void loadProperties() { } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.cylinder.info")); + } + + @CommandMethod("") + public void onBrushTruecircle( + final @NotNull Snipe snipe, + final @Argument("true-circle") @Liberal boolean trueCircle + ) { + this.trueCircle = trueCircle; + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )); + } + + @CommandMethod("h ") + public void onBrushH( + final @NotNull Snipe snipe, + final @Argument("height") int height + ) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); - String firstParameter = parameters[0]; + toolkitProperties.setVoxelHeight(height); - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.cylindern.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("true")) { - this.trueCircle = 0.5; - messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(true))); - } else if (firstParameter.equalsIgnoreCase("false")) { - this.trueCircle = 0; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.parameter.true-circle", - VoxelSniperText.getStatus(false) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("h")) { - Integer height = NumericParser.parseInteger(parameters[1]); - if (height != null) { - toolkitProperties.setVoxelHeight(height); - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.cylinder.set-voxel-height", - toolkitProperties.getVoxelHeight() - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("c")) { - Integer center = NumericParser.parseInteger(parameters[1]); - if (center != null) { - toolkitProperties.setCylinderCenter(center); - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.cylinder.set-origin", - toolkitProperties.getCylinderCenter() - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.cylinder.set-voxel-height", + toolkitProperties.getVoxelHeight() + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("h", "c", "true", "false"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("c
") + public void onBrushC( + final @NotNull Snipe snipe, + final @Argument("center") int center + ) { + ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); + toolkitProperties.setCylinderCenter(center); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.cylinder.set-origin", + toolkitProperties.getCylinderCenter() + )); } @Override @@ -128,7 +128,7 @@ private void cylinder(Snipe snipe, BlockVector3 targetBlock) { } int blockX = targetBlock.getX(); int blockZ = targetBlock.getZ(); - double bSquared = Math.pow(brushSize + this.trueCircle, 2); + double bSquared = Math.pow(brushSize + (this.trueCircle ? 0.5 : 0), 2); for (int y = yEndPoint; y >= yStartingPoint; y--) { for (int x = brushSize; x >= 0; x--) { double xSquared = Math.pow(x, 2); @@ -175,7 +175,10 @@ public void sendInfo(Snipe snipe) { .brushSizeMessage() .voxelHeightMessage() .cylinderCenterMessage() - .message(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(this.trueCircle == 0.5))) + .message(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/EllipseBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/EllipseBrush.java index 666b9eee..5d4ccb42 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/EllipseBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/EllipseBrush.java @@ -1,17 +1,22 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b ellipse|el") +@CommandPermission("voxelsniper.brush.ellipse") public class EllipseBrush extends AbstractPerformerBrush { private static final double TWO_PI = (2 * Math.PI); @@ -48,74 +53,73 @@ public void loadProperties() { this.steps = getIntegerProperty("default-steps", DEFAULT_STEPS); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.ellipse.info")); + } + + @CommandMethod("fill") + public void onBrushFill( + final @NotNull Snipe snipe + ) { + this.fill = !this.fill; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.ellipse.set-fill-mode", + VoxelSniperText.getStatus(this.fill) + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.ellipse.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("fill")) { - if (this.fill) { - this.fill = false; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.ellipse.set-fill-mode", - VoxelSniperText.getStatus(false) - )); - } else { - this.fill = true; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.ellipse.set-fill-mode", - VoxelSniperText.getStatus(true) - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("x")) { - Integer xscl = NumericParser.parseInteger(parameters[1]); - if (xscl != null && xscl >= this.sclMin && xscl <= this.sclMax) { - this.xscl = xscl; - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.ellipse.set-x-scale", this.xscl)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("y")) { - Integer yscl = NumericParser.parseInteger(parameters[1]); - if (yscl != null && yscl >= this.sclMin && yscl <= this.sclMax) { - this.yscl = yscl; - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.ellipse.set-y-scale", this.yscl)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("t")) { - Integer steps = NumericParser.parseInteger(parameters[1]); - if (steps != null && steps >= this.stepsMin && steps <= this.stepsMax) { - this.steps = steps; - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.ellipse.set-steps", this.steps)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } + @CommandMethod("x ") + public void onBrushX( + final @NotNull Snipe snipe, + final @Argument("x-scl") @DynamicRange(min = "sclMin", max = "sclMax") int xscl + ) { + this.xscl = xscl; - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.ellipse.set-x-scale", + this.xscl + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("fill", "x", "y", "t"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("y ") + public void onBrushY( + final @NotNull Snipe snipe, + final @Argument("y-scl") @DynamicRange(min = "sclMin", max = "sclMax") int yscl + ) { + this.yscl = yscl; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.ellipse.set-y-scale", + this.yscl + )); + } + + @CommandMethod("t ") + public void onBrushT( + final @NotNull Snipe snipe, + final @Argument("steps") @DynamicRange(min = "stepsMin", max = "stepsMax") int steps + ) { + this.steps = steps; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.ellipse.set-steps", + this.steps + )); } @Override @@ -180,9 +184,9 @@ private void ellipse(Snipe snipe, BlockVector3 targetBlock) { break; } } - } catch (RuntimeException exception) { + } catch (RuntimeException e) { SnipeMessenger messenger = snipe.createMessenger(); - messenger.sendMessage(Caption.of("voxelsniper.command.invalid-block")); + messenger.sendMessage(Caption.of("voxelsniper.command.invalid-target-block")); } } @@ -276,9 +280,9 @@ private void ellipseFill(Snipe snipe, BlockVector3 targetBlock) { iy--; } } - } catch (RuntimeException exception) { + } catch (RuntimeException e) { SnipeMessenger messenger = snipe.createMessenger(); - messenger.sendMessage(Caption.of("voxelsniper.command.invalid-block")); + messenger.sendMessage(Caption.of("voxelsniper.command.invalid-target-block")); } } @@ -299,9 +303,18 @@ public void sendInfo(Snipe snipe) { "voxelsniper.performer-brush.ellipse.set-fill-mode", VoxelSniperText.getStatus(fill) )) - .message(Caption.of("voxelsniper.performer-brush.ellipse.set-x-scale", this.xscl)) - .message(Caption.of("voxelsniper.performer-brush.ellipse.set-y-scale", this.yscl)) - .message(Caption.of("voxelsniper.performer-brush.ellipse.set-steps", this.steps)) + .message(Caption.of( + "voxelsniper.performer-brush.ellipse.set-x-scale", + this.xscl + )) + .message(Caption.of( + "voxelsniper.performer-brush.ellipse.set-y-scale", + this.yscl + )) + .message(Caption.of( + "voxelsniper.performer-brush.ellipse.set-steps", + this.steps + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/EllipsoidBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/EllipsoidBrush.java index 2c60645f..4d64313b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/EllipsoidBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/EllipsoidBrush.java @@ -1,15 +1,20 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b ellipsoid|elo") +@CommandPermission("voxelsniper.brush.ellipsoid") public class EllipsoidBrush extends AbstractPerformerBrush { private static final int DEFAULT_X_RAD = 0; @@ -22,71 +27,74 @@ public class EllipsoidBrush extends AbstractPerformerBrush { private double yRad = DEFAULT_Y_RAD; private double zRad = DEFAULT_Z_RAD; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.ellipsoid.info")); + } + + @CommandMethod("") + public void onBrushOffset( + final @NotNull Snipe snipe, + final @Argument("offset") @Liberal boolean offset + ) { + this.offset = offset; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.ellipsoid.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("true")) { - this.offset = true; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.ellipsoid.set-offset", - VoxelSniperText.getStatus(true) - )); - } else if (firstParameter.equalsIgnoreCase("false")) { - this.offset = false; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.ellipsoid.set-offset", - VoxelSniperText.getStatus(false) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("x")) { - Integer xRad = NumericParser.parseInteger(parameters[1]); - if (xRad != null) { - this.xRad = xRad; - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.ellipsoid.set-x-radius", this.xRad)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("y")) { - Integer yRad = NumericParser.parseInteger(parameters[1]); - if (yRad != null) { - this.yRad = yRad; - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.ellipsoid.set-y-radius", this.yRad)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("z")) { - Integer zRad = NumericParser.parseInteger(parameters[1]); - if (zRad != null) { - this.zRad = zRad; - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.ellipsoid.set-z-radius", this.zRad)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.ellipsoid.set-offset", + VoxelSniperText.getStatus(this.offset) + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("true", "false", "x", "y", "z"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("x ") + public void onBrushX( + final @NotNull Snipe snipe, + final @Argument("x-rad") int xRad + ) { + this.xRad = xRad; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.ellipsoid.set-x-radius", + this.xRad + )); + } + + @CommandMethod("y ") + public void onBrushY( + final @NotNull Snipe snipe, + final @Argument("y-rad") int yRad + ) { + this.yRad = yRad; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.ellipsoid.set-y-radius", + this.yRad + )); + } + + @CommandMethod("z ") + public void onBrushZ( + final @NotNull Snipe snipe, + final @Argument("z-rad") int zRad + ) { + this.zRad = zRad; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.ellipsoid.set-z-radius", + this.zRad + )); } @Override @@ -184,9 +192,18 @@ public void sendInfo(Snipe snipe) { "voxelsniper.performer-brush.ellipsoid.set-offset", VoxelSniperText.getStatus(offset) )) - .message(Caption.of("voxelsniper.performer-brush.ellipsoid.set-x-radius", this.xRad)) - .message(Caption.of("voxelsniper.performer-brush.ellipsoid.set-y-radius", this.yRad)) - .message(Caption.of("voxelsniper.performer-brush.ellipsoid.set-z-radius", this.zRad)) + .message(Caption.of( + "voxelsniper.performer-brush.ellipsoid.set-x-radius", + this.xRad + )) + .message(Caption.of( + "voxelsniper.performer-brush.ellipsoid.set-y-radius", + this.yRad + )) + .message(Caption.of( + "voxelsniper.performer-brush.ellipsoid.set-z-radius", + this.zRad + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/FillDownBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/FillDownBrush.java index 4fc53e52..4fe70a2b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/FillDownBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/FillDownBrush.java @@ -1,22 +1,27 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.Materials; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b fill_down|filldown|fd") +@CommandPermission("voxelsniper.brush.filldown") public class FillDownBrush extends AbstractPerformerBrush { - private double trueCircle; + private boolean trueCircle; private boolean fillLiquid = true; private boolean fromExisting; private int minY; @@ -28,79 +33,99 @@ public void loadProperties() { } } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of( + "voxelsniper.performer-brush.fill-down.info", + this.getEditSession().getMinY() + )); + } + + @CommandMethod("") + public void onBrushTruecircle( + final @NotNull Snipe snipe, + final @Argument("true-circle") @Liberal boolean trueCircle + ) { + this.trueCircle = trueCircle; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )); + } + + @CommandMethod("all") + public void onBrushAll( + final @NotNull Snipe snipe + ) { + this.fillLiquid = true; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.fill-down.set-fill-all", + VoxelSniperText.getStatus(true) + )); + } + + @CommandMethod("some") + public void onBrushSome( + final @NotNull Snipe snipe + ) { + ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); + this.fillLiquid = false; + toolkitProperties.resetReplacePattern(); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.fill-down.set-fill-some", + VoxelSniperText.getStatus(true) + )); + } + + @CommandMethod("e") + public void onBrushE( + final @NotNull Snipe snipe + ) { + this.fromExisting = !this.fromExisting; - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.fill-down.info", getEditSession().getMinY())); + SnipeMessenger messenger = snipe.createMessenger(); + if (this.fromExisting) { + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.fill-down.set-fill-down-existing", + VoxelSniperText.getStatus(true) + )); } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("true")) { - this.trueCircle = 0.5; - messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(true))); - } else if (firstParameter.equalsIgnoreCase("false")) { - this.trueCircle = 0; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.parameter.true-circle", - VoxelSniperText.getStatus(false) - )); - } else if (firstParameter.equalsIgnoreCase("all")) { - this.fillLiquid = true; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.fill-down.set-fill-all", - VoxelSniperText.getStatus(true) - )); - } else if (firstParameter.equalsIgnoreCase("some")) { - this.fillLiquid = false; - ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); - toolkitProperties.resetReplacePattern(); - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.fill-down.set-fill-some", - VoxelSniperText.getStatus(true) - )); - } else if (firstParameter.equalsIgnoreCase("e")) { - this.fromExisting = !this.fromExisting; - if (this.fromExisting) { - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.fill-down.set-fill-down-existing", - VoxelSniperText.getStatus(true) - )); - } else { - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.fill-down.set-fill-down-all", - VoxelSniperText.getStatus(true) - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("y")) { - Integer minY = NumericParser.parseInteger(parameters[1]); - if (minY != null) { - int minYMin = getEditSession().getMinY(); - int minYMax = getEditSession().getMaxY(); - this.minY = minY < minYMin ? minYMin : Math.min(minY, minYMax); - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.fill-down.set-min-y", this.minY)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.fill-down.set-fill-down-all", + VoxelSniperText.getStatus(true) + )); } } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("true", "false", "some", "all", "e"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("y ") + public void onBrushY( + final @NotNull Snipe snipe, + final @Argument("min-y") int minY + ) { + int minYMin = this.getEditSession().getMinY(); + int minYMax = this.getEditSession().getMaxY(); + this.minY = minY < minYMin ? minYMin : Math.min(minY, minYMax); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.fill-down.set-min-y", + this.minY + )); } @Override @@ -116,7 +141,7 @@ public void handleGunpowderAction(Snipe snipe) { private void fillDown(Snipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); int brushSize = toolkitProperties.getBrushSize(); - double brushSizeSquared = Math.pow(brushSize + this.trueCircle, 2); + double brushSizeSquared = Math.pow(brushSize + (this.trueCircle ? 0.5 : 0), 2); BlockVector3 targetBlock = this.getTargetBlock(); for (int x = -brushSize; x <= brushSize; x++) { double currentXSquared = Math.pow(x, 2); @@ -170,8 +195,14 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .brushSizeMessage() - .message(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(this.trueCircle == 0.5))) - .message(Caption.of("voxelsniper.performer-brush.fill-down.set-fill-all", VoxelSniperText.getStatus(fillLiquid))) + .message(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )) + .message(Caption.of( + "voxelsniper.performer-brush.fill-down.set-fill-all", + VoxelSniperText.getStatus(fillLiquid) + )) .message(Caption.of( "voxelsniper.performer-brush.fill-down.set-fill-some", VoxelSniperText.getStatus(!fillLiquid) @@ -184,7 +215,10 @@ public void sendInfo(Snipe snipe) { "voxelsniper.performer-brush.fill-down.set-fill-down-all", VoxelSniperText.getStatus(!fromExisting) )) - .message(Caption.of("voxelsniper.performer-brush.fill-down.set-min-y", this.minY)) + .message(Caption.of( + "voxelsniper.performer-brush.fill-down.set-min-y", + this.minY + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/JaggedLineBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/JaggedLineBrush.java index 61908b20..b16a3fa5 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/JaggedLineBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/JaggedLineBrush.java @@ -1,22 +1,29 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.Vectors; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.util.BlockIterator; import org.bukkit.util.NumberConversions; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; -import java.util.List; import java.util.Random; -import java.util.stream.Stream; +@RequireToolkit +@CommandMethod(value = "brush|b jagged_line|jaggedline|jagged|j") +@CommandPermission("voxelsniper.brush.jaggedline") public class JaggedLineBrush extends AbstractPerformerBrush { private static final Vector HALF_BLOCK_OFFSET = new Vector(0.5, 0.5, 0.5); @@ -46,61 +53,52 @@ public void loadProperties() { this.spread = getIntegerProperty("default-spread", DEFAULT_SPREAD); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of( + "voxelsniper.performer-brush.jagged-line.info", + this.getIntegerProperty("default-recursion", DEFAULT_RECURSION), + this.recursionMin, + this.recursionMax, + this.getIntegerProperty("default-spread", DEFAULT_SPREAD) + )); + } + + @CommandMethod("r ") + public void onBrushR( + final @NotNull Snipe snipe, + final @Argument("recursions") @DynamicRange(min = "recursionMin", max = "recursionMax") int recursions + ) { + this.recursions = recursions; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.jagged-line.info", - getIntegerProperty("default-recursion", DEFAULT_RECURSION), - this.recursionMin, - this.recursionMax, - getIntegerProperty("default-spread", DEFAULT_SPREAD) - )); - } else { - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("r")) { - Integer recursions = NumericParser.parseInteger(parameters[1]); - if (recursions != null && recursions >= this.recursionMin && recursions <= this.recursionMax) { - this.recursions = recursions; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.jagged-line.set-recursions", - this.recursions - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - recursionMin, recursionMax - )); - } - } else if (firstParameter.equalsIgnoreCase("s")) { - Integer spread = NumericParser.parseInteger(parameters[1]); - if (spread != null) { - this.spread = spread; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.jagged-line.set-spread", - this.spread - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.jagged-line.set-recursions", + this.recursions + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("r", "s"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("s ") + public void onBrushS( + final @NotNull Snipe snipe, + final @Argument("spread") @Range(min = "0") int spread + ) { + this.spread = spread; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.jagged-line.set-spread", + this.spread + )); } @Override @@ -151,9 +149,9 @@ private void jaggedP() { while (iterator.hasNext()) { Block block = iterator.next(); for (int i = 0; i < this.recursions; i++) { - int x = Math.round(block.getX() + this.random.nextInt(this.spread * 2) - this.spread); - int y = Math.round(block.getY() + this.random.nextInt(this.spread * 2) - this.spread); - int z = Math.round(block.getZ() + this.random.nextInt(this.spread * 2) - this.spread); + int x = block.getX() + this.random.nextInt(this.spread * 2) - this.spread; + int y = block.getY() + this.random.nextInt(this.spread * 2) - this.spread; + int z = block.getZ() + this.random.nextInt(this.spread * 2) - this.spread; this.performer.perform(getEditSession(), x, clampY(y), z, clampY(x, y, z)); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/LineBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/LineBrush.java index 26629050..79ed58d5 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/LineBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/LineBrush.java @@ -1,9 +1,12 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.util.TaskManager; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.Vectors; @@ -12,7 +15,11 @@ import org.bukkit.util.BlockIterator; import org.bukkit.util.NumberConversions; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b line|l") +@CommandPermission("voxelsniper.brush.line") public class LineBrush extends AbstractPerformerBrush { private static final Vector HALF_BLOCK_OFFSET = new Vector(0.5, 0.5, 0.5); @@ -25,14 +32,18 @@ public class LineBrush extends AbstractPerformerBrush { public void loadProperties() { } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.line.info")); - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.line.info")); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/OverlayBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/OverlayBrush.java index 76001ec6..4f41ecbf 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/OverlayBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/OverlayBrush.java @@ -1,21 +1,26 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.MaterialSets; import com.thevoxelbox.voxelsniper.util.material.Materials; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b overlay|over") +@CommandPermission("overlay") public class OverlayBrush extends AbstractPerformerBrush { private static final int DEFAULT_DEPTH = 3; @@ -29,55 +34,58 @@ public void loadProperties() { this.depth = getIntegerProperty("default-depth", DEFAULT_DEPTH); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.overlay.info")); + } + + @CommandMethod("all") + public void onBrushAll( + final @NotNull Snipe snipe + ) { + this.allBlocks = true; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.overlay.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("all")) { - this.allBlocks = true; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.overlay.set-overlay-all", - VoxelSniperText.getStatus(true) - )); - } else if (firstParameter.equalsIgnoreCase("some")) { - this.allBlocks = false; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.overlay.set-overlay-natural", - VoxelSniperText.getStatus(true) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("d")) { - Integer depth = NumericParser.parseInteger(parameters[1]); - if (depth != null) { - this.depth = depth < 1 ? 1 : depth; - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.overlay.set-depth", this.depth)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.overlay.set-overlay-all", + VoxelSniperText.getStatus(true) + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("all", "some", "d"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("some") + public void onBrushSome( + final @NotNull Snipe snipe + ) { + this.allBlocks = false; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.overlay.set-overlay-natural", + VoxelSniperText.getStatus(true) + )); + } + + @CommandMethod("d ") + public void onBrushD( + final @NotNull Snipe snipe, + final @Argument("depth") @Range(min = "1") int depth + ) { + this.depth = depth; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.overlay.set-depth", + this.depth + )); } @Override @@ -228,7 +236,10 @@ public void sendInfo(Snipe snipe) { "voxelsniper.performer-brush.overlay.set-overlay-natural", VoxelSniperText.getStatus(!this.allBlocks) )) - .message(Caption.of("voxelsniper.performer-brush.overlay.set-depth", this.depth)) + .message(Caption.of( + "voxelsniper.performer-brush.overlay.set-depth", + this.depth + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/PunishBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/PunishBrush.java index e0450166..41863b4c 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/PunishBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/PunishBrush.java @@ -1,10 +1,14 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.util.TaskManager; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.Sniper; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; @@ -15,19 +19,21 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.entity.HumanEntity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.Random; -import java.util.stream.Stream; +@RequireToolkit +@CommandMethod(value = "brush|b punish|p") +@CommandPermission("voxelsniper.brush.punish") public class PunishBrush extends AbstractPerformerBrush { private static final int TICKS_PER_SECOND = 20; @@ -43,7 +49,6 @@ public class PunishBrush extends AbstractPerformerBrush { .map(punishment -> punishment.name().toLowerCase(Locale.ROOT)) .toList(); - private boolean specificPlayer; private String punishPlayerName = ""; private boolean hypnoAffectLandscape; @@ -66,91 +71,88 @@ public void loadProperties() { this.punishDuration = getIntegerProperty("default-punish-duration", DEFAULT_PUNISH_DURATION); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.punish.info")); + } + + @CommandMethod("list") + public void onBrushList( + final @NotNull Snipe snipe + ) { SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(VoxelSniperText.formatListWithCurrent( + Arrays.asList(Punishment.values()), + (punishment, punishment2) -> punishment.getName().compareTo(punishment2.getName()), + Punishment::getFullName, + punishment -> punishment, + this.punishment, + "voxelsniper.performer-brush.punish" + )); + } + + @CommandMethod("toggleSelf") + public void onBrushToggleself( + final @NotNull Snipe snipe + ) { + this.hitsSelf = !this.hitsSelf; - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.punish.info")); + SnipeMessenger messenger = snipe.createMessenger(); + if (this.hitsSelf) { + messenger.sendMessage(Caption.of("voxelsniper.performer-brush.punish.hit-self")); } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("list")) { - messenger.sendMessage(VoxelSniperText.formatListWithCurrent( - Arrays.stream(Punishment.values()).toList(), - (punishment, punishment2) -> punishment.getName().compareTo(punishment2.getName()), - Punishment::getFullName, - punishment -> punishment, - this.punishment, - "voxelsniper.performer-brush.punish" - )); - } else if (firstParameter.equalsIgnoreCase("toggleSelf")) { - this.hitsSelf = !this.hitsSelf; - if (this.hitsSelf) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.punish.hit-self")); - } else { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.punish.hit-other")); - } - } else if (firstParameter.equalsIgnoreCase("toggleHypnoLandscape")) { - this.hypnoAffectLandscape = !this.hypnoAffectLandscape; - } else { - try { - this.punishment = Punishment.valueOf(firstParameter.toUpperCase(Locale.ROOT)); - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.punish.set-punishment", - this.punishment.getFullName() - )); - } catch (IllegalArgumentException exception) { - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.punish.invalid-punishment", - firstParameter - )); - } - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("toggleSM")) { - String punishPlayerName = parameters[1]; - if (Bukkit.getPlayer(punishPlayerName) != null) { - this.specificPlayer = !this.specificPlayer; - if (this.specificPlayer) { - this.punishPlayerName = punishPlayerName; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.punish.hit-player", - this.punishPlayerName - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.punish.invalid-player", punishPlayerName)); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } + messenger.sendMessage(Caption.of("voxelsniper.performer-brush.punish.hit-other")); } } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.concat( - PUNISHMENTS.stream(), - Stream.of("list", "toggleSM", "toggleSelf", "toggleHypnoLandscape") - ), parameter, 0); - } - if (parameters.length == 2) { - String firstParameter = parameters[0]; - if (firstParameter.equalsIgnoreCase("toggleSM")) { - String parameter = parameters[1]; - Player sniper = snipe.getSniper().getPlayer(); - return super.sortCompletions(Bukkit.getOnlinePlayers().stream() - .filter(sniper::canSee) - .map(HumanEntity::getName), parameter, 1); - } - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("toggleHypnoLandscape") + public void onBrushToggleHypnoLandscape( + final @NotNull Snipe snipe + ) { + this.hypnoAffectLandscape = !this.hypnoAffectLandscape; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.punish.hypno-affect-landscape", + this.hypnoAffectLandscape + )); + } + + @CommandMethod("") + public void onBrushPunishment( + final @NotNull Snipe snipe, + final @NotNull @Argument("punishment") Punishment punishment + ) { + this.punishment = punishment; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.punish.set-punishment", + this.punishment.getFullName() + )); + } + + @CommandMethod("toggleSM ") + public void onBrushTogglesm( + final @NotNull Snipe snipe, + final @NotNull @Argument("player") Player player + ) { + this.punishPlayerName = player.getName(); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.punish.hit-player", + this.punishPlayerName + )); } @Override @@ -159,17 +161,16 @@ public void handleArrowAction(Snipe snipe) { SnipeMessenger messenger = snipe.createMessenger(); Sniper sniper = snipe.getSniper(); Player player = sniper.getPlayer(); - if (!player.hasPermission("voxelsniper.punish")) { - messenger.sendMessage(Caption.of("voxelsniper.command.missing-permission", "voxelsniper.punish")); - return; - } this.punishDuration = toolkitProperties.getVoxelHeight(); this.punishLevel = toolkitProperties.getCylinderCenter(); if (this.specificPlayer) { TaskManager.taskManager().sync(() -> { Player punishedPlayer = Bukkit.getPlayer(this.punishPlayerName); if (punishedPlayer == null) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.punish.invalid-player", this.punishPlayerName)); + messenger.sendMessage(Caption.of( + "voxelsniper.command.invalid-player", + this.punishPlayerName + )); return null; } applyPunishment(punishedPlayer, snipe); @@ -194,8 +195,8 @@ public void handleArrowAction(Snipe snipe) { numPunishApps++; applyPunishment(entity, snipe); } - } catch (RuntimeException exception) { - exception.printStackTrace(); + } catch (RuntimeException e) { + e.printStackTrace(); messenger.sendMessage(Caption.of("voxelsniper.error.unexpected")); return null; } @@ -216,10 +217,6 @@ public void handleGunpowderAction(Snipe snipe) { SnipeMessenger messenger = snipe.createMessenger(); Sniper sniper = snipe.getSniper(); Player player = sniper.getPlayer(); - if (!player.hasPermission("voxelsniper.punish")) { - messenger.sendMessage(Caption.of("voxelsniper.command.missing-permission", "voxelsniper.punish")); - return; - } int brushSize = toolkitProperties.getBrushSize(); int brushSizeSquare = brushSize * brushSize; World world = BukkitAdapter.adapt(getEditSession().getWorld()); @@ -241,96 +238,46 @@ public void handleGunpowderAction(Snipe snipe) { private void applyPunishment(LivingEntity entity, Snipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); switch (this.punishment) { - case FIRE: - entity.setFireTicks(TICKS_PER_SECOND * this.punishDuration); - break; - case LIGHTNING: - entity.getWorld() - .strikeLightning(entity.getLocation()); - break; - case BLINDNESS: - addEffect(entity, PotionEffectType.BLINDNESS); - break; - case DRUNK: - addEffect(entity, PotionEffectType.CONFUSION); - break; - case SLOW: - addEffect(entity, PotionEffectType.SLOW); - break; - case JUMP: - addEffect(entity, PotionEffectType.JUMP); - break; - case ABSORPTION: - addEffect(entity, PotionEffectType.ABSORPTION); - break; - case DAMAGE_RESISTANCE: - addEffect(entity, PotionEffectType.DAMAGE_RESISTANCE); - break; - case FAST_DIGGING: - addEffect(entity, PotionEffectType.FAST_DIGGING); - break; - case FIRE_RESISTANCE: - addEffect(entity, PotionEffectType.FIRE_RESISTANCE); - break; - case HEAL: - addEffect(entity, PotionEffectType.HEAL); - break; - case HEALTH_BOOST: - addEffect(entity, PotionEffectType.HEALTH_BOOST); - break; - case HUNGER: - addEffect(entity, PotionEffectType.HUNGER); - break; - case INCREASE_DAMAGE: - addEffect(entity, PotionEffectType.INCREASE_DAMAGE); - break; - case INVISIBILITY: - addEffect(entity, PotionEffectType.INVISIBILITY); - break; - case NIGHT_VISION: - addEffect(entity, PotionEffectType.NIGHT_VISION); - break; - case POISON: - addEffect(entity, PotionEffectType.POISON); - break; - case REGENERATION: - addEffect(entity, PotionEffectType.REGENERATION); - break; - case SATURATION: - addEffect(entity, PotionEffectType.SATURATION); - break; - case SLOW_DIGGING: - addEffect(entity, PotionEffectType.SLOW_DIGGING); - break; - case SPEED: - addEffect(entity, PotionEffectType.SPEED); - break; - case WATER_BREATHING: - addEffect(entity, PotionEffectType.WATER_BREATHING); - break; - case WEAKNESS: - addEffect(entity, PotionEffectType.WEAKNESS); - break; - case WITHER: - addEffect(entity, PotionEffectType.WITHER); - break; - case KILL: - entity.setHealth(0.0d); - break; - case RANDOMTP: + case FIRE -> entity.setFireTicks(TICKS_PER_SECOND * this.punishDuration); + case LIGHTNING -> entity.getWorld() + .strikeLightning(entity.getLocation()); + case BLINDNESS -> addEffect(entity, PotionEffectType.BLINDNESS); + case DRUNK -> addEffect(entity, PotionEffectType.CONFUSION); + case SLOW -> addEffect(entity, PotionEffectType.SLOW); + case JUMP -> addEffect(entity, PotionEffectType.JUMP); + case ABSORPTION -> addEffect(entity, PotionEffectType.ABSORPTION); + case DAMAGE_RESISTANCE -> addEffect(entity, PotionEffectType.DAMAGE_RESISTANCE); + case FAST_DIGGING -> addEffect(entity, PotionEffectType.FAST_DIGGING); + case FIRE_RESISTANCE -> addEffect(entity, PotionEffectType.FIRE_RESISTANCE); + case HEAL -> addEffect(entity, PotionEffectType.HEAL); + case HEALTH_BOOST -> addEffect(entity, PotionEffectType.HEALTH_BOOST); + case HUNGER -> addEffect(entity, PotionEffectType.HUNGER); + case INCREASE_DAMAGE -> addEffect(entity, PotionEffectType.INCREASE_DAMAGE); + case INVISIBILITY -> addEffect(entity, PotionEffectType.INVISIBILITY); + case NIGHT_VISION -> addEffect(entity, PotionEffectType.NIGHT_VISION); + case POISON -> addEffect(entity, PotionEffectType.POISON); + case REGENERATION -> addEffect(entity, PotionEffectType.REGENERATION); + case SATURATION -> addEffect(entity, PotionEffectType.SATURATION); + case SLOW_DIGGING -> addEffect(entity, PotionEffectType.SLOW_DIGGING); + case SPEED -> addEffect(entity, PotionEffectType.SPEED); + case WATER_BREATHING -> addEffect(entity, PotionEffectType.WATER_BREATHING); + case WEAKNESS -> addEffect(entity, PotionEffectType.WEAKNESS); + case WITHER -> addEffect(entity, PotionEffectType.WITHER); + case KILL -> entity.setHealth(0.0d); + case RANDOMTP -> { Random random = new Random(); Location targetLocation = entity.getLocation(); targetLocation.setX(targetLocation.getX() + (random.nextInt(this.maxRandomTeleportationRange) - this.maxRandomTeleportationRange / 2.0)); targetLocation.setZ(targetLocation.getZ() + (random.nextInt(this.maxRandomTeleportationRange) - this.maxRandomTeleportationRange / 2.0)); entity.teleport(targetLocation); - break; - case ALL_POTION: + } + case ALL_POTION -> { addEffect(entity, PotionEffectType.BLINDNESS); addEffect(entity, PotionEffectType.CONFUSION); addEffect(entity, PotionEffectType.SLOW); addEffect(entity, PotionEffectType.JUMP); - break; - case FORCE: + } + case FORCE -> { Vector playerVector = Vectors.toBukkit(getTargetBlock()); Vector direction = entity.getLocation().toVector().clone(); direction.subtract(playerVector); @@ -339,8 +286,8 @@ private void applyPunishment(LivingEntity entity, Snipe snipe) { direction.normalize(); direction.multiply(strength); entity.setVelocity(direction); - break; - case HYPNO: + } + case HYPNO -> { if (entity instanceof Player) { Location location = entity.getLocation(); Location target = location.clone(); @@ -365,9 +312,8 @@ private void applyPunishment(LivingEntity entity, Snipe snipe) { } } } - break; - default: - throw new IllegalStateException("Unexpected value: " + this.punishment); + } + default -> throw new IllegalStateException("Unexpected value: " + this.punishment); } } @@ -389,7 +335,7 @@ public void sendInfo(Snipe snipe) { .send(); } - private enum Punishment { + public enum Punishment { FIRE("fire"), LIGHTNING("lightning"), BLINDNESS("blindness"), diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/RingBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/RingBrush.java index e277e7d9..e2cbb853 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/RingBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/RingBrush.java @@ -1,70 +1,69 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b ring|ri") +@CommandPermission("voxelsniper.brush.ring") public class RingBrush extends AbstractPerformerBrush { private static final double DEFAULT_INNER_SIZE = 0.0; - private double trueCircle; + private boolean trueCircle; private double innerSize = DEFAULT_INNER_SIZE; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.ring.info")); + } + + @CommandMethod("") + public void onBrushTruecircle( + final @NotNull Snipe snipe, + final @Argument("true-circle") @Liberal boolean trueCircle + ) { + this.trueCircle = trueCircle; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.ring.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("true")) { - this.trueCircle = 0.5; - messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(true))); - } else if (firstParameter.equalsIgnoreCase("false")) { - this.trueCircle = 0; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.parameter.true-circle", - VoxelSniperText.getStatus(false) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("ir")) { - Double innerSize = NumericParser.parseDouble(parameters[1]); - if (innerSize != null) { - this.innerSize = innerSize; - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.ring.set-inner-radius", this.innerSize)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("true", "false", "ir"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("ir ") + public void onBrushIr( + final @NotNull Snipe snipe, + final @Argument("inner-size") double innerSize + ) { + this.innerSize = innerSize; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.ring.set-inner-radius", + this.innerSize + )); } @Override @@ -82,7 +81,7 @@ public void handleGunpowderAction(Snipe snipe) { private void ring(Snipe snipe, BlockVector3 targetBlock) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); int brushSize = toolkitProperties.getBrushSize(); - double outerSquared = Math.pow(brushSize + this.trueCircle, 2); + double outerSquared = Math.pow(brushSize + (this.trueCircle ? 0.5 : 0), 2); double innerSquared = Math.pow(this.innerSize, 2); int blockX = targetBlock.getX(); int blockY = targetBlock.getY(); @@ -130,8 +129,14 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .brushSizeMessage() - .message(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(this.trueCircle == 0.5))) - .message(Caption.of("voxelsniper.performer-brush.ring.set-inner-radius", this.innerSize)) + .message(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )) + .message(Caption.of( + "voxelsniper.performer-brush.ring.set-inner-radius", + this.innerSize + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SetBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SetBrush.java index 13e5cdf9..5b7bf3bf 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SetBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SetBrush.java @@ -1,12 +1,19 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +@RequireToolkit +@CommandMethod(value = "brush|b set") +@CommandPermission("voxelsniper.brush.set") public class SetBrush extends AbstractPerformerBrush { private static final int SELECTION_SIZE_MAX = 5000000; @@ -22,6 +29,13 @@ public void loadProperties() { this.selectionSizeMax = getIntegerProperty("selection-size-max", SELECTION_SIZE_MAX); } + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { BlockVector3 targetBlock = getTargetBlock(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SnipeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SnipeBrush.java index 0595ef26..d9af3352 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SnipeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SnipeBrush.java @@ -1,14 +1,28 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b snipe|s") +@CommandPermission("voxelsniper.brush.snipe") public class SnipeBrush extends AbstractPerformerBrush { @Override public void loadProperties() { } + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { BlockVector3 targetBlock = getTargetBlock(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SplineBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SplineBrush.java index 7494ce95..bb193198 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SplineBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/SplineBrush.java @@ -1,19 +1,25 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; -import java.util.stream.Stream; /** * FOR ANY BRUSH THAT USES A SPLINE, EXTEND THAT BRUSH FROM THIS BRUSH!!! That way, the spline calculations are already there. Also, the UI for * the splines will be included. */ +@RequireToolkit +@CommandMethod(value = "brush|b spline|sp") +@CommandPermission("voxelsniper.brush.ellipsoid") public class SplineBrush extends AbstractPerformerBrush { private final List endPts = new ArrayList<>(); @@ -26,77 +32,77 @@ public class SplineBrush extends AbstractPerformerBrush { public void loadProperties() { } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.spline.info")); + } + + @CommandMethod("ss") + public void onBrushSs( + final @NotNull Snipe snipe + ) { + this.set = !this.set; + if (this.set) { + this.ctrl = false; + } + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.spline.set-endpoint", + VoxelSniperText.getStatus(this.set) + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.spline.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("ss")) { - if (this.set) { - this.set = false; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.spline.set-endpoint", - VoxelSniperText.getStatus(false) - )); - } else { - this.set = true; - this.ctrl = false; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.spline.set-endpoint", - VoxelSniperText.getStatus(true) - )); - } - } else if (firstParameter.equalsIgnoreCase("sc")) { - if (this.ctrl) { - this.ctrl = false; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.spline.set-control-point", - VoxelSniperText.getStatus(false) - )); - } else { - this.set = false; - this.ctrl = true; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.spline.set-control-point", - VoxelSniperText.getStatus(true) - )); - } - } else if (firstParameter.equalsIgnoreCase("clear")) { - clear(snipe); - } else if (firstParameter.equalsIgnoreCase("ren")) { - if (this.endPts.size() == 2 && this.ctrlPts.size() == 2) { - if (spline( - new Point(this.endPts.get(0)), - new Point(this.endPts.get(1)), - new Point(this.ctrlPts.get(0)), - new Point(this.ctrlPts.get(1)), - snipe - )) { - render(); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.spline.missing-points")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } + @CommandMethod("sc") + public void onBrushSc( + final @NotNull Snipe snipe + ) { + this.ctrl = !this.ctrl; + if (this.ctrl) { + this.set = false; } + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.spline.set-control-point", + VoxelSniperText.getStatus(this.ctrl) + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("ss", "sc", "clear", "ren"), parameter, 0); + @CommandMethod("clear") + public void onBrushClear( + final @NotNull Snipe snipe + ) { + this.clear(snipe); + } + + @CommandMethod("ren") + public void onBrushRen( + final @NotNull Snipe snipe + ) { + if (this.endPts.size() == 2 && this.ctrlPts.size() == 2) { + if (spline( + new Point(this.endPts.get(0)), + new Point(this.endPts.get(1)), + new Point(this.ctrlPts.get(0)), + new Point(this.ctrlPts.get(1)), + snipe + )) { + render(); + } + } else { + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of("voxelsniper.performer-brush.spline.missing-points")); } - return super.handleCompletions(parameters, snipe); } @Override @@ -201,7 +207,7 @@ private boolean spline(Point start, Point end, Point c1, Point c2, Snipe snipe) } } return true; - } catch (RuntimeException exception) { + } catch (RuntimeException e) { messenger.sendMessage(Caption.of("voxelsniper.performer-brush.spline.not-enough-points", this.endPts.size(), this.ctrlPts.size() )); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/ThreePointCircleBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/ThreePointCircleBrush.java index b6860a04..1853fece 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/ThreePointCircleBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/ThreePointCircleBrush.java @@ -1,29 +1,30 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.Vectors; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; import org.bukkit.util.NumberConversions; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.stream.Stream; +@RequireToolkit +@CommandMethod(value = "brush|b three_point_circle|threepointcircle|tpc") +@CommandPermission("voxelsniper.brush.threepointcircle") public class ThreePointCircleBrush extends AbstractPerformerBrush { private static final Tolerance DEFAULT_TOLERANCE = Tolerance.DEFAULT; - private static final List TOLERANCES = Arrays.stream(Tolerance.values()) - .map(Tolerance::getName) - .toList(); - @Nullable private Vector coordinatesOne; @Nullable @@ -38,55 +39,47 @@ public void loadProperties() { this.tolerance = (Tolerance) getEnumProperty("default-tolerance", Tolerance.class, DEFAULT_TOLERANCE); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.three-point-circle.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("list")) { - messenger.sendMessage(VoxelSniperText.formatListWithCurrent( - Arrays.stream(Tolerance.values()).toList(), - (tolerance, tolerance2) -> tolerance.getName().compareTo(tolerance2.getName()), - Tolerance::getFullName, - tolerance -> tolerance, - this.tolerance, - "voxelsniper.brush.three-point-circle" - )); - } else { - try { - this.tolerance = Tolerance.valueOf(firstParameter.toUpperCase(Locale.ROOT)); - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.three-point-circle.set-tolerance", - this.tolerance.getFullName() - )); - } catch (IllegalArgumentException exception) { - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.three-point-circle.invalid-tolerance", - firstParameter - )); - } - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.three-point-circle.info")); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions( - Stream.concat( - TOLERANCES.stream(), - Stream.of("list") - ), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("list") + public void onBrushList( + final @NotNull Snipe snipe + ) { + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(VoxelSniperText.formatListWithCurrent( + Arrays.stream(Tolerance.values()).toList(), + (tolerance, tolerance2) -> tolerance.getName().compareTo(tolerance2.getName()), + Tolerance::getFullName, + tolerance -> tolerance, + this.tolerance, + "voxelsniper.brush.three-point-circle" + )); + } + + @CommandMethod("") + public void onBrushTolerance( + final @NotNull Snipe snipe, + final @NotNull @Argument("tolerance") Tolerance tolerance + ) { + this.tolerance = tolerance; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.three-point-circle.set-tolerance", + this.tolerance.getFullName() + )); } @Override @@ -214,7 +207,7 @@ public void sendInfo(Snipe snipe) { .send(); } - private enum Tolerance { + public enum Tolerance { DEFAULT("default", 1000), ACCURATE("accurate", 10), diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/TriangleBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/TriangleBrush.java index b90bd017..9565bb73 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/TriangleBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/TriangleBrush.java @@ -1,14 +1,21 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.math.MathHelper; +import org.jetbrains.annotations.NotNull; import java.util.stream.DoubleStream; import java.util.stream.IntStream; +@RequireToolkit +@CommandMethod(value = "brush|b triangle|tri") +@CommandPermission("voxelsniper.brush.triangle") public class TriangleBrush extends AbstractPerformerBrush { private final double[] coordinatesOne = new double[3]; // Three corners @@ -25,14 +32,18 @@ public class TriangleBrush extends AbstractPerformerBrush { public void loadProperties() { } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.triangle.info")); - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.triangle.info")); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/UnderlayBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/UnderlayBrush.java index df66bc07..c6b1fad4 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/UnderlayBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/UnderlayBrush.java @@ -1,19 +1,24 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.MaterialSets; import com.thevoxelbox.voxelsniper.util.material.Materials; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b underlay|under") +@CommandPermission("voxelsniper.brush.underlay") public class UnderlayBrush extends AbstractPerformerBrush { private static final int DEFAULT_DEPTH = 3; @@ -27,55 +32,58 @@ public void loadProperties() { this.depth = getIntegerProperty("default-depth", DEFAULT_DEPTH); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.performer-brush.underlay.info")); + } + + @CommandMethod("all") + public void onBrushAll( + final @NotNull Snipe snipe + ) { + this.allBlocks = true; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.underlay.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("all")) { - this.allBlocks = true; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.underlay.set-underlay-all", - VoxelSniperText.getStatus(true) - )); - } else if (firstParameter.equalsIgnoreCase("some")) { - this.allBlocks = false; - messenger.sendMessage(Caption.of( - "voxelsniper.performer-brush.underlay.set-underlay-natural", - VoxelSniperText.getStatus(true) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("d")) { - Integer depth = NumericParser.parseInteger(parameters[1]); - if (depth != null) { - this.depth = depth < 1 ? 1 : depth; - messenger.sendMessage(Caption.of("voxelsniper.performer-brush.underlay.set-depth", this.depth)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.underlay.set-underlay-all", + VoxelSniperText.getStatus(true) + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("d", "all", "some"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("some") + public void onBrushSome( + final @NotNull Snipe snipe + ) { + this.allBlocks = false; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.underlay.set-underlay-natural", + VoxelSniperText.getStatus(true) + )); + } + + @CommandMethod("d ") + public void onBrushD( + final @NotNull Snipe snipe, + final @Argument("depth") @Range(min = "1") int depth + ) { + this.depth = depth; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.performer-brush.underlay.set-depth", + this.depth + )); } @Override @@ -215,7 +223,10 @@ public void sendInfo(Snipe snipe) { "voxelsniper.performer-brush.underlay.set-underlay-natural", VoxelSniperText.getStatus(!this.allBlocks) )) - .message(Caption.of("voxelsniper.performer-brush.underlay.set-depth", this.depth)) + .message(Caption.of( + "voxelsniper.performer-brush.underlay.set-depth", + this.depth + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/VoxelBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/VoxelBrush.java index d880bea5..81dea79e 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/VoxelBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/VoxelBrush.java @@ -1,15 +1,29 @@ package com.thevoxelbox.voxelsniper.brush.type.performer; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b voxel|v") +@CommandPermission("voxelsniper.brush.voxel") public class VoxelBrush extends AbstractPerformerBrush { @Override public void loadProperties() { } + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { voxel(snipe); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/DiscBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/DiscBrush.java index bc59521b..76c51fb4 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/DiscBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/DiscBrush.java @@ -1,59 +1,57 @@ package com.thevoxelbox.voxelsniper.brush.type.performer.disc; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.math.MutableBlockVector3; import com.sk89q.worldedit.math.BlockVector3; import com.thevoxelbox.voxelsniper.brush.type.performer.AbstractPerformerBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b disc|d") +@CommandPermission("voxelsniper.brush.disc") public class DiscBrush extends AbstractPerformerBrush { - private double trueCircle; + private boolean trueCircle; @Override public void loadProperties() { } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.disc.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("true")) { - this.trueCircle = 0.5; - messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(true))); - } else if (firstParameter.equalsIgnoreCase("false")) { - this.trueCircle = 0; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.parameter.true-circle", - VoxelSniperText.getStatus(false) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.disc.info")); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("true", "false"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("") + public void onBrushTruecircle( + final @NotNull Snipe snipe, + final @Argument("true-circle") @Liberal boolean trueCircle + ) { + this.trueCircle = trueCircle; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )); } @Override @@ -71,7 +69,7 @@ public void handleGunpowderAction(Snipe snipe) { private void disc(Snipe snipe, BlockVector3 targetBlock) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); int brushSize = toolkitProperties.getBrushSize(); - double radiusSquared = (brushSize + this.trueCircle) * (brushSize + this.trueCircle); + double radiusSquared = (brushSize + (this.trueCircle ? 0.5 : 0)) * (brushSize + (this.trueCircle ? 0.5 : 0)); MutableBlockVector3 currentPoint = new MutableBlockVector3(targetBlock); for (int x = -brushSize; x <= brushSize; x++) { currentPoint.mutX(targetBlock.getX() + x); @@ -95,7 +93,10 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .brushSizeMessage() - .message(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(this.trueCircle == 0.5))) + .message(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/DiscFaceBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/DiscFaceBrush.java index 67daf2ac..359f5a13 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/DiscFaceBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/DiscFaceBrush.java @@ -1,59 +1,57 @@ package com.thevoxelbox.voxelsniper.brush.type.performer.disc; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Liberal; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.thevoxelbox.voxelsniper.brush.type.performer.AbstractPerformerBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b disc_face|discface|df") +@CommandPermission("voxelsniper.brush.discface") public class DiscFaceBrush extends AbstractPerformerBrush { - private double trueCircle; + private boolean trueCircle; @Override public void loadProperties() { } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.disc-face.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("true")) { - this.trueCircle = 0.5; - messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(true))); - } else if (firstParameter.equalsIgnoreCase("false")) { - this.trueCircle = 0; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.parameter.true-circle", - VoxelSniperText.getStatus(false) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("true", "false"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.disc-face.info")); + } + + @CommandMethod("") + public void onBrushTruecircle( + final @NotNull Snipe snipe, + final @Argument("true-circle") @Liberal boolean trueCircle + ) { + this.trueCircle = trueCircle; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )); } @Override @@ -71,7 +69,7 @@ public void handleGunpowderAction(Snipe snipe) { private void discUpDown(Snipe snipe, BlockVector3 targetBlock) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); int brushSize = toolkitProperties.getBrushSize(); - double brushSizeSquared = Math.pow(brushSize + this.trueCircle, 2); + double brushSizeSquared = Math.pow(brushSize + (this.trueCircle ? 0.5 : 0), 2); int blockX = targetBlock.getX(); int blockY = targetBlock.getY(); int blockZ = targetBlock.getZ(); @@ -115,7 +113,7 @@ private void discUpDown(Snipe snipe, BlockVector3 targetBlock) { private void discNorthSouth(Snipe snipe, BlockVector3 targetBlock) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); int brushSize = toolkitProperties.getBrushSize(); - double brushSizeSquared = Math.pow(brushSize + this.trueCircle, 2); + double brushSizeSquared = Math.pow(brushSize + (this.trueCircle ? 0.5 : 0), 2); int blockX = targetBlock.getX(); int blockY = targetBlock.getY(); int blockZ = targetBlock.getZ(); @@ -159,7 +157,7 @@ private void discNorthSouth(Snipe snipe, BlockVector3 targetBlock) { private void discEastWest(Snipe snipe, BlockVector3 targetBlock) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); int brushSize = toolkitProperties.getBrushSize(); - double brushSizeSquared = Math.pow(brushSize + this.trueCircle, 2); + double brushSizeSquared = Math.pow(brushSize + (this.trueCircle ? 0.5 : 0), 2); int blockX = targetBlock.getX(); int blockY = targetBlock.getY(); int blockZ = targetBlock.getZ(); @@ -220,7 +218,10 @@ public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() .brushSizeMessage() - .message(Caption.of("voxelsniper.brush.parameter.true-circle", VoxelSniperText.getStatus(this.trueCircle == 0.5))) + .message(Caption.of( + "voxelsniper.brush.parameter.true-circle", + VoxelSniperText.getStatus(this.trueCircle) + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/VoxelDiscBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/VoxelDiscBrush.java index 04508545..1cc4465f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/VoxelDiscBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/VoxelDiscBrush.java @@ -1,16 +1,30 @@ package com.thevoxelbox.voxelsniper.brush.type.performer.disc; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.math.BlockVector3; import com.thevoxelbox.voxelsniper.brush.type.performer.AbstractPerformerBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b voxel_disc|voxeldisc|vd") +@CommandPermission("voxelsniper.brush.voxel_disc") public class VoxelDiscBrush extends AbstractPerformerBrush { @Override public void loadProperties() { } + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { BlockVector3 targetBlock = getTargetBlock(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/VoxelDiscFaceBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/VoxelDiscFaceBrush.java index cd8f810f..56c73f1e 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/VoxelDiscFaceBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/disc/VoxelDiscFaceBrush.java @@ -1,17 +1,31 @@ package com.thevoxelbox.voxelsniper.brush.type.performer.disc; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.thevoxelbox.voxelsniper.brush.type.performer.AbstractPerformerBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b voxel_disc_face|voxeldiscface|vdf") +@CommandPermission("voxelsniper.brush.voxel_disc") public class VoxelDiscFaceBrush extends AbstractPerformerBrush { @Override public void loadProperties() { } + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { BlockVector3 lastBlock = getLastBlock(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterBallBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterBallBrush.java index e689e38d..1b079daa 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterBallBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterBallBrush.java @@ -1,83 +1,77 @@ package com.thevoxelbox.voxelsniper.brush.type.performer.splatter; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.thevoxelbox.voxelsniper.brush.type.performer.AbstractPerformerBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b splatter_ball|splatterball|sb") +@CommandPermission("voxelsniper.brush.splatterball") public class SplatterBallBrush extends AbstractPerformerBrush { - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.splatter-ball.info")); + } + + @CommandMethod("s ") + public void onBrushS( + final @NotNull Snipe snipe, + final @Argument("seed-percent") @DynamicRange(min = "seedPercentMin", max = "seedPercentMax") int seedPercent + ) { + this.seedPercent = seedPercent; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-ball.set-seed-percent", + DECIMAL_FORMAT.format(this.seedPercent / 100) + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.splatter-ball.info")); - } else { - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("s")) { - Integer seedPercent = NumericParser.parseInteger(parameters[1]); - if (seedPercent != null && seedPercent >= super.seedPercentMin && seedPercent <= super.seedPercentMax) { - this.seedPercent = seedPercent; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-ball.set-seed-parcent", - DECIMAL_FORMAT.format(this.seedPercent / 100) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.seedPercentMin, this.seedPercentMax - )); - } - } else if (firstParameter.equalsIgnoreCase("g")) { - Integer growthPercent = NumericParser.parseInteger(parameters[1]); - if (growthPercent != null && growthPercent >= super.growthPercentMin && growthPercent <= super.growthPercentMax) { - this.growthPercent = growthPercent; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-ball.set-growth-percent", - DECIMAL_FORMAT.format(this.growthPercent / 100) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.growthPercentMin, this.growthPercentMax - )); - } - } else if (firstParameter.equalsIgnoreCase("r")) { - Integer splatterRecursions = NumericParser.parseInteger(parameters[1]); - if (splatterRecursions != null && splatterRecursions >= super.splatterRecursionsMin - && splatterRecursions <= super.splatterRecursionsMax) { - this.splatterRecursions = splatterRecursions; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-ball.set-splatter-recursions", - this.splatterRecursions - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.splatterRecursionsMin, this.splatterRecursionsMax - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("g ") + public void onBrushG( + final @NotNull Snipe snipe, + final @Argument("growth-percent") @DynamicRange(min = "growthPercentMin", max = "growthPercentMax") int growthPercent + ) { + this.growthPercent = growthPercent; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-ball.set-growth-percent", + DECIMAL_FORMAT.format(this.growthPercent / 100) + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("s", "g", "r"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("r ") + public void onBrushR( + final @NotNull Snipe snipe, + final @Argument("splatter-recursions") @DynamicRange(min = "splatterRecursionsMin", max = "splatterRecursionsMax") int splatterRecursions + ) { + this.splatterRecursions = splatterRecursions; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-ball.set-splatter-recursions", + this.splatterRecursions + )); } @Override @@ -98,7 +92,7 @@ private void splatterBall(Snipe snipe, BlockVector3 targetBlock) { if (this.seedPercent < super.seedPercentMin || this.seedPercent > super.seedPercentMax) { this.seedPercent = getIntegerProperty("default-seed-percent", DEFAULT_SEED_PERCENT); messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-ball.set-seed-parcent", + "voxelsniper.brush.splatter-ball.set-seed-percent", DECIMAL_FORMAT.format(this.seedPercent / 100) )); } @@ -226,7 +220,7 @@ public void sendInfo(Snipe snipe) { .brushNameMessage() .brushSizeMessage() .message(Caption.of( - "voxelsniper.brush.splatter-ball.set-seed-parcent", + "voxelsniper.brush.splatter-ball.set-seed-percent", DECIMAL_FORMAT.format(this.seedPercent / 100) )) .message(Caption.of( diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterDiscBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterDiscBrush.java index 3a6c8703..f3f6f322 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterDiscBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterDiscBrush.java @@ -1,83 +1,77 @@ package com.thevoxelbox.voxelsniper.brush.type.performer.splatter; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.thevoxelbox.voxelsniper.brush.type.performer.AbstractPerformerBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b splatter_disc|splatterdisc|sd") +@CommandPermission("voxelsniper.brush.splatterdisc") public class SplatterDiscBrush extends AbstractPerformerBrush { - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.splatter-disc.info")); + } + + @CommandMethod("s ") + public void onBrushS( + final @NotNull Snipe snipe, + final @Argument("seed-percent") @DynamicRange(min = "seedPercentMin", max = "seedPercentMax") int seedPercent + ) { + this.seedPercent = seedPercent; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-disc.set-seed-percent", + DECIMAL_FORMAT.format(this.seedPercent / 100) + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.splatter-disc.info")); - } else { - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("s")) { - Integer seedPercent = NumericParser.parseInteger(parameters[1]); - if (seedPercent != null && seedPercent >= super.seedPercentMin && seedPercent <= super.seedPercentMax) { - this.seedPercent = seedPercent; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-disc.set-seed-parcent", - DECIMAL_FORMAT.format(this.seedPercent / 100) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.seedPercentMin, this.seedPercentMax - )); - } - } else if (firstParameter.equalsIgnoreCase("g")) { - Integer growthPercent = NumericParser.parseInteger(parameters[1]); - if (growthPercent != null && growthPercent >= super.growthPercentMin && growthPercent <= super.growthPercentMax) { - this.growthPercent = growthPercent; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-disc.set-growth-percent", - DECIMAL_FORMAT.format(this.growthPercent / 100) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.growthPercentMin, this.growthPercentMax - )); - } - } else if (firstParameter.equalsIgnoreCase("r")) { - Integer splatterRecursions = NumericParser.parseInteger(parameters[1]); - if (splatterRecursions != null && splatterRecursions >= super.splatterRecursionsMin - && splatterRecursions <= super.splatterRecursionsMax) { - this.splatterRecursions = splatterRecursions; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-disc.set-splatter-recursions", - this.splatterRecursions - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.splatterRecursionsMin, this.splatterRecursionsMax - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("g ") + public void onBrushG( + final @NotNull Snipe snipe, + final @Argument("growth-percent") @DynamicRange(min = "growthPercentMin", max = "growthPercentMax") int growthPercent + ) { + this.growthPercent = growthPercent; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-disc.set-growth-percent", + DECIMAL_FORMAT.format(this.growthPercent / 100) + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("s", "g", "r"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("r ") + public void onBrushR( + final @NotNull Snipe snipe, + final @Argument("splatter-recursions") @DynamicRange(min = "splatterRecursionsMin", max = "splatterRecursionsMax") int splatterRecursions + ) { + this.splatterRecursions = splatterRecursions; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-disc.set-splatter-recursions", + this.splatterRecursions + )); } @Override @@ -98,7 +92,7 @@ private void splatterDisc(Snipe snipe, BlockVector3 targetBlock) { if (this.seedPercent < super.seedPercentMin || this.seedPercent > super.seedPercentMax) { this.seedPercent = getIntegerProperty("default-seed-percent", DEFAULT_SEED_PERCENT); messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-disc.set-seed-parcent", + "voxelsniper.brush.splatter-disc.set-seed-percent", DECIMAL_FORMAT.format(this.seedPercent / 100) )); } @@ -209,7 +203,7 @@ public void sendInfo(Snipe snipe) { .brushNameMessage() .brushSizeMessage() .message(Caption.of( - "voxelsniper.brush.splatter-disc.set-seed-parcent", + "voxelsniper.brush.splatter-disc.set-seed-percent", DECIMAL_FORMAT.format(this.seedPercent / 100) )) .message(Caption.of( diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterOverlayBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterOverlayBrush.java index 8b0a1058..89aaf37f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterOverlayBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterOverlayBrush.java @@ -1,22 +1,28 @@ package com.thevoxelbox.voxelsniper.brush.type.performer.splatter; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.thevoxelbox.voxelsniper.brush.type.performer.AbstractPerformerBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.MaterialSets; import com.thevoxelbox.voxelsniper.util.material.Materials; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b splatter_overlay|splatteroverlay|sover") +@CommandPermission("voxelsniper.brush.splatteroverlay") public class SplatterOverlayBrush extends AbstractPerformerBrush { private static final int DEFAULT_DEPTH = 3; @@ -35,109 +41,127 @@ public void loadProperties() { this.yOffset = getIntegerProperty("default-y-offset", DEFAULT_Y_OFFSET); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.splatter-overlay.info")); + } + + @CommandMethod("all") + public void onBrushAll( + final @NotNull Snipe snipe + ) { + this.allBlocks = true; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-overlay.set-overlay-all", + VoxelSniperText.getStatus(true) + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.splatter-overlay.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("all")) { - this.allBlocks = true; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-overlay.set-overlay-all", - VoxelSniperText.getStatus(true) - )); - } else if (firstParameter.equalsIgnoreCase("some")) { - this.allBlocks = false; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-overlay.set-overlay-natural", - VoxelSniperText.getStatus(true) - )); - } else if (firstParameter.equalsIgnoreCase("randh")) { - this.randomizeHeight = !this.randomizeHeight; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-overlay.set-randomize-height", - VoxelSniperText.getStatus(true) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("d")) { - Integer depth = NumericParser.parseInteger(parameters[1]); - if (depth != null) { - this.depth = depth < 1 ? 1 : depth; - messenger.sendMessage(Caption.of("voxelsniper.brush.splatter-overlay.set-depth", this.depth)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else if (firstParameter.equalsIgnoreCase("s")) { - Integer seedPercent = NumericParser.parseInteger(parameters[1]); - if (seedPercent != null && seedPercent >= super.seedPercentMin && seedPercent <= super.seedPercentMax) { - this.seedPercent = seedPercent; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-overlay.set-seed-parcent", - DECIMAL_FORMAT.format(this.seedPercent / 100) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.seedPercentMin, this.seedPercentMax - )); - } - } else if (firstParameter.equalsIgnoreCase("g")) { - Integer growthPercent = NumericParser.parseInteger(parameters[1]); - if (growthPercent != null && growthPercent >= super.growthPercentMin && growthPercent <= super.growthPercentMax) { - this.growthPercent = growthPercent; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-overlay.set-growth-percent", - DECIMAL_FORMAT.format(this.growthPercent / 100) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.growthPercentMin, this.growthPercentMax - )); - } - } else if (firstParameter.equalsIgnoreCase("r")) { - Integer splatterRecursions = NumericParser.parseInteger(parameters[1]); - if (splatterRecursions != null && splatterRecursions >= super.splatterRecursionsMin - && splatterRecursions <= super.splatterRecursionsMax) { - this.splatterRecursions = splatterRecursions; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-overlay.set-splatter-recursions", - this.splatterRecursions - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.splatterRecursionsMin, this.splatterRecursionsMax - )); - } - } else if (firstParameter.equalsIgnoreCase("yoff")) { - Integer yOffset = NumericParser.parseInteger(parameters[1]); - if (yOffset != null) { - this.yOffset = yOffset; - messenger.sendMessage(Caption.of("voxelsniper.brush.splatter-overlay.set-y-offset", this.yOffset)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("some") + public void onBrushSome( + final @NotNull Snipe snipe + ) { + this.allBlocks = false; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-overlay.set-overlay-natural", + VoxelSniperText.getStatus(true) + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("all", "some", "d", "s", "g", "r", "randh", "yoff"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("randh") + public void onBrushRandh( + final @NotNull Snipe snipe + ) { + this.randomizeHeight = !this.randomizeHeight; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-overlay.set-randomize-height", + VoxelSniperText.getStatus(this.randomizeHeight) + )); + } + + @CommandMethod("d ") + public void onBrushD( + final @NotNull Snipe snipe, + final @Argument("depth") @Range(min = "1") int depth + ) { + this.depth = depth; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-overlay.set-depth", + this.depth + )); + } + + @CommandMethod("s ") + public void onBrushS( + final @NotNull Snipe snipe, + final @Argument("seed-percent") @DynamicRange(min = "seedPercentMin", max = "seedPercentMax") int seedPercent + ) { + this.seedPercent = seedPercent; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-overlay.set-seed-percent", + DECIMAL_FORMAT.format(this.seedPercent / 100) + )); + } + + @CommandMethod("g ") + public void onBrushG( + final @NotNull Snipe snipe, + final @Argument("growth-percent") @DynamicRange(min = "growthPercentMin", max = "growthPercentMax") int growthPercent + ) { + this.growthPercent = growthPercent; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-overlay.set-growth-percent", + DECIMAL_FORMAT.format(this.growthPercent / 100) + )); + } + + @CommandMethod("r ") + public void onBrushR( + final @NotNull Snipe snipe, + final @Argument("splatter-recursions") @DynamicRange(min = "splatterRecursionsMin", max = "splatterRecursionsMax") int splatterRecursions + ) { + this.splatterRecursions = splatterRecursions; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-overlay.set-splatter-recursions", + this.splatterRecursions + )); + } + + @CommandMethod("yoff ") + public void onBrushY( + final @NotNull Snipe snipe, + final @Argument("y-offset") int yOffset + ) { + this.yOffset = yOffset; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-overlay.set-y-offset", + this.yOffset + )); } @Override @@ -412,7 +436,7 @@ public void sendInfo(Snipe snipe) { )) .message(Caption.of("voxelsniper.brush.splatter-overlay.set-depth", this.depth)) .message(Caption.of( - "voxelsniper.brush.splatter-overlay.set-seed-parcent", + "voxelsniper.brush.splatter-overlay.set-seed-percent", DECIMAL_FORMAT.format(this.seedPercent / 100) )) .message(Caption.of( @@ -423,7 +447,10 @@ public void sendInfo(Snipe snipe) { "voxelsniper.brush.splatter-overlay.set-splatter-recursions", this.splatterRecursions )) - .message(Caption.of("voxelsniper.brush.splatter-overlay.set-y-offset", this.yOffset)) + .message(Caption.of( + "voxelsniper.brush.splatter-overlay.set-y-offset", + this.yOffset + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterVoxelBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterVoxelBrush.java index 11eebf5e..0ae3ef39 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterVoxelBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterVoxelBrush.java @@ -1,83 +1,77 @@ package com.thevoxelbox.voxelsniper.brush.type.performer.splatter; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.thevoxelbox.voxelsniper.brush.type.performer.AbstractPerformerBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b splatter_voxel|splattervoxel|sv") +@CommandPermission("voxelsniper.brush.splattervoxel") public class SplatterVoxelBrush extends AbstractPerformerBrush { - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.splatter-voxel.info")); + } + + @CommandMethod("s ") + public void onBrushS( + final @NotNull Snipe snipe, + final @Argument("seed-percent") @DynamicRange(min = "seedPercentMin", max = "seedPercentMax") int seedPercent + ) { + this.seedPercent = seedPercent; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-voxel.set-seed-percent", + DECIMAL_FORMAT.format(this.seedPercent / 100) + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.splatter-voxel.info")); - } else { - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("s")) { - Integer seedPercent = NumericParser.parseInteger(parameters[1]); - if (seedPercent != null && seedPercent >= super.seedPercentMin && seedPercent <= super.seedPercentMax) { - this.seedPercent = seedPercent; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-voxel.set-seed-parcent", - DECIMAL_FORMAT.format(this.seedPercent / 100) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.seedPercentMin, this.seedPercentMax - )); - } - } else if (firstParameter.equalsIgnoreCase("g")) { - Integer growthPercent = NumericParser.parseInteger(parameters[1]); - if (growthPercent != null && growthPercent >= super.growthPercentMin && growthPercent <= super.growthPercentMax) { - this.growthPercent = growthPercent; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-voxel.set-growth-percent", - DECIMAL_FORMAT.format(this.growthPercent / 100) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.growthPercentMin, this.growthPercentMax - )); - } - } else if (firstParameter.equalsIgnoreCase("r")) { - Integer splatterRecursions = NumericParser.parseInteger(parameters[1]); - if (splatterRecursions != null && splatterRecursions >= super.splatterRecursionsMin - && splatterRecursions <= super.splatterRecursionsMax) { - this.splatterRecursions = splatterRecursions; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-voxel.set-splatter-recursions", - this.splatterRecursions - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.splatterRecursionsMin, this.splatterRecursionsMax - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("g ") + public void onBrushG( + final @NotNull Snipe snipe, + final @Argument("growth-percent") @DynamicRange(min = "growthPercentMin", max = "growthPercentMax") int growthPercent + ) { + this.growthPercent = growthPercent; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-voxel.set-growth-percent", + DECIMAL_FORMAT.format(this.growthPercent / 100) + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("s", "g", "r"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("r ") + public void onBrushR( + final @NotNull Snipe snipe, + final @Argument("splatter-recursions") @DynamicRange(min = "splatterRecursionsMin", max = "splatterRecursionsMax") int splatterRecursions + ) { + this.splatterRecursions = splatterRecursions; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-voxel.set-splatter-recursions", + this.splatterRecursions + )); } @Override @@ -98,7 +92,7 @@ private void voxelSplatterBall(Snipe snipe, BlockVector3 targetBlock) { if (this.seedPercent < super.seedPercentMin || this.seedPercent > super.seedPercentMax) { this.seedPercent = getIntegerProperty("default-seed-percent", DEFAULT_SEED_PERCENT); messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-voxel.set-seed-parcent", + "voxelsniper.brush.splatter-voxel.set-seed-percent", DECIMAL_FORMAT.format(this.seedPercent / 100) )); } @@ -223,7 +217,7 @@ public void sendInfo(Snipe snipe) { .brushNameMessage() .brushSizeMessage() .message(Caption.of( - "voxelsniper.brush.splatter-voxel.set-seed-parcent", + "voxelsniper.brush.splatter-voxel.set-seed-percent", DECIMAL_FORMAT.format(this.seedPercent / 100) )) .message(Caption.of( diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterVoxelDiscBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterVoxelDiscBrush.java index eea979fb..4259cc56 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterVoxelDiscBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/performer/splatter/SplatterVoxelDiscBrush.java @@ -1,83 +1,77 @@ package com.thevoxelbox.voxelsniper.brush.type.performer.splatter; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.thevoxelbox.voxelsniper.brush.type.performer.AbstractPerformerBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b splatter_voxel_disc|splattervoxeldisc|svd") +@CommandPermission("voxelsniper.brush.splattervoxel") public class SplatterVoxelDiscBrush extends AbstractPerformerBrush { - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.splatter-voxel-disc.info")); + } + + @CommandMethod("s ") + public void onBrushS( + final @NotNull Snipe snipe, + final @Argument("seed-percent") @DynamicRange(min = "seedPercentMin", max = "seedPercentMax") int seedPercent + ) { + this.seedPercent = seedPercent; + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-voxel-disc.set-seed-percent", + DECIMAL_FORMAT.format(this.seedPercent / 100) + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.splatter-voxel-disc.info")); - } else { - if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("s")) { - Integer seedPercent = NumericParser.parseInteger(parameters[1]); - if (seedPercent != null && seedPercent >= super.seedPercentMin && seedPercent <= super.seedPercentMax) { - this.seedPercent = seedPercent; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-voxel-disc.set-seed-parcent", - DECIMAL_FORMAT.format(this.seedPercent / 100) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.seedPercentMin, this.seedPercentMax - )); - } - } else if (firstParameter.equalsIgnoreCase("g")) { - Integer growthPercent = NumericParser.parseInteger(parameters[1]); - if (growthPercent != null && growthPercent >= super.growthPercentMin && growthPercent <= super.growthPercentMax) { - this.growthPercent = growthPercent; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-voxel-disc.set-growth-percent", - DECIMAL_FORMAT.format(this.growthPercent / 100) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.growthPercentMin, this.growthPercentMax - )); - } - } else if (firstParameter.equalsIgnoreCase("r")) { - Integer splatterRecursions = NumericParser.parseInteger(parameters[1]); - if (splatterRecursions != null && splatterRecursions >= super.splatterRecursionsMin - && splatterRecursions <= super.splatterRecursionsMax) { - this.splatterRecursions = splatterRecursions; - messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-voxel-disc.set-splatter-recursions", - this.splatterRecursions - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", parameters[1], - this.splatterRecursionsMin, this.splatterRecursionsMax - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("g ") + public void onBrushG( + final @NotNull Snipe snipe, + final @Argument("growth-percent") @DynamicRange(min = "growthPercentMin", max = "growthPercentMax") int growthPercent + ) { + this.growthPercent = growthPercent; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-voxel-disc.set-growth-percent", + DECIMAL_FORMAT.format(this.growthPercent / 100) + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("s", "g", "r"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("r ") + public void onBrushR( + final @NotNull Snipe snipe, + final @Argument("splatter-recursions") @DynamicRange(min = "splatterRecursionsMin", max = "splatterRecursionsMax") int splatterRecursions + ) { + this.splatterRecursions = splatterRecursions; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.splatter-voxel-disc.set-splatter-recursions", + this.splatterRecursions + )); } @Override @@ -98,7 +92,7 @@ private void vSplatterDisc(Snipe snipe, BlockVector3 targetBlock) { if (this.seedPercent < super.seedPercentMin || this.seedPercent > super.seedPercentMax) { this.seedPercent = getIntegerProperty("default-seed-percent", DEFAULT_SEED_PERCENT); messenger.sendMessage(Caption.of( - "voxelsniper.brush.splatter-voxel-disc.set-seed-parcent", + "voxelsniper.brush.splatter-voxel-disc.set-seed-percent", DECIMAL_FORMAT.format(this.seedPercent / 100) )); } @@ -207,7 +201,7 @@ public void sendInfo(Snipe snipe) { .brushNameMessage() .brushSizeMessage() .message(Caption.of( - "voxelsniper.brush.splatter-voxel-disc.set-seed-parcent", + "voxelsniper.brush.splatter-voxel-disc.set-seed-percent", DECIMAL_FORMAT.format(this.seedPercent / 100) )) .message(Caption.of( diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/redstone/SetRedstoneFlipBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/redstone/SetRedstoneFlipBrush.java index a2b1f380..c96c71cc 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/redstone/SetRedstoneFlipBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/redstone/SetRedstoneFlipBrush.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.brush.type.redstone; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.registry.state.PropertyKey; import com.sk89q.worldedit.math.BlockVector3; @@ -8,52 +10,53 @@ import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; -import java.util.stream.Stream; - +@RequireToolkit +@CommandMethod(value = "brush|b set_redstone_flip|setredstoneflip|setrf") +@CommandPermission("voxelsniper.brush.setredstoneflip") public class SetRedstoneFlipBrush extends AbstractBrush { @Nullable private BlockVector3 block; private boolean northSouth = true; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.set-redstone-flip.info")); - } else { - if (parameters.length == 1) { - if (Stream.of("n", "s", "ns") - .anyMatch(firstParameter::startsWith)) { - this.northSouth = true; - messenger.sendMessage(Caption.of("voxelsniper.brush.set-redstone-flip.north-south")); - } else if (Stream.of("e", "w", "ew") - .anyMatch(firstParameter::startsWith)) { - this.northSouth = false; - messenger.sendMessage(Caption.of("voxelsniper.brush.set-redstone-flip.east-west")); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.set-redstone-flip.info")); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("n", "s", "ns", "e", "w", "ew"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("ns|n|s") + public void onBrushNs( + final @NotNull Snipe snipe + ) { + this.northSouth = true; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of("voxelsniper.brush.set-redstone-flip.north-south")); + } + + @CommandMethod("ew|e|w") + public void onBrushEw( + final @NotNull Snipe snipe + ) { + this.northSouth = false; + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of("voxelsniper.brush.set-redstone-flip.east-west")); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/redstone/SetRedstoneRotateBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/redstone/SetRedstoneRotateBrush.java index 1f2f4503..d7e4692b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/redstone/SetRedstoneRotateBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/redstone/SetRedstoneRotateBrush.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.brush.type.redstone; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.registry.state.PropertyKey; import com.sk89q.worldedit.math.BlockVector3; @@ -8,15 +10,27 @@ import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +@RequireToolkit +@CommandMethod(value = "brush|b set_redstone_rotate|setredstonerotatep|setrr") +@CommandPermission("voxelsniper.brush.setredstonerotate") public class SetRedstoneRotateBrush extends AbstractBrush { @Nullable private BlockVector3 block; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { BlockVector3 targetBlock = getTargetBlock(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation2DBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation2DBrush.java index 1c5553f2..83c995b0 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation2DBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation2DBrush.java @@ -1,17 +1,25 @@ package com.thevoxelbox.voxelsniper.brush.type.rotation; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.Materials; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b rotation_2d|rotation2d|rot2d|rot2") +@CommandPermission("voxelsniper.brush.rot2d") public class Rotation2DBrush extends AbstractBrush { private static final int DEFAULT_ANGLE = 0; @@ -21,30 +29,35 @@ public class Rotation2DBrush extends AbstractBrush { private double angle = DEFAULT_ANGLE; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.rotation-2d.info", 180, DECIMAL_FORMAT.format(Math.PI))); - } else { - if (parameters.length == 1) { - Double degreesAngle = NumericParser.parseDouble(firstParameter); - if (degreesAngle != null) { - this.angle = Math.toRadians(degreesAngle); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.rotation-2d.set-angle", - DECIMAL_FORMAT.format(this.angle), - DECIMAL_FORMAT.format(degreesAngle) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", firstParameter)); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.rotation-2d.info", + 180, DECIMAL_FORMAT.format(Math.PI) + )); + } + + @CommandMethod("") + public void onBrushDegreesangle( + final @NotNull Snipe snipe, + final @Argument("degrees-angle") @Range(min = "0", max = "360") int degreesAngle + ) { + this.angle = Math.toRadians(degreesAngle); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.rotation-2d.set-angle", + DECIMAL_FORMAT.format(this.angle), + DECIMAL_FORMAT.format(degreesAngle) + )); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation2DVerticalBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation2DVerticalBrush.java index 402e73cd..3774236c 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation2DVerticalBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation2DVerticalBrush.java @@ -1,19 +1,27 @@ package com.thevoxelbox.voxelsniper.brush.type.rotation; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.Materials; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; +import org.jetbrains.annotations.NotNull; // The X Y and Z variable names in this file do NOT MAKE ANY SENSE. Do not attempt to actually figure out what on earth is going on here. Just go to the // original 2d horizontal brush if you wish to make anything similar to this, and start there. I didn't bother renaming everything. +@RequireToolkit +@CommandMethod(value = "brush|b rotation_2d_vert|rotation2dvert|rot2dv|rot2v") +@CommandPermission("voxelsniper.brush.rot2dvert") public class Rotation2DVerticalBrush extends AbstractBrush { private static final int DEFAULT_ANGLE = 0; @@ -23,30 +31,35 @@ public class Rotation2DVerticalBrush extends AbstractBrush { private double angle = DEFAULT_ANGLE; - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.rotation-2d-vertical.info", 180, DECIMAL_FORMAT.format(Math.PI))); - } else { - if (parameters.length == 1) { - Double degreesAngle = NumericParser.parseDouble(firstParameter); - if (degreesAngle != null) { - this.angle = Math.toRadians(degreesAngle); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.rotation-2d-vertical.set-angle", - DECIMAL_FORMAT.format(this.angle), - DECIMAL_FORMAT.format(degreesAngle) - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", firstParameter)); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.rotation-2d-vertical.info", + 180, DECIMAL_FORMAT.format(Math.PI) + )); + } + + @CommandMethod("") + public void onBrushDegreesangle( + final @NotNull Snipe snipe, + final @Argument("degrees-angle") @Range(min = "0", max = "360") int degreesAngle + ) { + this.angle = Math.toRadians(degreesAngle); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.rotation-2d-vertical.set-angle", + DECIMAL_FORMAT.format(this.angle), + DECIMAL_FORMAT.format(degreesAngle) + )); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation3DBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation3DBrush.java index 1629b8c2..155f36ef 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation3DBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/rotation/Rotation3DBrush.java @@ -1,20 +1,25 @@ package com.thevoxelbox.voxelsniper.brush.type.rotation; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.material.Materials; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b rotation_3d|rotation3d|rot3d|rot3") +@CommandPermission("voxelsniper.brush.rot3d") public class Rotation3DBrush extends AbstractBrush { private static final int DEFAULT_SE_YAW = 0; @@ -28,60 +33,65 @@ public class Rotation3DBrush extends AbstractBrush { private double sePitch = DEFAULT_SE_PITCH; private double seRoll = DEFAULT_SE_ROLL; - // after all rotations, compare snapshot to new state of world? - // --> agreed. Do what erode does and store one snapshot with Block pointers and int id of what the block started with, afterwards simply go thru that - // matrix and compare Block.getId with 'id' - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.rotation.3d.info", + 180, DECIMAL_FORMAT.format(Math.PI) + )); + } + + @CommandMethod("p ") + public void onBrushP( + final @NotNull Snipe snipe, + final @Argument("degrees-angle") @Range(min = "0", max = "360") int degreesAngle + ) { + this.sePitch = Math.toRadians(degreesAngle); + SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; - - // which way is clockwise is less obvious for roll and pitch... should probably fix that / make it clear - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.rotation-3d.info", 180, DECIMAL_FORMAT.format(Math.PI))); - } else { - if (parameters.length == 2) { - Double degreesAngle = NumericParser.parseDouble(parameters[1]); - - if (degreesAngle != null && degreesAngle >= 0 && degreesAngle <= 359) { - if (firstParameter.equalsIgnoreCase("p")) { - this.sePitch = Math.toRadians(degreesAngle); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.rotation-3d.set-z-angle", - DECIMAL_FORMAT.format(this.sePitch), - DECIMAL_FORMAT.format(degreesAngle) - )); - } else if (firstParameter.equalsIgnoreCase("r")) { - this.seRoll = Math.toRadians(degreesAngle); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.rotation-3d.set-x-angle", - DECIMAL_FORMAT.format(this.seRoll), - DECIMAL_FORMAT.format(degreesAngle) - )); - } else if (firstParameter.equalsIgnoreCase("y")) { - this.seYaw = Math.toRadians(degreesAngle); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.rotation-3d.set-y-angle", - DECIMAL_FORMAT.format(this.seYaw), - DECIMAL_FORMAT.format(degreesAngle) - )); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number-between", firstParameter, 1, 359)); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + messenger.sendMessage(Caption.of( + "voxelsniper.brush.rotation-3d.set-z-angle", + DECIMAL_FORMAT.format(this.sePitch), + DECIMAL_FORMAT.format(degreesAngle) + )); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("p", "r", "y"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("r ") + public void onBrushR( + final @NotNull Snipe snipe, + final @Argument("degrees-angle") @Range(min = "0", max = "360") int degreesAngle + ) { + this.seRoll = Math.toRadians(degreesAngle); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.rotation-3d.set-x-angle", + DECIMAL_FORMAT.format(this.seRoll), + DECIMAL_FORMAT.format(degreesAngle) + )); + } + + @CommandMethod("y ") + public void onBrushY( + final @NotNull Snipe snipe, + final @Argument("degrees-angle") @Range(min = "0", max = "360") int degreesAngle + ) { + this.seYaw = Math.toRadians(degreesAngle); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.rotation-3d.set-y-angle", + DECIMAL_FORMAT.format(this.seYaw), + DECIMAL_FORMAT.format(degreesAngle) + )); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellBallBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellBallBrush.java index e44bb16d..776f97a7 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellBallBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellBallBrush.java @@ -1,16 +1,30 @@ package com.thevoxelbox.voxelsniper.brush.type.shell; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b shell_ball|shellball|shb") +@CommandPermission("voxelsniper.brush.shellball") public class ShellBallBrush extends AbstractBrush { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { BlockVector3 targetBlock = getTargetBlock(); @@ -99,7 +113,7 @@ private void bShell(Snipe snipe, BlockVector3 targetBlock) { } } } - // This is needed because most uses of this brush will not be sible to the sniper. + // This is needed because most uses of this brush will not be visible to the sniper. SnipeMessenger messenger = snipe.createMessenger(); messenger.sendMessage(Caption.of("voxelsniper.brush.shell.completed")); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellSetBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellSetBrush.java index 10096ae3..c874be3f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellSetBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellSetBrush.java @@ -1,19 +1,26 @@ package com.thevoxelbox.voxelsniper.brush.type.shell; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +@RequireToolkit +@CommandMethod(value = "brush|b shell_set|shellset|shs") +@CommandPermission("voxelsniper.brush.shellset") public class ShellSetBrush extends AbstractBrush { private static final int MAX_SIZE = 5000000; @@ -28,6 +35,13 @@ public void loadProperties() { this.maxSize = getIntegerProperty("max-size", MAX_SIZE); } + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { BlockVector3 targetBlock = getTargetBlock(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellVoxelBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellVoxelBrush.java index 1f308ea8..13821f98 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellVoxelBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/shell/ShellVoxelBrush.java @@ -1,16 +1,30 @@ package com.thevoxelbox.voxelsniper.brush.type.shell; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@RequireToolkit +@CommandMethod(value = "brush|b shell_voxel|shellvoxel|shv") +@CommandPermission("voxelsniper.brush.shellvoxel") public class ShellVoxelBrush extends AbstractBrush { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + @Override public void handleArrowAction(Snipe snipe) { BlockVector3 targetBlock = getTargetBlock(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stamp/CloneStampBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stamp/CloneStampBrush.java index ffb748c4..bba5111f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stamp/CloneStampBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stamp/CloneStampBrush.java @@ -1,90 +1,95 @@ package com.thevoxelbox.voxelsniper.brush.type.stamp; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.math.BlockVector3; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; - -import java.util.List; -import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; /** * The CloneStamp class is used to create a collection of blocks in a cylinder shape according to the selection the player has set. */ +@RequireToolkit +@CommandMethod(value = "brush|b clone_stamp|clonestamp|cs") +@CommandPermission("voxelsniper.brush.clonestamp") public class CloneStampBrush extends AbstractStampBrush { private static final StampType DEFAULT_STAMP_TYPE = StampType.DEFAULT; @Override public void loadProperties() { - this.setStamp((StampType) getEnumProperty("default-stamp-type", StampType.class, DEFAULT_STAMP_TYPE)); + this.stamp = ((StampType) getEnumProperty("default-stamp-type", StampType.class, DEFAULT_STAMP_TYPE)); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); + } + + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.clone-stamp.info")); + } + + @CommandMethod("") + public void onBrushStamptype( + final @NotNull Snipe snipe, + final @NotNull @Argument("stamp-type") StampType stampType + ) { + this.stamp = stampType; + this.reSort(); + SnipeMessenger messenger = snipe.createMessenger(); - ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); - String firstParameter = parameters[0]; + messenger.sendMessage(Caption.of( + "voxelsniper.brush.clone-stamp.set-stamp-type", + StampType.FILL.getFullName() + )); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.clone-stamp.info")); - } else { - if (parameters.length == 1) { - if (firstParameter.equalsIgnoreCase("a")) { - setStamp(StampType.NO_AIR); - reSort(); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.clone-stamp.set-stamp-type", - StampType.NO_AIR.getFullName() - )); - } else if (firstParameter.equalsIgnoreCase("f")) { - setStamp(StampType.FILL); - reSort(); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.clone-stamp.set-stamp-type", - StampType.FILL.getFullName() - )); - } else if (firstParameter.equalsIgnoreCase("d")) { - setStamp(StampType.DEFAULT); - reSort(); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.clone-stamp.set-stamp-type", - StampType.DEFAULT.getFullName() - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else if (parameters.length == 2) { - if (firstParameter.equalsIgnoreCase("c")) { - Integer cylinderCenter = NumericParser.parseInteger(parameters[1]); - if (cylinderCenter != null) { - toolkitProperties.setCylinderCenter(cylinderCenter); - messenger.sendMessage(Caption.of( - "voxelsniper.brush.clone-stamp.set-center", - toolkitProperties.getCylinderCenter() - )); - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.invalid-number", parameters[1])); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters")); - } - } else { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - } - } + @CommandMethod("a") + public void onBrushA( + final @NotNull Snipe snipe + ) { + this.onBrushStamptype(snipe, StampType.NO_AIR); } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("f", "a", "d", "c"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("f") + public void onBrushF( + final @NotNull Snipe snipe + ) { + this.onBrushStamptype(snipe, StampType.FILL); + } + + @CommandMethod("d") + public void onBrushD( + final @NotNull Snipe snipe + ) { + this.onBrushStamptype(snipe, StampType.DEFAULT); + } + + @CommandMethod("c
") + public void onBrushC( + final @NotNull Snipe snipe, + final @Argument("center") int center + ) { + ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); + toolkitProperties.setCylinderCenter(center); + + SnipeMessenger messenger = snipe.createMessenger(); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.clone-stamp.set-center", + toolkitProperties.getCylinderCenter() + )); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stencil/StencilBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stencil/StencilBrush.java index 1c61b4ea..03b4f08f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stencil/StencilBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stencil/StencilBrush.java @@ -1,13 +1,18 @@ package com.thevoxelbox.voxelsniper.brush.type.stencil; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.material.Materials; +import org.jetbrains.annotations.NotNull; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -17,21 +22,21 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.util.List; -import java.util.stream.Stream; /** * This is paste only currently. Assumes files exist, and thus has no usefulness until I add in saving stencils later. Uses sniper-exclusive stencil format: 3 * shorts for X,Z,Y size of cuboid 3 shorts for X,Z,Y offsets from the -X,-Z,-Y corner. This is the reference point for pasting, corresponding to where you * click your brush. 1 long integer saying how many runs of blocks are in the schematic (data is compressed into runs) 1 per run: (1 boolean: true = compressed * line ahead, false = locally unique block ahead. This wastes a bit instead of a byte, and overall saves space, as long as at least 1/8 of all RUNS are going - * to be size 1, which in Minecraft is almost definitely true. IF boolean was true, next unsigned byte stores the number of consecutive blocks of the same type, + * to be size 1, which in Minecraft is almost definitely true. IF boolean was true, next unstenciled byte stores the number of consecutive blocks of the same type, * up to 256. IF boolean was false, there is no byte here, goes straight to ID and data instead, which applies to just one block. 2 bytes to identify type of * block. First byte is ID, second is data. This applies to every one of the line of consecutive blocks if boolean was true.) */ +@RequireToolkit +@CommandMethod(value = "brush|b stencil|st") +@CommandPermission("voxelsniper.brush.stencil") public class StencilBrush extends AbstractBrush { - private static final String NO_FILE_LOADED = "NoFileLoaded"; private static final int DEFAULT_PASTE_OPTION = 1; private static final int DEFAULT_MAX_AREA_VOLUME = 5_000_000; private static final int DEFAULT_MAX_SAVE_VOLUME = 50_000; @@ -39,7 +44,7 @@ public class StencilBrush extends AbstractBrush { private final int[] firstPoint = new int[3]; private final int[] secondPoint = new int[3]; private final int[] pastePoint = new int[3]; - private String filename = NO_FILE_LOADED; + private File file = null; private short x; private short z; private short y; @@ -57,63 +62,70 @@ public void loadProperties() { this.pasteOption = (byte) getIntegerProperty("default-paste-option", DEFAULT_PASTE_OPTION); this.maxAreaVolume = getIntegerProperty("default-max-area-volume", DEFAULT_MAX_AREA_VOLUME); this.maxSaveVolume = getIntegerProperty("default-max-save-volume", DEFAULT_MAX_SAVE_VOLUME); + } - File dataFolder = new File(PLUGIN_DATA_FOLDER, "/stencils"); - dataFolder.mkdirs(); + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.stencil.info")); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.info")); - } else { - byte pasteOption; - byte pasteParam; - if (firstParameter.equalsIgnoreCase("full")) { - pasteOption = 0; - pasteParam = 1; - } else if (firstParameter.equalsIgnoreCase("fill")) { - pasteOption = 1; - pasteParam = 1; - } else if (firstParameter.equalsIgnoreCase("replace")) { - pasteOption = 2; - pasteParam = 1; - } else { - // Reset to [s] parameter expected. - pasteOption = 1; - pasteParam = 0; - } - if (parameters.length != 1 + pasteParam) { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - return; - } + private void onBrushPasteCommand(Snipe snipe, byte pasteOption, File stencil) { + this.pasteOption = pasteOption; + this.file = stencil; - this.pasteOption = pasteOption; - try { - this.filename = parameters[pasteParam]; - File file = new File(PLUGIN_DATA_FOLDER, "/stencils/" + this.filename + ".vstencil"); - if (file.exists()) { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.loaded", this.filename)); - } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.missing", this.filename)); - } - } catch (RuntimeException exception) { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.wrong-stencil-name")); - exception.printStackTrace(); - } + SnipeMessenger messenger = snipe.createMessenger(); + if (stencil.exists()) { + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.loaded", + this.file.getName() + )); + } else { + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.missing", + this.file.getName() + )); } } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("full", "fill", "replace"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("full ") + public void onBrushFull( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "stencil", parserName = "stencil-file_parser") File stencil + ) { + this.onBrushPasteCommand(snipe, (byte) 0, stencil); + } + + @CommandMethod("fill ") + public void onBrushFill( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "stencil", parserName = "stencil-file_parser") File stencil + ) { + this.onBrushPasteCommand(snipe, (byte) 1, stencil); + } + + @CommandMethod("replace ") + public void onBrushReplace( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "stencil", parserName = "stencil-file_parser") File stencil + ) { + this.onBrushPasteCommand(snipe, (byte) 2, stencil); + } + + @CommandMethod("") + public void onBrushStencil( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "stencil", parserName = "stencil-file_parser") File stencil + ) { + this.onBrushFill(snipe, stencil); } @Override @@ -125,8 +137,9 @@ public void handleArrowAction(Snipe snipe) { // will be used to copy/save later this.firstPoint[1] = targetBlock.getZ(); this.firstPoint[2] = targetBlock.getY(); messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.first-point")); - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.coordinates", this.firstPoint[0], this.firstPoint[1], - this.firstPoint[2] + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.coordinates", + this.firstPoint[0], this.firstPoint[1], this.firstPoint[2] )); this.point = 2; } else if (this.point == 2) { @@ -135,7 +148,10 @@ public void handleArrowAction(Snipe snipe) { // will be used to copy/save later this.secondPoint[2] = targetBlock.getY(); if ((Math.abs(this.firstPoint[0] - this.secondPoint[0]) * Math.abs(this.firstPoint[1] - this.secondPoint[1]) * Math.abs( this.firstPoint[2] - this.secondPoint[2])) > this.maxAreaVolume) { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.area-too-large", this.maxAreaVolume)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.area-too-large", + this.maxAreaVolume + )); this.point = 1; } else { messenger.sendMessage(Caption.of("voxelsniper.brush.parameter.second-point")); @@ -152,8 +168,9 @@ public void handleArrowAction(Snipe snipe) { // will be used to copy/save later this.pastePoint[1] = targetBlock.getZ(); this.pastePoint[2] = targetBlock.getY(); messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.paste-point")); - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.coordinates", this.pastePoint[0], this.pastePoint[1], - this.pastePoint[2] + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.coordinates", + this.pastePoint[0], this.pastePoint[1], this.pastePoint[2] )); this.point = 1; this.stencilSave(snipe); @@ -167,11 +184,10 @@ public void handleGunpowderAction(Snipe snipe) { // will be used to paste later private void stencilPaste(Snipe snipe, StencilReader.BlockDataReader blockDataReader) { SnipeMessenger messenger = snipe.createMessenger(); - if (this.filename.matches(NO_FILE_LOADED)) { + if (this.file == null) { messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.missing-file")); return; } - File file = new File(PLUGIN_DATA_FOLDER, "/stencils/" + this.filename + ".vstencil"); if (file.exists()) { try { DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); @@ -336,25 +352,28 @@ private void stencilPaste(Snipe snipe, StencilReader.BlockDataReader blockDataRe } } } - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.pasted", this.filename, volume)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.pasted", + this.file.getName(), + volume + )); in.close(); - } catch (IOException exception) { + } catch (IOException e) { if (blockDataReader == StencilReader.BlockDataReader.BLOCK_DATA) { // Tries with some legacy handling for legacy stencils. stencilPaste(snipe, StencilReader.BlockDataReader.LEGACY_IDS); } else { messenger.sendMessage(Caption.of("voxelsniper.error.unexpected")); - exception.printStackTrace(); + e.printStackTrace(); } } } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.wrong-stencil-name")); + messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.invalid-stencil-name")); } } private void stencilSave(Snipe snipe) { SnipeMessenger messenger = snipe.createMessenger(); - File file = new File(PLUGIN_DATA_FOLDER, "/stencils/" + this.filename + ".vstencil"); try { this.x = (short) (Math.abs((this.firstPoint[0] - this.secondPoint[0])) + 1); this.z = (short) (Math.abs((this.firstPoint[1] - this.secondPoint[1])) + 1); @@ -385,7 +404,9 @@ private void stencilSave(Snipe snipe) { out.writeShort(this.xRef); out.writeShort(this.zRef); out.writeShort(this.yRef); - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.volume-coordinates", this.x * this.z * this.y, + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.volume-coordinates", + this.x * this.z * this.y, blockPositionX, blockPositionZ, blockPositionY )); BlockState[] blockDataArray = new BlockState[this.x * this.z * this.y]; @@ -422,11 +443,15 @@ private void stencilSave(Snipe snipe) { } out.writeUTF(blockDataArray[i].getAsString()); } - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.saved", this.filename, volume)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.saved", + this.file.getName(), + volume + )); out.close(); - } catch (IOException exception) { + } catch (IOException e) { messenger.sendMessage(Caption.of("voxelsniper.error.unexpected")); - exception.printStackTrace(); + e.printStackTrace(); } } @@ -446,7 +471,12 @@ private void createParentDirs(File file) throws IOException { public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() - .message(Caption.of("voxelsniper.brush.stencil.loaded", this.filename)) + .message(this.file == null + ? Caption.of("voxelsniper.brush.stencil-list.missing-file") + : Caption.of( + "voxelsniper.brush.stencil.loaded", + this.file.getName() + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stencil/StencilListBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stencil/StencilListBrush.java index 55c779a9..07fe9433 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stencil/StencilListBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/type/stencil/StencilListBrush.java @@ -1,12 +1,17 @@ package com.thevoxelbox.voxelsniper.brush.type.stencil; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.brush.type.AbstractBrush; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.snipe.message.SnipeMessenger; import com.thevoxelbox.voxelsniper.util.material.Materials; +import org.jetbrains.annotations.NotNull; import java.io.BufferedInputStream; import java.io.DataInputStream; @@ -15,18 +20,19 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Scanner; -import java.util.stream.Stream; +@RequireToolkit +@CommandMethod(value = "brush|b stencil_list|stencillist|sl") +@CommandPermission("voxelsniper.brush.stencillist") public class StencilListBrush extends AbstractBrush { private static final String NO_FILE_LOADED = "NoFileLoaded"; private static final int DEFAULT_PASTE_OPTION = 1; private final Map stencilList = new HashMap<>(); - private String filename = NO_FILE_LOADED; + private File file = null; private short x; private short z; private short y; @@ -39,64 +45,72 @@ public class StencilListBrush extends AbstractBrush { @Override public void loadProperties() { this.pasteOption = (byte) getIntegerProperty("default-paste-option", DEFAULT_PASTE_OPTION); + } - File dataFolder = new File(PLUGIN_DATA_FOLDER, "/stencilLists"); - dataFolder.mkdirs(); + @CommandMethod("") + public void onBrush( + final @NotNull Snipe snipe + ) { + super.onBrushCommand(snipe); } - @Override - public void handleCommand(String[] parameters, Snipe snipe) { - SnipeMessenger messenger = snipe.createMessenger(); - String firstParameter = parameters[0]; + @CommandMethod("info") + public void onBrushInfo( + final @NotNull Snipe snipe + ) { + super.onBrushInfoCommand(snipe, Caption.of("voxelsniper.brush.stencil-list.info")); + } - if (firstParameter.equalsIgnoreCase("info")) { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.info")); - } else { - byte pasteOption; - byte pasteParam; - if (firstParameter.equalsIgnoreCase("full")) { - pasteOption = 0; - pasteParam = 1; - } else if (firstParameter.equalsIgnoreCase("fill")) { - pasteOption = 1; - pasteParam = 1; - } else if (firstParameter.equalsIgnoreCase("replace")) { - pasteOption = 2; - pasteParam = 1; - } else { - // Reset to [s] parameter expected. - pasteOption = 1; - pasteParam = 0; - } - if (parameters.length != 1 + pasteParam) { - messenger.sendMessage(Caption.of("voxelsniper.error.brush.invalid-parameters-length")); - return; - } + private void onBrushPasteCommand(Snipe snipe, byte pasteOption, File stencilList) { + this.pasteOption = pasteOption; + this.file = stencilList; - this.pasteOption = pasteOption; - try { - this.filename = parameters[pasteParam]; - File file = new File(PLUGIN_DATA_FOLDER, "/stencilLists/" + this.filename + ".txt"); - if (file.exists()) { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.loaded", this.filename)); - readStencilList(); - } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.missing", this.filename)); - this.filename = NO_FILE_LOADED; - } - } catch (RuntimeException exception) { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.wrong-stencil-list-name")); - } + SnipeMessenger messenger = snipe.createMessenger(); + if (stencilList.exists()) { + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil-list.loaded", + this.file.getName() + )); + readStencilList(); + } else { + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil-list.missing", + this.file.getName() + )); + this.file = null; } } - @Override - public List handleCompletions(String[] parameters, Snipe snipe) { - if (parameters.length == 1) { - String parameter = parameters[0]; - return super.sortCompletions(Stream.of("full", "fill", "replace"), parameter, 0); - } - return super.handleCompletions(parameters, snipe); + @CommandMethod("full ") + public void onBrushFull( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "stencil-list", parserName = "stencil-list-file_parser") File stencilList + ) { + this.onBrushPasteCommand(snipe, (byte) 0, stencilList); + } + + @CommandMethod("fill ") + public void onBrushFill( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "stencil-list", parserName = "stencil-list-file_parser") File stencilList + ) { + this.onBrushPasteCommand(snipe, (byte) 1, stencilList); + } + + @CommandMethod("replace ") + public void onBrushReplace( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "stencil-list", parserName = "stencil-list-file_parser") File stencilList + ) { + this.onBrushPasteCommand(snipe, (byte) 2, stencilList); + } + + @CommandMethod("") + public void onBrushStencillist( + final @NotNull Snipe snipe, + final @NotNull @Argument(value = "stencil-list", parserName = "stencil-list-file_parser") File stencilList + ) { + this.onBrushFill(snipe, stencilList); } @Override @@ -117,7 +131,6 @@ private String readRandomStencil() { private void readStencilList() { stencilList.clear(); - File file = new File(PLUGIN_DATA_FOLDER, "/stencilLists/" + this.filename + ".txt"); if (file.exists()) { try { Scanner scanner = new Scanner(file); @@ -127,24 +140,24 @@ private void readStencilList() { counter++; } scanner.close(); - } catch (FileNotFoundException exception) { - exception.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); } } } private void stencilPaste(Snipe snipe, StencilReader.BlockDataReader blockDataReader) { SnipeMessenger messenger = snipe.createMessenger(); - if (this.filename.matches(NO_FILE_LOADED)) { + if (this.file == null) { messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.missing-file")); return; } String stencilName = this.readRandomStencil(); messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.stencil-loaded", stencilName)); - File file = new File(PLUGIN_DATA_FOLDER, "/stencils/" + stencilName + ".vstencil"); - if (file.exists()) { + File stencil = new File(PLUGIN_DATA_FOLDER, "/stencils/" + stencilName + ".vstencil"); + if (stencil.exists()) { try { - DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); + DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(stencil))); this.x = in.readShort(); this.z = in.readShort(); this.y = in.readShort(); @@ -299,34 +312,41 @@ private void stencilPaste(Snipe snipe, StencilReader.BlockDataReader blockDataRe } } } - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.pasted", this.filename, volume)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.pasted", + stencilName, + volume + )); in.close(); - } catch (IOException exception) { + } catch (IOException e) { if (blockDataReader == StencilReader.BlockDataReader.BLOCK_DATA) { // Tries with some legacy handling for legacy stencils. stencilPaste(snipe, StencilReader.BlockDataReader.LEGACY_IDS); } else { messenger.sendMessage(Caption.of("voxelsniper.error.unexpected")); - exception.printStackTrace(); + e.printStackTrace(); } } } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.wrong-stencil-list-name")); + messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.invalid-stencil-list-name")); } } private void stencilPaste180(Snipe snipe, StencilReader.BlockDataReader blockDataReader) { SnipeMessenger messenger = snipe.createMessenger(); - if (this.filename.matches(NO_FILE_LOADED)) { + if (this.file == null) { messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.missing-file")); return; } String stencilName = this.readRandomStencil(); - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.stencil-loaded", stencilName)); - File file = new File(PLUGIN_DATA_FOLDER, "/stencils/" + stencilName + ".vstencil"); - if (file.exists()) { + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil-list.stencil-loaded", + stencilName + )); + File stencil = new File(PLUGIN_DATA_FOLDER, "/stencils/" + stencilName + ".vstencil"); + if (stencil.exists()) { try { - DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); + DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(stencil))); this.x = in.readShort(); this.z = in.readShort(); this.y = in.readShort(); @@ -481,30 +501,37 @@ private void stencilPaste180(Snipe snipe, StencilReader.BlockDataReader blockDat } } } - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.pasted", this.filename, volume)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.pasted", + stencilName, + volume + )); in.close(); - } catch (IOException exception) { + } catch (IOException e) { if (blockDataReader == StencilReader.BlockDataReader.BLOCK_DATA) { // Tries with some legacy handling for legacy stencils. stencilPaste(snipe, StencilReader.BlockDataReader.LEGACY_IDS); } else { messenger.sendMessage(Caption.of("voxelsniper.error.unexpected")); - exception.printStackTrace(); + e.printStackTrace(); } } } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.wrong-stencil-list-name")); + messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.invalid-stencil-list-name")); } } private void stencilPaste270(Snipe snipe, StencilReader.BlockDataReader blockDataReader) { SnipeMessenger messenger = snipe.createMessenger(); - if (this.filename.matches(NO_FILE_LOADED)) { + if (this.file == null) { messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.missing-file")); return; } String stencilName = this.readRandomStencil(); - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.stencil-loaded", stencilName)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil-list.stencil-loaded", + stencilName + )); File file = new File(PLUGIN_DATA_FOLDER, "/stencils/" + stencilName + ".vstencil"); if (file.exists()) { try { @@ -671,30 +698,37 @@ private void stencilPaste270(Snipe snipe, StencilReader.BlockDataReader blockDat } } } - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.pasted", this.filename, volume)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.pasted", + stencilName, + volume + )); in.close(); - } catch (IOException exception) { + } catch (IOException e) { if (blockDataReader == StencilReader.BlockDataReader.BLOCK_DATA) { // Tries with some legacy handling for legacy stencils. stencilPaste(snipe, StencilReader.BlockDataReader.LEGACY_IDS); } else { messenger.sendMessage(Caption.of("voxelsniper.error.unexpected")); - exception.printStackTrace(); + e.printStackTrace(); } } } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.wrong-stencil-list-name")); + messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.invalid-stencil-list-name")); } } private void stencilPaste90(Snipe snipe, StencilReader.BlockDataReader blockDataReader) { SnipeMessenger messenger = snipe.createMessenger(); - if (this.filename.matches(NO_FILE_LOADED)) { + if (this.file == null) { messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.missing-file")); return; } String stencilName = this.readRandomStencil(); - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.stencil-loaded", stencilName)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil-list.stencil-loaded", + stencilName + )); File file = new File(PLUGIN_DATA_FOLDER, "/stencils/" + stencilName + ".vstencil"); if (file.exists()) { try { @@ -853,19 +887,23 @@ private void stencilPaste90(Snipe snipe, StencilReader.BlockDataReader blockData } } } - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil.pasted", this.filename, volume)); + messenger.sendMessage(Caption.of( + "voxelsniper.brush.stencil.pasted", + stencilName, + volume + )); in.close(); - } catch (IOException exception) { + } catch (IOException e) { if (blockDataReader == StencilReader.BlockDataReader.BLOCK_DATA) { // Tries with some legacy handling for legacy stencils. stencilPaste(snipe, StencilReader.BlockDataReader.LEGACY_IDS); } else { messenger.sendMessage(Caption.of("voxelsniper.error.unexpected")); - exception.printStackTrace(); + e.printStackTrace(); } } } else { - messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.wrong-stencil-list-name")); + messenger.sendMessage(Caption.of("voxelsniper.brush.stencil-list.invalid-stencil-list-name")); } } @@ -888,7 +926,12 @@ private void stencilPasteRotation(Snipe snipe) { public void sendInfo(Snipe snipe) { snipe.createMessageSender() .brushNameMessage() - .message(Caption.of("voxelsniper.brush.stencil-list.loaded", this.filename)) + .message(this.file == null + ? Caption.of("voxelsniper.brush.stencil-list.missing-file") + : Caption.of( + "voxelsniper.brush.stencil-list.loaded", + this.file.getName() + )) .send(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/Command.java b/src/main/java/com/thevoxelbox/voxelsniper/command/Command.java deleted file mode 100644 index 5330be8e..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/Command.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.thevoxelbox.voxelsniper.command; - -import com.fastasyncworldedit.core.configuration.Caption; -import com.sk89q.worldedit.util.formatting.text.serializer.legacy.LegacyComponentSerializer; -import com.thevoxelbox.voxelsniper.command.property.CommandProperties; -import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; -import java.util.Locale; - -public final class Command extends org.bukkit.command.Command { - - private final CommandProperties properties; - private final CommandExecutor executor; - private TabCompleter tabCompleter; - - public Command(CommandProperties properties, CommandExecutor executor) { - super(properties.getName(), properties.getDescriptionOrDefault(), properties.getUsage(), properties.getAliases()); - setupPermission(properties); - this.properties = properties; - this.executor = executor; - if (executor instanceof TabCompleter) { - this.tabCompleter = (TabCompleter) executor; - } - } - - @SuppressWarnings("deprecation") // Deprecated on Paper in favor of adventure - private void setupPermission(CommandProperties properties) { - String permission = properties.getPermission(); - setPermission(permission); - setPermissionMessage( - LegacyComponentSerializer.legacy().serialize( - VoxelSniperText.format(Caption.of("voxelsniper.command.missing-permission", permission), - Locale.ROOT, true - ) - ) - ); - } - - @Override - public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) { - Class senderType = this.properties.getSenderTypeOrDefault(); - if (!senderType.isInstance(sender)) { - VoxelSniperText.print( - sender, - Caption.of("voxelsniper.command.wrong-sender-type", senderType.getSimpleName()) - ); - return true; - } - String permission = this.properties.getPermission(); - if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) { - VoxelSniperText.print(sender, Caption.of("voxelsniper.command.missing-permission", permission)); - return true; - } - this.executor.executeCommand(sender, args); - return true; - } - - @Override - public @NotNull List tabComplete( - @NotNull CommandSender sender, - @NotNull String alias, - @NotNull String[] args, - @Nullable Location location - ) { - Class senderType = this.properties.getSenderTypeOrDefault(); - if (!senderType.isInstance(sender)) { - return Collections.emptyList(); - } - String permission = this.properties.getPermission(); - if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) { - return Collections.emptyList(); - } - if (this.tabCompleter == null) { - return super.tabComplete(sender, alias, args, location); - } - return this.tabCompleter.complete(sender, args); - } - -} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/CommandExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/CommandExecutor.java deleted file mode 100644 index 70f70425..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/CommandExecutor.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.thevoxelbox.voxelsniper.command; - -import org.bukkit.command.CommandSender; - -public interface CommandExecutor { - - void executeCommand(CommandSender sender, String[] arguments); - -} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/CommandRegistry.java b/src/main/java/com/thevoxelbox/voxelsniper/command/CommandRegistry.java index f751daad..8aca6ab1 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/CommandRegistry.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/CommandRegistry.java @@ -1,39 +1,455 @@ package com.thevoxelbox.voxelsniper.command; -import com.thevoxelbox.voxelsniper.command.property.CommandProperties; -import org.bukkit.Server; -import org.bukkit.command.CommandMap; -import org.bukkit.plugin.Plugin; +import cloud.commandframework.Command; +import cloud.commandframework.annotations.AnnotationParser; +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.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.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; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +import com.thevoxelbox.voxelsniper.brush.Brush; +import com.thevoxelbox.voxelsniper.brush.PerformerBrush; +import com.thevoxelbox.voxelsniper.brush.property.BrushProperties; +import com.thevoxelbox.voxelsniper.command.argument.VoxelCommandElementParseException; +import com.thevoxelbox.voxelsniper.command.argument.annotation.DynamicRange; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; +import com.thevoxelbox.voxelsniper.performer.Performer; +import com.thevoxelbox.voxelsniper.performer.property.PerformerProperties; +import com.thevoxelbox.voxelsniper.sniper.Sniper; +import com.thevoxelbox.voxelsniper.sniper.SniperCommander; +import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; +import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; +import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; +import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import com.thevoxelbox.voxelsniper.util.ReflectionsUtils; +import com.thevoxelbox.voxelsniper.util.math.MathHelper; +import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import io.leangen.geantyref.TypeToken; +import org.apache.commons.lang3.ClassUtils; +import org.bukkit.entity.Player; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Parameter; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; public class CommandRegistry { - private final Plugin plugin; + public static final CloudKey SNIPE_KEY = createTypeKey( + "snipe", Snipe.class + ); + public static final CloudKey PERFORMER_SNIPE_KEY = createTypeKey( + "snipe", PerformerSnipe.class + ); + public static final CloudKey TOOLKIT_KEY = createTypeKey( + "toolkit", Toolkit.class + ); - public CommandRegistry(Plugin plugin) { + private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); + private static final String NO_DESCRIPTION = "No Description."; + private static final CommandMeta.Key REQUIRE_TOOLKIT = createMetaKey( + "require-toolkit", + Boolean.class + ); + + private final VoxelSniperPlugin plugin; + private final Map, Map> dynamicRangeFields; + + private BukkitCommandManager commandManager; + private AnnotationParser annotationParser; + + /** + * Create a new command registry. + * + * @param plugin the plugin + */ + public CommandRegistry(VoxelSniperPlugin plugin) { this.plugin = plugin; + this.dynamicRangeFields = new HashMap<>(); } - public void register(CommandProperties properties, CommandExecutor executor) { - Command command = new Command(properties, executor); - register(command); + /** + * Initialize the command registry. + * + * @throws Exception initialization exception + * @since TODO + */ + public void initialize() throws Exception { + this.commandManager = createCommandManager(); + this.annotationParser = createAnnotationParser(this.commandManager); + } + + private BukkitCommandManager createCommandManager() throws Exception { + // Creates the command manager according to the server platform. + PaperCommandManager commandManager = new PaperCommandManager<>( + plugin, + CommandExecutionCoordinator.simpleCoordinator(), + commandSender -> plugin.getSniperRegistry().getSniperCommander(commandSender), + SniperCommander::getCommandSender + ); + + // Handles extra registrations. + commandManager.commandSuggestionProcessor(new FilteringCommandSuggestionProcessor<>( + FilteringCommandSuggestionProcessor.Filter.contains(true).andTrimBeforeLastSpace() + )); + if (commandManager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) { + commandManager.registerAsynchronousCompletions(); + } + + // Handles parameter injectors. + ParameterInjectorRegistry parameterInjectorRegistry = commandManager.parameterInjectorRegistry(); + parameterInjectorRegistry.registerInjector( + Snipe.class, + (context, annotations) -> context.get(SNIPE_KEY) + ); + parameterInjectorRegistry.registerInjector( + PerformerSnipe.class, + (context, annotations) -> context.get(PERFORMER_SNIPE_KEY) + ); + parameterInjectorRegistry.registerInjector( + Toolkit.class, + (context, annotations) -> context.get(TOOLKIT_KEY) + ); + + // 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)) { + return; + } + + Toolkit toolkit; + // Toolkit requirement relies on the custom annotation. + if (command.getCommandMeta() + .get(REQUIRE_TOOLKIT) + .orElse(false)) { + if ((toolkit = sniper.getCurrentToolkit()) == null) { + sniper.print(Caption.of("voxelsniper.command.missing-toolkit")); + ConsumerService.interrupt(); + } + commandContext.store(TOOLKIT_KEY, toolkit); + } else { + toolkit = null; + } + + MethodCommandExecutionHandler.CommandMethodContext methodContext = handler.context(); + Object executorInstance = methodContext.instance(); + if (toolkit == null) { + // Handles the custom dynamic range annotations. + handleDynamicRanges(commandContext, handler, executorInstance); + return; + } + + if (executorInstance instanceof Brush brushExecutor) { + postprocessBrush(commandContext, sniper, toolkit, brushExecutor); + + // Handles the custom dynamic range annotations. + handleDynamicRanges(commandContext, handler, commandContext.get(SNIPE_KEY).getBrush()); + } else if (executorInstance instanceof Performer performerExecutor) { + postprocessPerformer(commandContext, sniper, toolkit, performerExecutor); + + // Handles the custom dynamic range annotations. + handleDynamicRanges(commandContext, handler, commandContext.get(PERFORMER_SNIPE_KEY).getPerformer()); + } + }); + + // Handles exceptions. + commandManager.registerExceptionHandler(InvalidSyntaxException.class, (commander, e) -> + commander.print(Caption.of( + "voxelsniper.command.invalid-command-syntax", + e.getCorrectSyntax() + ))); + commandManager.registerExceptionHandler(InvalidCommandSenderException.class, (commander, e) -> + commander.print(Caption.of( + "voxelsniper.command.invalid-sender-type", + e.getRequiredSender().getSimpleName() + ))); + commandManager.registerExceptionHandler(NoPermissionException.class, (commander, e) -> + commander.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( + "voxelsniper.command.invalid-enum", + ee.getInput(), + VoxelSniperText.formatList( + Arrays.stream(ee.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() + .replace("argument.parse.failure.", "voxelsniper.command.invalid-"), + Arrays.stream(pe.captionVariables()) + .map(CaptionVariable::getValue) + .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(); + }); + + return commandManager; } - public void register(Command command) { - Server server = this.plugin.getServer(); - CommandMap commandMap = getCommandMap(server); - commandMap.register("voxel_sniper", command); + private AnnotationParser createAnnotationParser(BukkitCommandManager commandManager) { + // Creates the annotation parser. + AnnotationParser annotationParser = new AnnotationParser<>( + commandManager, + SniperCommander.class, + parserParameters -> CommandMeta.simple() + .with(CommandMeta.DESCRIPTION, parserParameters + .get(StandardParameters.DESCRIPTION, NO_DESCRIPTION)) + .build() + ); + + // Handles the custom annotations. + annotationParser.registerBuilderModifier( + RequireToolkit.class, + (requireToolkit, builder) -> builder + .senderType(Sniper.class) + .meta(REQUIRE_TOOLKIT, true) + ); + + // Handles the custom command execution method factories. + annotationParser.registerCommandExecutionMethodFactory( + method -> Brush.class.isAssignableFrom(method.getDeclaringClass()), + context -> { + try { + return new VoxelMethodCommandExecutionHandler<>( + context, + commandContext -> commandContext.get(SNIPE_KEY).getBrush() + ); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + ); + annotationParser.registerCommandExecutionMethodFactory( + method -> Performer.class.isAssignableFrom(method.getDeclaringClass()), + context -> { + try { + return new VoxelMethodCommandExecutionHandler<>( + context, + commandContext -> commandContext.get(PERFORMER_SNIPE_KEY).getPerformer() + ); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + ); + + return annotationParser; } - private CommandMap getCommandMap(Server server) { + @SuppressWarnings("unchecked") + private void handleDynamicRanges( + CommandContext commandContext, + MethodCommandExecutionHandler handler, + Object instance + ) { + SniperCommander commander = commandContext.getSender(); + MethodCommandExecutionHandler.CommandMethodContext methodContext = handler.context(); + + // Dynamic range is based on executor instance fields, we must postprocess them manually. + for (Parameter parameter : handler.parameters()) { + Class parameterType; + if (!parameter.isAnnotationPresent(Argument.class) + || (!parameter.isAnnotationPresent(DynamicRange.class) + || !Number.class.isAssignableFrom(ClassUtils.primitiveToWrapper((parameterType = parameter.getType()))))) { + continue; + } + + Argument argumentAnnotation = parameter.getAnnotation(Argument.class); + String argumentName; + if (argumentAnnotation.value().equals(AnnotationParser.INFERRED_ARGUMENT_NAME)) { + argumentName = parameter.getName(); + } else { + argumentName = this.annotationParser.processString(argumentAnnotation.value()); + } + + CommandArgument argument = + (CommandArgument) methodContext.commandArguments().get(argumentName); + double number = commandContext.get(argument).doubleValue(); + + DynamicRange dynamicRangeAnnotation = parameter.getAnnotation(DynamicRange.class); + String min = dynamicRangeAnnotation.min(); + String max = dynamicRangeAnnotation.max(); + double minNumber; + double maxNumber; + try { + minNumber = getDynamicRangeNumber(instance, min).doubleValue(); + maxNumber = getDynamicRangeNumber(instance, max).doubleValue(); + } catch (Throwable e) { + throw new RuntimeException(e); + } + + // Uses type min/max if undefined. + if (Double.isNaN(minNumber)) { + minNumber = MathHelper.minNumberType(parameterType).doubleValue(); + } + if (Double.isNaN(maxNumber)) { + maxNumber = MathHelper.maxNumberType(parameterType).doubleValue(); + } + + if (number < minNumber || number > maxNumber) { + commander.print(Caption.of("voxelsniper.command.invalid-number", + number, minNumber, maxNumber + )); + ConsumerService.interrupt(); + } + } + } + + private Number getDynamicRangeNumber(Object instance, String key) throws Throwable { + if (key.isEmpty()) { + return Double.NaN; + } + try { - Method method = server.getClass().getDeclaredMethod("getCommandMap"); - return (CommandMap) method.invoke(server); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException exception) { - throw new RuntimeException(exception); + return Double.parseDouble(key); + } catch (NumberFormatException ignored) { + Class clazz = instance.getClass(); + MethodHandle getter = dynamicRangeFields.computeIfAbsent(clazz, aClazz -> new HashMap<>()) + .computeIfAbsent(key, aKey -> { + try { + return LOOKUP.unreflectGetter(ReflectionsUtils.getField(clazz, key)); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + }); + + return (double) getter.invoke(instance); + } + } + + private void postprocessBrush( + CommandContext commandContext, Sniper sniper, + Toolkit toolkit, Brush brushExecutor + ) { + Player player = sniper.getPlayer(); + BrushProperties newBrush = brushExecutor.getProperties(); + String permission = newBrush.getPermission(); + if (permission != null && !player.hasPermission(permission)) { + sniper.print(Caption.of("voxelsniper.command.missing-permission", permission)); + ConsumerService.interrupt(); + } + + // Creates and stores the snipe for brush processing. + ToolkitProperties toolkitProperties = toolkit.getProperties(); + Brush brush = toolkit.useBrush(newBrush); + Snipe snipe = new Snipe( + sniper, toolkit, toolkitProperties, + newBrush, brush + ); + commandContext.store(SNIPE_KEY, snipe); + } + + private void postprocessPerformer( + CommandContext commandContext, Sniper sniper, + Toolkit toolkit, Performer performerExecutor + ) { + Brush brush = toolkit.getCurrentBrush(); + if (!(brush instanceof PerformerBrush performerBrush)) { + sniper.print(Caption.of("voxelsniper.command.performer.invalid-brush")); + ConsumerService.interrupt(); + return; } + + // Creates and sets the performer. + PerformerProperties properties = performerExecutor.getProperties(); + Performer performer = toolkit.usePerformer(properties); + performerBrush.setPerformer(performer); + + // Creates and stores the snipe performer for performer brush processing. + ToolkitProperties toolkitProperties = toolkit.getProperties(); + BrushProperties brushProperties = toolkit.getCurrentBrushProperties(); + PerformerSnipe snipe = new PerformerSnipe( + sniper, toolkit, toolkitProperties, + brushProperties, brush, + properties, performer + ); + commandContext.store(PERFORMER_SNIPE_KEY, snipe); + } + + /** + * Register the elements from a voxel command element into the command manager. + * + * @param voxelCommandElement the voxel command element + * @since TODO + */ + public void register(VoxelCommandElement voxelCommandElement) { + annotationParser.parse(voxelCommandElement); + } + + /** + * Return the command manager. + * + * @return the command manager + * @since TODO + */ + public BukkitCommandManager getCommandManager() { + return commandManager; + } + + /** + * Return the annotation parser. + * + * @return the annotation parser + * @since TODO + */ + 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); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/TabCompleter.java b/src/main/java/com/thevoxelbox/voxelsniper/command/TabCompleter.java deleted file mode 100644 index e044fc30..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/TabCompleter.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.thevoxelbox.voxelsniper.command; - -import org.bukkit.command.CommandSender; - -import java.util.List; - -public interface TabCompleter { - - List complete(CommandSender sender, String[] arguments); - -} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelCommandElement.java b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelCommandElement.java new file mode 100644 index 00000000..6b8d36de --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelCommandElement.java @@ -0,0 +1,5 @@ +package com.thevoxelbox.voxelsniper.command; + +public interface VoxelCommandElement { + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelMethodCommandExecutionHandler.java b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelMethodCommandExecutionHandler.java new file mode 100644 index 00000000..e208db93 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelMethodCommandExecutionHandler.java @@ -0,0 +1,53 @@ +package com.thevoxelbox.voxelsniper.command; + +import cloud.commandframework.annotations.MethodCommandExecutionHandler; +import cloud.commandframework.context.CommandContext; +import cloud.commandframework.exceptions.CommandExecutionException; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.util.function.Function; + +public class VoxelMethodCommandExecutionHandler extends MethodCommandExecutionHandler { + + private final MethodHandle methodHandle; + private final Function, Object> executorInstanceSupplier; + + /** + * Create a voxel method command execution handler. + * + * @param context the context + * @throws Exception instantiation exception + * @since TODO + */ + public VoxelMethodCommandExecutionHandler( + CommandMethodContext context, + Function, Object> executorInstanceSupplier + ) throws Exception { + super(context); + this.methodHandle = MethodHandles.lookup().unreflect(context.method()); + this.executorInstanceSupplier = executorInstanceSupplier; + } + + @Override + public void execute(@NonNull CommandContext commandContext) { + try { + this.methodHandle + .bindTo(executorInstanceSupplier.apply(commandContext)) + .invokeWithArguments( + this.createParameterValues( + commandContext, + commandContext.flags(), + super.parameters() + ) + ); + } catch (final Error e) { + throw e; + } catch (final Throwable throwable) { + throw new CommandExecutionException(throwable, commandContext); + } + } + + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractFileArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractFileArgument.java new file mode 100644 index 00000000..5d0ce00d --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractFileArgument.java @@ -0,0 +1,73 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.context.CommandContext; +import cloud.commandframework.exceptions.parsing.NoInputProvidedException; +import com.fastasyncworldedit.core.configuration.Caption; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.sniper.SniperCommander; + +import java.io.File; +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 { + + protected final VoxelSniperPlugin plugin; + protected final Path rootPath; + protected final String extension; + + /** + * Create an abstract file argument. + * + * @param plugin the plugin + * @param rootPath the root path + * @param extension the extension + * @since TODO + */ + public AbstractFileArgument(VoxelSniperPlugin plugin, Path rootPath, String extension) { + this.plugin = plugin; + this.rootPath = rootPath; + this.extension = extension; + + // Initializes the folder if needed. + File rootFile = rootPath.toFile(); + if (!rootFile.exists() && !rootFile.mkdirs()) { + throw new IllegalArgumentException("Invalid file argument root path: " + rootPath); + } + } + + protected List 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(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + protected File parseFile(CommandContext commandContext, Queue inputQueue) { + String input = inputQueue.peek(); + if (input == null) { + throw new NoInputProvidedException(AbstractFileArgument.class, commandContext); + } + + try { + File file = rootPath.resolve(input.endsWith(extension) ? input : input + extension).toFile(); + inputQueue.remove(); + return file; + } catch (Exception e) { + throw new VoxelCommandElementParseException(input, 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 new file mode 100644 index 00000000..c8b78390 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractPatternArgument.java @@ -0,0 +1,81 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.context.CommandContext; +import cloud.commandframework.exceptions.parsing.NoInputProvidedException; +import com.fastasyncworldedit.core.configuration.Caption; +import com.sk89q.worldedit.extension.input.InputParseException; +import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.internal.registry.AbstractFactory; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +import com.thevoxelbox.voxelsniper.brush.property.BrushPattern; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.config.VoxelSniperConfig; +import com.thevoxelbox.voxelsniper.sniper.SniperCommander; +import org.bukkit.command.CommandSender; + +import java.util.List; +import java.util.Locale; +import java.util.Queue; + +public abstract class AbstractPatternArgument implements VoxelCommandElement { + + protected final VoxelSniperPlugin plugin; + protected final VoxelSniperConfig config; + protected final AbstractFactory factory; + protected final String parseExceptionCaptionKey; + + /** + * Create an abstract pattern argument. + * + * @param plugin the plugin + * @param factory the factory + * @param parseExceptionCaptionKey the parse exception caption key + * @since TODO + */ + public AbstractPatternArgument(VoxelSniperPlugin plugin, AbstractFactory factory, String parseExceptionCaptionKey) { + this.plugin = plugin; + this.config = plugin.getVoxelSniperConfig(); + this.factory = factory; + this.parseExceptionCaptionKey = parseExceptionCaptionKey; + } + + protected List suggestPatterns(CommandContext commandContext, String input) { + return factory.getSuggestions(input); + } + + protected BrushPattern parsePattern(CommandContext commandContext, Queue inputQueue) { + String input = inputQueue.peek(); + if (input == null) { + throw new NoInputProvidedException(AbstractPatternArgument.class, commandContext); + } + + SniperCommander commander = commandContext.getSender(); + ParserContext parserContext = commander.createParserContext(); + try { + T pattern = factory.parseFromInput( + input.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( + "voxelsniper.command.not-allowed", + input + )); + } + + inputQueue.remove(); + return new BrushPattern(pattern, input); + } catch (InputParseException e) { + throw new VoxelCommandElementParseException(input, Caption.of( + parseExceptionCaptionKey, + input + )); + } + } + + protected abstract String getPatternResource(String input, T pattern); + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractRegistryArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractRegistryArgument.java new file mode 100644 index 00000000..a574feaa --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/AbstractRegistryArgument.java @@ -0,0 +1,59 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.context.CommandContext; +import cloud.commandframework.exceptions.parsing.NoInputProvidedException; +import com.fastasyncworldedit.core.configuration.Caption; +import com.sk89q.worldedit.registry.Keyed; +import com.sk89q.worldedit.registry.NamespacedRegistry; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.sniper.SniperCommander; + +import java.util.List; +import java.util.Locale; +import java.util.Queue; + +public abstract class AbstractRegistryArgument implements VoxelCommandElement { + + protected final VoxelSniperPlugin plugin; + protected final NamespacedRegistry registry; + protected final String parseExceptionCaptionKey; + + /** + * Create an abstract pattern argument. + * + * @param plugin the plugin + * @param registry the registry + * @param parseExceptionCaptionKey the parse exception caption key + * @since TODO + */ + public AbstractRegistryArgument(VoxelSniperPlugin plugin, NamespacedRegistry registry, String parseExceptionCaptionKey) { + this.plugin = plugin; + this.registry = registry; + this.parseExceptionCaptionKey = parseExceptionCaptionKey; + } + + protected List suggestValues(CommandContext commandContext, String input) { + return registry.getSuggestions(input) + .toList(); + } + + protected T parseValue(CommandContext commandContext, Queue inputQueue) { + String input = inputQueue.peek(); + if (input == null) { + throw new NoInputProvidedException(AbstractRegistryArgument.class, commandContext); + } + + T value = registry.get(input.toLowerCase(Locale.ROOT)); + if (value == null) { + throw new VoxelCommandElementParseException(input, Caption.of( + parseExceptionCaptionKey, + input + )); + } + + inputQueue.remove(); + return value; + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BiomeTypeArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BiomeTypeArgument.java new file mode 100644 index 00000000..70cbfaf7 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BiomeTypeArgument.java @@ -0,0 +1,35 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +import com.sk89q.worldedit.world.biome.BiomeType; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +import com.thevoxelbox.voxelsniper.sniper.SniperCommander; + +import java.util.List; +import java.util.Queue; + +public class BiomeTypeArgument extends AbstractRegistryArgument { + + /** + * Create a biome type argument. + * + * @param plugin the plugin + * @since TODO + */ + public BiomeTypeArgument(VoxelSniperPlugin plugin) { + super(plugin, BiomeType.REGISTRY, "voxelsniper.command.invalid-biome"); + } + + @Suggestions("biome-type_suggestions") + public List 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); + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockArgument.java new file mode 100644 index 00000000..5e8b6d78 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockArgument.java @@ -0,0 +1,42 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.world.block.BaseBlock; +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 BlockArgument extends AbstractPatternArgument { + + /** + * Create a block argument. + * + * @param plugin the plugin + * @since TODO + */ + public BlockArgument(VoxelSniperPlugin plugin) { + super(plugin, WorldEdit.getInstance().getBlockFactory(), "voxelsniper.command.invalid-block"); + } + + @Suggestions("block_suggestions") + public List suggestBlocks(CommandContext commandContext, String input) { + return super.suggestPatterns(commandContext, input); + } + + @Parser(name = "block_parser", suggestions = "block_suggestions") + public BrushPattern parseBlock(CommandContext commandContext, Queue inputQueue) { + return super.parsePattern(commandContext, inputQueue); + } + + @Override + protected String getPatternResource(String input, BaseBlock pattern) { + return pattern.getBlockType().getResource(); + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockTypeArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockTypeArgument.java new file mode 100644 index 00000000..a06b1404 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BlockTypeArgument.java @@ -0,0 +1,35 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +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; + +public class BlockTypeArgument extends AbstractRegistryArgument { + + /** + * Create a block type argument. + * + * @param plugin the plugin + * @since TODO + */ + public BlockTypeArgument(VoxelSniperPlugin plugin) { + super(plugin, BlockType.REGISTRY, "voxelsniper.command.invalid-block-type"); + } + + @Suggestions("block-type_suggestions") + public List 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); + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BrushPropertiesArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BrushPropertiesArgument.java new file mode 100644 index 00000000..3132f254 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/BrushPropertiesArgument.java @@ -0,0 +1,76 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +import cloud.commandframework.exceptions.parsing.NoInputProvidedException; +import com.fastasyncworldedit.core.configuration.Caption; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +import com.thevoxelbox.voxelsniper.brush.BrushRegistry; +import com.thevoxelbox.voxelsniper.brush.property.BrushProperties; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.sniper.SniperCommander; +import org.bukkit.command.CommandSender; + +import java.util.List; +import java.util.Map; +import java.util.Queue; + +public class BrushPropertiesArgument implements VoxelCommandElement { + + private final VoxelSniperPlugin plugin; + private final BrushRegistry brushRegistry; + + /** + * Create a brush properties argument. + * + * @param plugin the plugin + * @since TODO + */ + public BrushPropertiesArgument(VoxelSniperPlugin plugin) { + this.plugin = plugin; + this.brushRegistry = plugin.getBrushRegistry(); + } + + @Suggestions("brush-properties_suggestions") + public List suggestBrushProperties(CommandContext commandContext, String input) { + SniperCommander commander = commandContext.getSender(); + 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(); + } + + @Parser(name = "brush-properties_parser", suggestions = "brush-properties_suggestions") + public BrushProperties parseBrushProperties(CommandContext commandContext, Queue inputQueue) { + String input = inputQueue.peek(); + if (input == null) { + throw new NoInputProvidedException(BrushPropertiesArgument.class, commandContext); + } + + SniperCommander commander = commandContext.getSender(); + BrushProperties properties = brushRegistry.getBrushProperties(input); + if (properties == null) { + throw new VoxelCommandElementParseException(input, Caption.of( + "voxelsniper.command.brush.no-alias", + input + )); + } + CommandSender sender = commander.getCommandSender(); + String permission = properties.getPermission(); + if (permission != null && !sender.hasPermission(permission)) { + throw new VoxelCommandElementParseException(input, Caption.of( + "voxelsniper.command.missing-permission", + permission + )); + } + + 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 new file mode 100644 index 00000000..75d36501 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityClassArgument.java @@ -0,0 +1,88 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +import cloud.commandframework.exceptions.parsing.NoInputProvidedException; +import com.fastasyncworldedit.core.configuration.Caption; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.sniper.Sniper; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Queue; + +public class EntityClassArgument implements VoxelCommandElement { + + public static final List ENTITY_CLASSES = Arrays.stream(EntityType.values()) + .map(EntityType::getEntityClass) + .flatMap(entityClass -> getEntityClassHierarchy(entityClass).stream()) + .distinct() + .map(Class::getCanonicalName) + .toList(); + + public static List> getEntityClassHierarchy(Class entityClass) { + List> entityClassHierarchy = new ArrayList<>(10); + entityClassHierarchy.add(Entity.class); + Class currentClass = entityClass; + + while (currentClass != null && !currentClass.equals(Entity.class)) { + entityClassHierarchy.add(currentClass); + entityClassHierarchy.addAll(Arrays.asList(currentClass.getInterfaces())); + + currentClass = currentClass.getSuperclass(); + } + return entityClassHierarchy; + } + + private final VoxelSniperPlugin plugin; + + /** + * Create a toolkit argument. + * + * @param plugin the plugin + * @since TODO + */ + public EntityClassArgument(VoxelSniperPlugin plugin) { + this.plugin = plugin; + } + + @Suggestions("entity-class_suggestions") + public List suggestEntityClasses(CommandContext commandContext, String input) { + return ENTITY_CLASSES; + } + + @Parser(name = "entity-class_parser", suggestions = "entity-class_suggestions") + public Class parseEntityClass(CommandContext commandContext, Queue inputQueue) { + String input = inputQueue.peek(); + if (input == null) { + throw new NoInputProvidedException(EntityClassArgument.class, commandContext); + } + + Class clazz = getEntityClass(input); + if (clazz == null) { + throw new VoxelCommandElementParseException(input, Caption.of( + "voxelsniper.command.invalid-entity-class", + input + )); + } + + inputQueue.remove(); + return clazz; + } + + @SuppressWarnings("unchecked") + private Class getEntityClass(String path) { + try { + Class clazz = Class.forName(path); + return Entity.class.isAssignableFrom(clazz) ? (Class) clazz : null; + } catch (ClassNotFoundException e) { + return null; + } + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityTypeArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityTypeArgument.java new file mode 100644 index 00000000..2c9f0eac --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/EntityTypeArgument.java @@ -0,0 +1,35 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +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; + +public class EntityTypeArgument extends AbstractRegistryArgument { + + /** + * Create an entity type argument. + * + * @param plugin the plugin + * @since TODO + */ + public EntityTypeArgument(VoxelSniperPlugin plugin) { + super(plugin, EntityType.REGISTRY, "voxelsniper.command.invalid-entity"); + } + + @Suggestions("entity-type_suggestions") + public List 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); + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/PatternArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/PatternArgument.java new file mode 100644 index 00000000..acacc0a1 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/PatternArgument.java @@ -0,0 +1,41 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +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 { + + /** + * Create a pattern argument. + * + * @param plugin the plugin + * @since TODO + */ + public PatternArgument(VoxelSniperPlugin plugin) { + super(plugin, plugin.getPatternParser(), "voxelsniper.command.invalid-pattern"); + } + + @Suggestions("pattern_suggestions") + public List suggestPatterns(CommandContext commandContext, String input) { + return super.suggestPatterns(commandContext, input); + } + + @Parser(name = "pattern_parser", suggestions = "pattern_suggestions") + public BrushPattern parsePattern(CommandContext commandContext, Queue inputQueue) { + return super.parsePattern(commandContext, inputQueue); + } + + @Override + protected String getPatternResource(String input, Pattern pattern) { + return input; + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/SignFileArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/SignFileArgument.java new file mode 100644 index 00000000..874e424e --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/SignFileArgument.java @@ -0,0 +1,35 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +import com.thevoxelbox.voxelsniper.sniper.SniperCommander; + +import java.io.File; +import java.util.List; +import java.util.Queue; + +public class SignFileArgument extends AbstractFileArgument { + + /** + * Create a sign file argument. + * + * @param plugin the plugin + * @since TODO + */ + public SignFileArgument(VoxelSniperPlugin plugin) { + super(plugin, plugin.getDataFolder().toPath().resolve("signs/"), ".vsign"); + } + + @Suggestions("sign-file_suggestions") + public List 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); + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilFileArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilFileArgument.java new file mode 100644 index 00000000..ec51f21c --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilFileArgument.java @@ -0,0 +1,35 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +import com.thevoxelbox.voxelsniper.sniper.SniperCommander; + +import java.io.File; +import java.util.List; +import java.util.Queue; + +public class StencilFileArgument extends AbstractFileArgument { + + /** + * Create a stencil file argument. + * + * @param plugin the plugin + * @since TODO + */ + public StencilFileArgument(VoxelSniperPlugin plugin) { + super(plugin, plugin.getDataFolder().toPath().resolve("stencils/"), ".vstencil"); + } + + @Suggestions("stencil-file_suggestions") + public List 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); + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilListFileArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilListFileArgument.java new file mode 100644 index 00000000..94981b50 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/StencilListFileArgument.java @@ -0,0 +1,35 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +import com.thevoxelbox.voxelsniper.sniper.SniperCommander; + +import java.io.File; +import java.util.List; +import java.util.Queue; + +public class StencilListFileArgument extends AbstractFileArgument { + + /** + * Create a stencil file argument. + * + * @param plugin the plugin + * @since TODO + */ + public StencilListFileArgument(VoxelSniperPlugin plugin) { + super(plugin, plugin.getDataFolder().toPath().resolve("stencilLists/"), ".txt"); + } + + @Suggestions("stencil-list-file_suggestions") + public List 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); + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/ToolkitArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/ToolkitArgument.java new file mode 100644 index 00000000..3173a102 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/ToolkitArgument.java @@ -0,0 +1,59 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +import cloud.commandframework.exceptions.parsing.NoInputProvidedException; +import com.fastasyncworldedit.core.configuration.Caption; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.sniper.Sniper; +import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; + +import java.util.List; +import java.util.Queue; + +public class ToolkitArgument implements VoxelCommandElement { + + private final VoxelSniperPlugin plugin; + + /** + * Create a toolkit argument. + * + * @param plugin the plugin + * @since TODO + */ + public ToolkitArgument(VoxelSniperPlugin plugin) { + this.plugin = plugin; + } + + @Suggestions("toolkit_suggestions") + public List suggestToolkits(CommandContext commandContext, String input) { + Sniper sniper = commandContext.getSender(); + return sniper.getToolkits().stream() + .filter(toolkit -> !toolkit.isDefault()) + .map(Toolkit::getToolkitName) + .toList(); + } + + @Parser(suggestions = "toolkit_suggestions") + public Toolkit parseToolkit(CommandContext commandContext, Queue inputQueue) { + String input = inputQueue.peek(); + if (input == null) { + throw new NoInputProvidedException(ToolkitArgument.class, commandContext); + } + + Sniper sniper = commandContext.getSender(); + Toolkit toolkit = sniper.getToolkit(input); + if (toolkit == null) { + throw new VoxelCommandElementParseException(input, Caption.of( + "voxelsniper.command.toolkit.not-found", + input + )); + } + + inputQueue.remove(); + return toolkit; + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/VoxelCommandElementParseException.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/VoxelCommandElementParseException.java new file mode 100644 index 00000000..4242e8c6 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/VoxelCommandElementParseException.java @@ -0,0 +1,47 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import com.sk89q.worldedit.util.formatting.text.Component; + +import java.io.Serial; + +public class VoxelCommandElementParseException extends IllegalArgumentException { + + @Serial + private static final long serialVersionUID = -2010839991649577883L; + + private final String input; + private final Component errorMessage; + + /** + * Creates a voxel comment element parse exception. + * + * @param input the input + * @param errorMessage the error message + * @since TODO + */ + public VoxelCommandElementParseException(String input, Component errorMessage) { + this.input = input; + this.errorMessage = errorMessage; + } + + /** + * Return the input. + * + * @return the input + * @since TODO + */ + public String getInput() { + return input; + } + + /** + * Return the error message. + * + * @return the error message + * @since TODO + */ + public Component getErrorMessage() { + return errorMessage; + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/VoxelListBlocksArgument.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/VoxelListBlocksArgument.java new file mode 100644 index 00000000..9848abbf --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/VoxelListBlocksArgument.java @@ -0,0 +1,91 @@ +package com.thevoxelbox.voxelsniper.command.argument; + +import cloud.commandframework.annotations.parsers.Parser; +import cloud.commandframework.annotations.suggestions.Suggestions; +import cloud.commandframework.context.CommandContext; +import cloud.commandframework.exceptions.parsing.NoInputProvidedException; +import com.fastasyncworldedit.core.configuration.Caption; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.input.InputParseException; +import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; +import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; +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 { + + private final VoxelSniperPlugin plugin; + + /** + * Create a voxel list blocks argument. + * + * @param plugin the plugin + * @since TODO + */ + public VoxelListBlocksArgument(VoxelSniperPlugin plugin) { + this.plugin = plugin; + } + + @Suggestions("voxel-list-block_suggestions") + public List suggestVoxelListBlocks(CommandContext commandContext, String input) { + return WorldEdit.getInstance().getBlockFactory() + .getSuggestions(input.startsWith("-") ? input.substring(1) : input).stream() + .flatMap(id -> Stream.of(id, "-" + id)) + .toList(); + } + + @Parser(suggestions = "voxel-list-block_suggestions") + public BlockWrapper[] parseVoxelListBlock(CommandContext commandContext, Queue inputQueue) { + if (inputQueue.isEmpty()) { + throw new NoInputProvidedException(VoxelListBlocksArgument.class, commandContext); + } + + BlockWrapper[] blockWrappers = new BlockWrapper[inputQueue.size()]; + int i = 0; + while (!inputQueue.isEmpty()) { + String input = inputQueue.peek(); + SniperCommander commander = commandContext.getSender(); + ParserContext parserContext = commander.createParserContext(); + + boolean remove = input.startsWith("-"); + if (remove) { + input = input.substring(1); + } + try { + BaseBlock baseBlock = WorldEdit.getInstance().getBlockFactory().parseFromInput( + input.toLowerCase(Locale.ROOT), + parserContext + ); + + inputQueue.remove(); + blockWrappers[i++] = new BlockWrapper(baseBlock.toBlockState(), remove); + } catch (InputParseException e) { + throw new VoxelCommandElementParseException(input, Caption.of( + "voxelsniper.command.invalid-block-type", + input + )); + } + } + + return blockWrappers; + } + + /** + * Voxel list block wrapper. + * + * @param block the block + * @param remove whether the block should be removed or not + * @since TODO + */ + public record BlockWrapper(BlockState block, boolean remove) { + + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/annotation/DynamicRange.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/annotation/DynamicRange.java new file mode 100644 index 00000000..d3f5bb40 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/annotation/DynamicRange.java @@ -0,0 +1,35 @@ +package com.thevoxelbox.voxelsniper.command.argument.annotation; + +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Used to specify min and max field values of numerical. + * + * @since TODO + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface DynamicRange { + + /** + * Return the minimum field value accepted by the parser. + * + * @return minimum field value + * @since TODO + */ + @NonNull String min() default ""; + + /** + * Return the maximum field value accepted by the parser. + * + * @return maximum field value + * @since TODO + */ + @NonNull String max() default ""; + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/argument/annotation/RequireToolkit.java b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/annotation/RequireToolkit.java new file mode 100644 index 00000000..1b0e84a7 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/argument/annotation/RequireToolkit.java @@ -0,0 +1,17 @@ +package com.thevoxelbox.voxelsniper.command.argument.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Used to specify toolkit requirement. + * + * @since TODO + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +public @interface RequireToolkit { + +} 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 620fda0e..0e1ecbb6 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushExecutor.java @@ -1,153 +1,73 @@ 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; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.configuration.Caption; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; -import com.thevoxelbox.voxelsniper.brush.Brush; -import com.thevoxelbox.voxelsniper.brush.BrushRegistry; import com.thevoxelbox.voxelsniper.brush.property.BrushProperties; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; -import com.thevoxelbox.voxelsniper.command.TabCompleter; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.config.VoxelSniperConfig; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; -import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.Messenger; -import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -public class BrushExecutor implements CommandExecutor, TabCompleter { +@RequireToolkit +@CommandMethod(value = "brush|b") +@CommandDescription("Brush executor.") +@CommandPermission("voxelsniper.sniper") +public class BrushExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; + private final VoxelSniperConfig config; public BrushExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; + this.config = this.plugin.getVoxelSniperConfig(); } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - VoxelSniperText.print(sender, Caption.of("voxelsniper.command.missing-sniper")); - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - sniper.print(Caption.of("voxelsniper.command.missing-toolkit")); - return; - } - ToolkitProperties toolkitProperties = toolkit.getProperties(); - if (arguments.length == 0) { - BrushProperties previousBrushProperties = toolkit.getPreviousBrushProperties(); - String permission = previousBrushProperties.getPermission(); - if (permission != null && !player.hasPermission(permission)) { - sniper.print(Caption.of("voxelsniper.command.missing-permission", permission)); - return; - } - toolkit.useBrush(previousBrushProperties); - sniper.sendInfo(sender, true); - return; - } - String firstArgument = arguments[0]; - Integer brushSize = NumericParser.parseInteger(firstArgument); - if (brushSize != null) { - if (brushSize < 0) { - sniper.print(Caption.of("voxelsniper.command.brush.invalid-size")); - return; - } - VoxelSniperConfig config = this.plugin.getVoxelSniperConfig(); - int litesniperMaxBrushSize = config.getLitesniperMaxBrushSize(); - Messenger messenger = new Messenger(plugin, sender); - if (!sender.hasPermission("voxelsniper.ignorelimitations") && brushSize > litesniperMaxBrushSize) { - sniper.print(Caption.of("voxelsniper.command.brush.restricted-size", litesniperMaxBrushSize)); - toolkitProperties.setBrushSize(litesniperMaxBrushSize); - messenger.sendBrushSizeMessage(litesniperMaxBrushSize); - } else { - toolkitProperties.setBrushSize(brushSize); - messenger.sendBrushSizeMessage(brushSize); - } - return; - } - BrushRegistry brushRegistry = this.plugin.getBrushRegistry(); - BrushProperties newBrush = brushRegistry.getBrushProperties(firstArgument); - if (newBrush == null) { - sniper.print(Caption.of("voxelsniper.command.brush.no-alias", firstArgument)); - return; - } - String permission = newBrush.getPermission(); + @CommandMethod("") + public void onBrush( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit + ) { + Player player = sniper.getPlayer(); + BrushProperties previousBrushProperties = toolkit.getPreviousBrushProperties(); + String permission = previousBrushProperties.getPermission(); if (permission != null && !player.hasPermission(permission)) { sniper.print(Caption.of("voxelsniper.command.missing-permission", permission)); return; } - Brush brush = toolkit.useBrush(newBrush); - if (arguments.length > 1) { - Snipe snipe = new Snipe(sniper, toolkit, toolkitProperties, newBrush, brush); - String[] parameters = Arrays.copyOfRange(arguments, 1, arguments.length); - brush.handleCommand(parameters, snipe); - return; - } - sniper.sendInfo(sender, true); - } - - @Override - public List complete(CommandSender sender, String[] arguments) { - if (arguments.length == 1) { - String argument = arguments[0]; - String argumentLowered = argument.toLowerCase(Locale.ROOT); - return this.plugin.getBrushRegistry().getBrushesProperties().entrySet().stream() - .filter(entry -> { - String permission = entry.getValue().getPermission(); - return permission == null || permission.isEmpty() || sender.hasPermission(permission); - }) - .map(Map.Entry::getKey) - .filter(brushAlias -> brushAlias.startsWith(argumentLowered)) - .toList(); - } - if (arguments.length > 1) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return Collections.emptyList(); - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - return Collections.emptyList(); - } - - String firstArgument = arguments[0]; - BrushRegistry brushRegistry = this.plugin.getBrushRegistry(); - BrushProperties newBrush = brushRegistry.getBrushProperties(firstArgument); - if (newBrush == null) { - return Collections.emptyList(); - } - - String permission = newBrush.getPermission(); - if (permission != null && !player.hasPermission(permission)) { - return Collections.emptyList(); - } - - Brush brush = toolkit.useBrush(newBrush); - ToolkitProperties toolkitProperties = toolkit.getProperties(); + toolkit.useBrush(previousBrushProperties); + sniper.sendInfo(true); + } - Snipe snipe = new Snipe(sniper, toolkit, toolkitProperties, newBrush, brush); - String[] parameters = Arrays.copyOfRange(arguments, 1, arguments.length); + @CommandMethod("") + public void onBrushSize( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit, + final @Argument("size") @Range(min = "0", max = "500") int size + ) { + ToolkitProperties toolkitProperties = toolkit.getProperties(); + Player player = sniper.getPlayer(); - return brush.handleCompletions(parameters, snipe); + int litesniperMaxBrushSize = config.getLitesniperMaxBrushSize(); + Messenger messenger = new Messenger(plugin, player); + if (!player.hasPermission("voxelsniper.ignorelimitations") && size > litesniperMaxBrushSize) { + sniper.print(Caption.of("voxelsniper.command.brush.restricted-size", litesniperMaxBrushSize)); + toolkitProperties.setBrushSize(litesniperMaxBrushSize); + messenger.sendBrushSizeMessage(litesniperMaxBrushSize); + } else { + toolkitProperties.setBrushSize(size); + messenger.sendBrushSizeMessage(size); } - return Collections.emptyList(); } } 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 0c223fe1..979ea381 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushToolkitExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/BrushToolkitExecutor.java @@ -1,28 +1,27 @@ 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; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; -import com.thevoxelbox.voxelsniper.command.TabCompleter; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolAction; import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; -import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import org.jetbrains.annotations.NotNull; -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.stream.Stream; - -public class BrushToolkitExecutor implements CommandExecutor, TabCompleter { +@CommandMethod(value = "brush_toolkit|brushtoolkit|btool") +@CommandDescription("Brush toolkit.") +@CommandPermission("voxelsniper.sniper") +public class BrushToolkitExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; @@ -30,108 +29,74 @@ public BrushToolkitExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - VoxelSniperText.print(sender, Caption.of("voxelsniper.command.missing-sniper")); - return; - } - int length = arguments.length; - if (length == 0) { + @CommandMethod("assign ") + public void onBrushToolkitAssign( + final @NotNull Sniper sniper, + final @NotNull @Argument("action") ToolAction action, + final @NotNull @Argument("toolkit-name") String name + ) { + Player player = sniper.getPlayer(); + PlayerInventory inventory = player.getInventory(); + ItemStack itemInHand = inventory.getItemInMainHand(); + ItemType itemType = BukkitAdapter.asItemType(itemInHand.getType()); + if (itemType == null || itemType == ItemTypes.AIR) { sniper.print(Caption.of("voxelsniper.command.toolkit.assign-help")); - sniper.print(Caption.of("voxelsniper.command.toolkit.remove-help-1")); - sniper.print(Caption.of("voxelsniper.command.toolkit.remove-help-2")); return; } - String firstArgument = arguments[0]; - if (length == 3 && firstArgument.equalsIgnoreCase("assign")) { - ToolAction action = ToolAction.getToolAction(arguments[1]); - if (action == null) { - sniper.print(Caption.of("voxelsniper.command.toolkit.assign-help")); - return; - } - PlayerInventory inventory = player.getInventory(); - ItemStack itemInHand = inventory.getItemInMainHand(); - ItemType itemType = BukkitAdapter.asItemType(itemInHand.getType()); - if (itemType == ItemTypes.AIR) { - sniper.print(Caption.of("voxelsniper.command.toolkit.assign-help")); - return; - } - String toolkitName = arguments[2]; - Toolkit toolkit = sniper.getToolkit(toolkitName); - if (toolkit == null) { - toolkit = new Toolkit(toolkitName); - } - toolkit.addToolAction(itemType, action); - sniper.addToolkit(toolkit); - sniper.print(Caption.of("voxelsniper.command.toolkit.assigned", itemInHand.getType().name(), - toolkitName, action.name() - )); - return; + + Toolkit toolkit = sniper.getToolkit(name); + if (toolkit == null) { + toolkit = new Toolkit(name); } - if (length == 2 && firstArgument.equalsIgnoreCase("remove")) { - Toolkit toolkit = sniper.getToolkit(arguments[1]); - if (toolkit == null) { - sniper.print(Caption.of("voxelsniper.command.toolkit.not-found", arguments[1])); - return; - } - sniper.removeToolkit(toolkit); + if (toolkit.isDefault()) { + sniper.print(Caption.of("voxelsniper.command.toolkit.default-tool")); return; } - if (length == 1 && firstArgument.equalsIgnoreCase("remove")) { - PlayerInventory inventory = player.getInventory(); - ItemStack itemInHand = inventory.getItemInMainHand(); - ItemType itemType = BukkitAdapter.asItemType(itemInHand.getType()); - if (itemType == ItemTypes.AIR) { - sniper.print(Caption.of("voxelsniper.command.toolkit.empty-hands")); - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - sniper.print(Caption.of("voxelsniper.command.toolkit.default-tool")); - return; - } - toolkit.removeToolAction(itemType); - } - } + toolkit.addToolAction(itemType, action); + sniper.addToolkit(toolkit); + sniper.print(Caption.of("voxelsniper.command.toolkit.assigned", itemType.getRichName(), + toolkit.getToolkitName(), action.name() + )); + } - @Override - public List complete(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null || arguments.length == 0) { - return Collections.emptyList(); + @CommandMethod("remove ") + public void onBrushToolkitRemove( + final @NotNull Sniper sniper, + final @NotNull @Argument("toolkit") Toolkit toolkit + ) { + if (toolkit.isDefault()) { + sniper.print(Caption.of("voxelsniper.command.toolkit.default-tool")); + return; } - String firstArgument = arguments[0]; - if (arguments.length == 1) { - String argumentLowered = firstArgument.toLowerCase(Locale.ROOT); - return Stream.of("assign", "remove") - .filter(subCommand -> subCommand.startsWith(argumentLowered)) - .toList(); - } - if (arguments.length == 2 && firstArgument.equalsIgnoreCase("assign")) { - String argument = arguments[1]; - String argumentLowered = argument.toLowerCase(Locale.ROOT); - return Stream.of("arrow", "gunpowder") - .filter(tool -> tool.startsWith(argumentLowered)) - .toList(); + sniper.removeToolkit(toolkit); + sniper.print(Caption.of("voxelsniper.command.toolkit.removed", toolkit.getToolkitName())); + } + + @CommandMethod("remove") + public void onBrushToolkitRemove( + final @NotNull Sniper sniper + ) { + Player player = sniper.getPlayer(); + PlayerInventory inventory = player.getInventory(); + ItemStack itemInHand = inventory.getItemInMainHand(); + ItemType itemType = BukkitAdapter.asItemType(itemInHand.getType()); + if (itemType == null || itemType == ItemTypes.AIR) { + sniper.print(Caption.of("voxelsniper.command.toolkit.empty-hands")); + return; } - if (arguments.length == 2 && firstArgument.equalsIgnoreCase("remove") || - arguments.length == 3 && firstArgument.equalsIgnoreCase("assign")) { - String argument = arguments[arguments.length - 1]; - String argumentLowered = argument.toLowerCase(Locale.ROOT); - return sniper.getToolkits().stream() - .map(Toolkit::getToolkitName) - .filter(toolkitName -> toolkitName.startsWith(argumentLowered)) - .toList(); + + Toolkit toolkit = sniper.getCurrentToolkit(); + if (toolkit == null || toolkit.isDefault()) { + sniper.print(Caption.of("voxelsniper.command.toolkit.default-tool")); + return; } - return Collections.emptyList(); + + toolkit.removeToolAction(itemType); + sniper.print(Caption.of("voxelsniper.command.toolkit.unassigned", itemType.getRichName(), + toolkit.getToolkitName() + )); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/DefaultExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/DefaultExecutor.java index fe4b878b..d44e5dde 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/DefaultExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/DefaultExecutor.java @@ -1,16 +1,21 @@ package com.thevoxelbox.voxelsniper.command.executor; +import cloud.commandframework.annotations.CommandDescription; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; -import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; -public class DefaultExecutor implements CommandExecutor { +@RequireToolkit +@CommandMethod(value = "default|d") +@CommandDescription("VoxelSniper Default.") +@CommandPermission("voxelsniper.goto") +public class DefaultExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; @@ -18,20 +23,11 @@ public DefaultExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - VoxelSniperText.print(sender, Caption.of("voxelsniper.command.missing-sniper")); - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - sniper.print(Caption.of("voxelsniper.command.missing-toolkit")); - return; - } + @CommandMethod("") + public void onDefault( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit + ) { toolkit.reset(); sniper.print(Caption.of("voxelsniper.command.default.reset")); } 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 cda10c9d..2563dbf8 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/GotoExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/GotoExecutor.java @@ -1,16 +1,22 @@ 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; import com.fastasyncworldedit.core.configuration.Caption; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; -public class GotoExecutor implements CommandExecutor { +@CommandMethod(value = "goto") +@CommandDescription("Warp to the specified coordinates.") +@CommandPermission("voxelsniper.goto") +public class GotoExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; @@ -18,24 +24,15 @@ public GotoExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return; - } + @CommandMethod(" ") + public void onGoto( + final @NotNull Sniper sniper, + final @Argument("x") int x, + final @Argument("z") int z + ) { + Player player = sniper.getPlayer(); + World world = player.getWorld(); - int x; - int z; - try { - x = Integer.parseInt(arguments[0]); - z = Integer.parseInt(arguments[1]); - } catch (NumberFormatException | ArrayIndexOutOfBoundsException ignored) { - sniper.print(Caption.of("voxelsniper.command.goto.invalid-syntax", arguments[0], arguments[1])); - return; - } player.teleport(new Location(world, x, world.getHighestBlockYAt(x, z), z)); sniper.print(Caption.of("voxelsniper.command.goto.woosh")); } 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 0ad93d5b..4156803a 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/PaintExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/PaintExecutor.java @@ -1,27 +1,22 @@ package com.thevoxelbox.voxelsniper.command.executor; -import com.fastasyncworldedit.core.configuration.Caption; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandDescription; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; -import com.thevoxelbox.voxelsniper.command.TabCompleter; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; import com.thevoxelbox.voxelsniper.util.ArtHelper; import org.bukkit.Art; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Locale; - -public class PaintExecutor implements CommandExecutor, TabCompleter { - - private static final List ART_NAMES = Arrays.stream(Art.values()) - .map(Art::name) - .map(String::toLowerCase) - .toList(); +@CommandMethod(value = "paint") +@CommandDescription("Change the selected painting to another painting.") +@CommandPermission("voxelsniper.sniper") +public class PaintExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; @@ -29,40 +24,29 @@ public PaintExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return; - } - if (arguments.length == 1) { - if (arguments[0].equalsIgnoreCase("back")) { - ArtHelper.paintAuto(player, true); - } else { - Art art = Art.getByName(arguments[0]); - if (art == null) { - sniper.print(Caption.of("voxelsniper.command.paint.invalid-art", arguments[0])); - return; - } - ArtHelper.paint(player, art); - } - } else { - ArtHelper.paintAuto(player, false); - } + @CommandMethod("") + public void onPaint( + final @NotNull Sniper sniper + ) { + Player player = sniper.getPlayer(); + ArtHelper.paintAuto(player, false); + } + + @CommandMethod("back") + public void onPaintBack( + final @NotNull Sniper sniper + ) { + Player player = sniper.getPlayer(); + ArtHelper.paintAuto(player, true); } - @Override - public List complete(CommandSender sender, String[] arguments) { - if (arguments.length == 1) { - String argument = arguments[0]; - String argumentLowered = argument.toLowerCase(Locale.ROOT); - return ART_NAMES.stream() - .filter(artName -> artName.startsWith(argumentLowered)) - .toList(); - } - return Collections.emptyList(); + @CommandMethod("") + public void onPaintArt( + final @NotNull Sniper sniper, + final @Nullable @Argument("art") Art art + ) { + Player player = sniper.getPlayer(); + ArtHelper.paint(player, art); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/PerformerExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/PerformerExecutor.java index 6c2832e3..31160e3c 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/PerformerExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/PerformerExecutor.java @@ -1,21 +1,23 @@ package com.thevoxelbox.voxelsniper.command.executor; +import cloud.commandframework.annotations.CommandDescription; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; import com.thevoxelbox.voxelsniper.brush.Brush; import com.thevoxelbox.voxelsniper.brush.PerformerBrush; -import com.thevoxelbox.voxelsniper.brush.property.BrushProperties; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; -import com.thevoxelbox.voxelsniper.performer.PerformerRegistry; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; -import com.thevoxelbox.voxelsniper.sniper.snipe.Snipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; -import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; -public class PerformerExecutor implements CommandExecutor { +@RequireToolkit +@CommandMethod(value = "performer|perf|p") +@CommandDescription("Performer executor.") +@CommandPermission("voxelsniper.sniper") +public class PerformerExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; @@ -23,32 +25,18 @@ public PerformerExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - return; - } - ToolkitProperties toolkitProperties = toolkit.getProperties(); - if (toolkitProperties == null) { - return; - } - BrushProperties brushProperties = toolkit.getCurrentBrushProperties(); + @CommandMethod("") + public void onPerformer( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit + ) { Brush brush = toolkit.getCurrentBrush(); - if (!(brush instanceof PerformerBrush performer)) { + if (!(brush instanceof PerformerBrush)) { sniper.print(Caption.of("voxelsniper.command.performer.invalid-brush")); return; } - String[] parameters = arguments.length == 0 ? new String[]{"m"} : arguments; - Snipe snipe = new Snipe(sniper, toolkit, toolkitProperties, brushProperties, brush); - PerformerRegistry performerRegistry = this.plugin.getPerformerRegistry(); - performer.handlePerformerCommand(parameters, snipe, performerRegistry); + + sniper.sendInfo(true); } } 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 ce5302cf..171a94cb 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelCenterExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelCenterExecutor.java @@ -1,17 +1,24 @@ package com.thevoxelbox.voxelsniper.command.executor; -import com.fastasyncworldedit.core.configuration.Caption; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandDescription; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.Messenger; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; -public class VoxelCenterExecutor implements CommandExecutor { +@RequireToolkit +@CommandMethod(value = "voxel_center|voxelcenter|vc") +@CommandDescription("VoxelCenter & VoxelCentroid input.") +@CommandPermission("voxelsniper.sniper") +public class VoxelCenterExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; @@ -19,34 +26,17 @@ public VoxelCenterExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - return; - } + @CommandMethod("
") + public void onVoxelCenter( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit, + final @Argument("center") int center + ) { + Player player = sniper.getPlayer(); ToolkitProperties toolkitProperties = toolkit.getProperties(); - if (toolkitProperties == null) { - return; - } - int center; - try { - center = Integer.parseInt(arguments[0]); - } catch (NumberFormatException ignored) { - sniper.print(Caption.of("voxelsniper.command.voxel-center.invalid-input", arguments[0])); - return; - } catch (ArrayIndexOutOfBoundsException ignored) { - sniper.print(Caption.of("voxelsniper.command.voxel-center.invalid-input-none")); - return; - } toolkitProperties.setCylinderCenter(center); - Messenger messenger = new Messenger(plugin, sender); + + Messenger messenger = new Messenger(plugin, player); messenger.sendCylinderCenterMessage(center); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelChunkExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelChunkExecutor.java index 5f40f860..bae55ec0 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelChunkExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelChunkExecutor.java @@ -1,16 +1,21 @@ package com.thevoxelbox.voxelsniper.command.executor; +import cloud.commandframework.annotations.CommandDescription; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.fastasyncworldedit.core.configuration.Caption; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; -public class VoxelChunkExecutor implements CommandExecutor { +@CommandMethod(value = "voxel_chunk|voxelchunk|vchunk") +@CommandDescription("Update the chunk you are standing in.") +@CommandPermission("voxelsniper.sniper") +public class VoxelChunkExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; @@ -18,14 +23,11 @@ public VoxelChunkExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return; - } + @CommandMethod("") + public void onVoxelChunk( + final @NotNull Sniper sniper + ) { + Player player = sniper.getPlayer(); World world = player.getWorld(); Location location = player.getLocation(); int x = location.getBlockX(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelExecutor.java index 0d6b78d8..b862ad10 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelExecutor.java @@ -1,112 +1,82 @@ 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; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.bukkit.BukkitPlayer; -import com.sk89q.worldedit.extension.input.InputParseException; -import com.sk89q.worldedit.extension.input.ParserContext; -import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; import com.thevoxelbox.voxelsniper.brush.property.BrushPattern; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; -import com.thevoxelbox.voxelsniper.command.TabCompleter; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.config.VoxelSniperConfig; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; import com.thevoxelbox.voxelsniper.sniper.toolkit.BlockTracer; import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.Messenger; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.List; -import java.util.Locale; - -public class VoxelExecutor implements CommandExecutor, TabCompleter { +@RequireToolkit +@CommandMethod(value = "voxel|v|voxel_ink|voxelink|vi") +@CommandDescription("Voxel input.") +@CommandPermission("voxelsniper.sniper") +public class VoxelExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; + private final VoxelSniperConfig config; public VoxelExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; + this.config = plugin.getVoxelSniperConfig(); } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - return; - } + @CommandMethod("[pattern]") + public void onVoxel( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit, + final @Nullable @Argument(value = "pattern", parserName = "pattern_parser") BrushPattern brushPattern + ) { + Player player = sniper.getPlayer(); ToolkitProperties toolkitProperties = toolkit.getProperties(); - if (toolkitProperties == null) { - return; - } - Messenger messenger = new Messenger(plugin, sender); - VoxelSniperConfig config = this.plugin.getVoxelSniperConfig(); - List liteSniperRestrictedPatterns = config.getLitesniperRestrictedMaterials(); - if (arguments.length == 0) { + + if (brushPattern == null) { BlockTracer blockTracer = toolkitProperties.createBlockTracer(player); BlockVector3 targetBlock = blockTracer.getTargetBlock(); if (targetBlock != null) { - BlockType targetBlockType = BukkitAdapter.asBlockType( + BlockState targetBlockState = BukkitAdapter.adapt( player.getWorld().getBlockAt( targetBlock.getX(), targetBlock.getY(), targetBlock.getZ() - ).getType()); - - if (targetBlockType == null) { - sniper.print(Caption.of("voxelsniper.command.invalid-block")); + ).getBlockData()); + if (targetBlockState == null) { + sniper.print(Caption.of("voxelsniper.command.invalid-target-block")); return; } - if (!sender.hasPermission("voxelsniper.ignorelimitations") && liteSniperRestrictedPatterns.contains( - targetBlockType.getResource())) { + + BlockType targetBlockType = targetBlockState.getBlockType(); + if (!player.hasPermission("voxelsniper.ignorelimitations") && config + .getLitesniperRestrictedMaterials() + .contains(targetBlockType.getResource())) { sniper.print(Caption.of("voxelsniper.command.not-allowed", targetBlockType.getId())); return; } - toolkitProperties.setPattern(new BrushPattern(targetBlockType)); - messenger.sendPatternMessage(toolkitProperties.getPattern()); + toolkitProperties.setPattern(new BrushPattern(targetBlockState)); } } else { - BukkitPlayer wePlayer = BukkitAdapter.adapt(player); - ParserContext parserContext = new ParserContext(); - parserContext.setSession(wePlayer.getSession()); - parserContext.setWorld(wePlayer.getWorld()); - parserContext.setActor(wePlayer); - parserContext.setRestricted(false); - try { - String argument = arguments[0].toLowerCase(Locale.ROOT); - Pattern pattern = plugin.getPatternParser().parseFromInput(argument, parserContext); - - if (!sender.hasPermission("voxelsniper.ignorelimitations") && liteSniperRestrictedPatterns.contains(argument)) { - sniper.print(Caption.of("voxelsniper.command.not-allowed", argument)); - return; - } - - toolkitProperties.setPattern(new BrushPattern(pattern, argument)); - messenger.sendPatternMessage(toolkitProperties.getPattern()); - } catch (InputParseException e) { - sniper.print(Caption.of("voxelsniper.command.voxel-executor.invalid-pattern", arguments[0])); - } + toolkitProperties.setPattern(brushPattern); } - } - @Override - public List complete(CommandSender sender, String[] arguments) { - if (arguments.length == 1) { - return plugin.getPatternParser().getSuggestions(arguments[0]); - } - return Collections.emptyList(); + Messenger messenger = new Messenger(plugin, player); + messenger.sendPatternMessage(toolkitProperties.getPattern()); } } 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 3369a34f..a7d7a989 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelHeightExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelHeightExecutor.java @@ -1,17 +1,24 @@ package com.thevoxelbox.voxelsniper.command.executor; -import com.fastasyncworldedit.core.configuration.Caption; +import cloud.commandframework.annotations.Argument; +import cloud.commandframework.annotations.CommandDescription; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.Messenger; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; -public class VoxelHeightExecutor implements CommandExecutor { +@RequireToolkit +@CommandMethod(value = "voxel_height|voxelheight|vh") +@CommandDescription("VoxelHeight input.") +@CommandPermission("voxelsniper.sniper") +public class VoxelHeightExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; @@ -19,34 +26,17 @@ public VoxelHeightExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - return; - } + @CommandMethod("") + public void onVoxelHeight( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit, + final @Argument("height") int height + ) { + Player player = sniper.getPlayer(); ToolkitProperties toolkitProperties = toolkit.getProperties(); - if (toolkitProperties == null) { - return; - } - int height; - try { - height = Integer.parseInt(arguments[0]); - } catch (NumberFormatException ignored) { - sniper.print(Caption.of("voxelsniper.command.voxel-height.invalid-input", arguments[0])); - return; - } catch (ArrayIndexOutOfBoundsException ignored) { - sniper.print(Caption.of("voxelsniper.command.voxel-height.invalid-input-none")); - return; - } toolkitProperties.setVoxelHeight(height); - Messenger messenger = new Messenger(plugin, sender); + + Messenger messenger = new Messenger(plugin, player); messenger.sendVoxelHeightMessage(height); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelInkExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelInkExecutor.java deleted file mode 100644 index 615b9a9d..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelInkExecutor.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.thevoxelbox.voxelsniper.command.executor; - -import com.fastasyncworldedit.core.configuration.Caption; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.extension.input.InputParseException; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockState; -import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; -import com.thevoxelbox.voxelsniper.brush.property.BrushPattern; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; -import com.thevoxelbox.voxelsniper.config.VoxelSniperConfig; -import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; -import com.thevoxelbox.voxelsniper.sniper.toolkit.BlockTracer; -import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; -import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; -import com.thevoxelbox.voxelsniper.util.message.Messenger; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.List; - -public class VoxelInkExecutor implements CommandExecutor { - - private final VoxelSniperPlugin plugin; - - public VoxelInkExecutor(VoxelSniperPlugin plugin) { - this.plugin = plugin; - } - - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - return; - } - ToolkitProperties toolkitProperties = toolkit.getProperties(); - if (toolkitProperties == null) { - return; - } - VoxelSniperConfig config = this.plugin.getVoxelSniperConfig(); - List liteSniperRestrictedPatterns = config.getLitesniperRestrictedMaterials(); - BlockState blockState; - if (arguments.length == 0) { - BlockTracer blockTracer = toolkitProperties.createBlockTracer(player); - BlockVector3 targetBlock = blockTracer.getTargetBlock(); - blockState = BukkitAdapter.adapt(player.getWorld().getBlockAt( - targetBlock.getX(), targetBlock.getY(), targetBlock.getZ() - ).getBlockData()); - } else { - try { - blockState = BlockState.get(arguments[0]); - } catch (InputParseException ignored) { - sniper.print(Caption.of("voxelsniper.command.cannot-parse-input")); - return; - } - } - - if (blockState == null) { - sniper.print(Caption.of("voxelsniper.command.invalid-block")); - return; - } - if (!sender.hasPermission("voxelsniper.ignorelimitations") && liteSniperRestrictedPatterns.contains( - blockState.getBlockType().getResource())) { - sniper.print(Caption.of("voxelsniper.command.not-allowed", blockState.getAsString())); - return; - } - - toolkitProperties.setPattern(new BrushPattern(blockState)); - Messenger messenger = new Messenger(plugin, sender); - messenger.sendPatternMessage(toolkitProperties.getPattern()); - } - -} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelInkReplaceExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelInkReplaceExecutor.java deleted file mode 100644 index 48c9eff1..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelInkReplaceExecutor.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.thevoxelbox.voxelsniper.command.executor; - -import com.fastasyncworldedit.core.configuration.Caption; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.extension.input.InputParseException; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockState; -import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; -import com.thevoxelbox.voxelsniper.brush.property.BrushPattern; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; -import com.thevoxelbox.voxelsniper.config.VoxelSniperConfig; -import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; -import com.thevoxelbox.voxelsniper.sniper.toolkit.BlockTracer; -import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; -import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; -import com.thevoxelbox.voxelsniper.util.message.Messenger; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.List; - -public class VoxelInkReplaceExecutor implements CommandExecutor { - - private final VoxelSniperPlugin plugin; - - public VoxelInkReplaceExecutor(VoxelSniperPlugin plugin) { - this.plugin = plugin; - } - - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - return; - } - ToolkitProperties toolkitProperties = toolkit.getProperties(); - if (toolkitProperties == null) { - return; - } - VoxelSniperConfig config = this.plugin.getVoxelSniperConfig(); - List liteSniperRestrictedPatterns = config.getLitesniperRestrictedMaterials(); - BlockState blockState; - if (arguments.length == 0) { - BlockTracer blockTracer = toolkitProperties.createBlockTracer(player); - BlockVector3 targetBlock = blockTracer.getTargetBlock(); - blockState = BukkitAdapter.adapt(player.getWorld().getBlockAt( - targetBlock.getX(), targetBlock.getY(), targetBlock.getZ() - ).getBlockData()); - } else { - try { - blockState = BlockState.get(arguments[0]); - } catch (InputParseException ignored) { - sniper.print(Caption.of("voxelsniper.command.cannot-parse-input")); - return; - } - } - - if (blockState == null) { - sniper.print(Caption.of("voxelsniper.command.invalid-block")); - return; - } - if (!sender.hasPermission("voxelsniper.ignorelimitations") && liteSniperRestrictedPatterns.contains( - blockState.getBlockType().getResource())) { - sniper.print(Caption.of("voxelsniper.command.not-allowed", blockState.getAsString())); - return; - } - - toolkitProperties.setReplacePattern(new BrushPattern(blockState)); - Messenger messenger = new Messenger(plugin, sender); - messenger.sendReplacePatternMessage(toolkitProperties.getReplacePattern()); - } - -} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelListExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelListExecutor.java index dcd36605..b81c1960 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelListExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelListExecutor.java @@ -1,25 +1,32 @@ 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; +import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.block.BlockTypes; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.command.argument.VoxelListBlocksArgument; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; import com.thevoxelbox.voxelsniper.sniper.toolkit.BlockTracer; import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.Messenger; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.Locale; +import java.util.Collection; -public class VoxelListExecutor implements CommandExecutor { +@RequireToolkit +@CommandMethod(value = "voxel_list|voxellist|vl") +@CommandDescription("Voxel block exclusions list.") +@CommandPermission("voxelsniper.sniper") +public class VoxelListExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; @@ -27,65 +34,63 @@ public VoxelListExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - return; - } + @CommandMethod("") + public void onVoxelList( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit + ) { + Player player = sniper.getPlayer(); ToolkitProperties toolkitProperties = toolkit.getProperties(); - if (toolkitProperties == null) { - return; - } - Messenger messenger = new Messenger(plugin, sender); - if (arguments.length == 0) { - BlockTracer blockTracer = toolkitProperties.createBlockTracer(player); - BlockVector3 targetBlock = blockTracer.getTargetBlock(); - if (targetBlock == null) { - return; - } - BlockState blockState = BukkitAdapter.adapt(player.getWorld().getBlockAt( - targetBlock.getX(), targetBlock.getY(), targetBlock.getZ() - ).getBlockData()); - toolkitProperties.addToVoxelList(blockState); - List voxelList = toolkitProperties.getVoxelList(); - messenger.sendVoxelListMessage(voxelList); + BlockTracer blockTracer = toolkitProperties.createBlockTracer(player); + BlockVector3 targetBlock = blockTracer.getTargetBlock(); + if (targetBlock == null) { + sniper.print(Caption.of("voxelsniper.command.invalid-target-block")); return; - } else { - if (arguments[0].equalsIgnoreCase("clear")) { - toolkitProperties.clearVoxelList(); - List voxelList = toolkitProperties.getVoxelList(); - messenger.sendVoxelListMessage(voxelList); - return; - } } - boolean remove = false; - for (String string : arguments) { - String materialString; - if (!string.isEmpty() && string.charAt(0) == '-') { - remove = true; - materialString = string.replaceAll("-", ""); + + BlockState blockState = BukkitAdapter.adapt(player.getWorld().getBlockAt( + targetBlock.getX(), targetBlock.getY(), targetBlock.getZ() + ).getBlockData()); + toolkitProperties.addToVoxelList(blockState); + + Messenger messenger = new Messenger(plugin, player); + Collection voxelList = toolkitProperties.getVoxelList(); + messenger.sendVoxelListMessage(voxelList); + } + + @CommandMethod("clear") + public void onVoxelListClear( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit + ) { + Player player = sniper.getPlayer(); + ToolkitProperties toolkitProperties = toolkit.getProperties(); + toolkitProperties.clearVoxelList(); + + Messenger messenger = new Messenger(plugin, player); + Collection voxelList = toolkitProperties.getVoxelList(); + messenger.sendVoxelListMessage(voxelList); + } + + @CommandMethod("") + public void onVoxelListBlocks( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit, + final @NotNull @Argument("blocks") VoxelListBlocksArgument.BlockWrapper[] blockWrappers + ) { + Player player = sniper.getPlayer(); + ToolkitProperties toolkitProperties = toolkit.getProperties(); + for (VoxelListBlocksArgument.BlockWrapper blockWrapper : blockWrappers) { + if (blockWrapper.remove()) { + toolkitProperties.removeFromVoxelList(blockWrapper.block()); } else { - materialString = string; - } - BlockType blockType = BlockTypes.get(materialString.toLowerCase(Locale.ROOT)); - if (blockType != null) { - BlockState blockState = blockType.getDefaultState(); - if (remove) { - toolkitProperties.removeFromVoxelList(blockState); - } else { - toolkitProperties.addToVoxelList(blockState); - } - List voxelList = toolkitProperties.getVoxelList(); - messenger.sendVoxelListMessage(voxelList); + toolkitProperties.addToVoxelList(blockWrapper.block()); } } + + Messenger messenger = new Messenger(plugin, player); + Collection voxelList = toolkitProperties.getVoxelList(); + messenger.sendVoxelListMessage(voxelList); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelReplaceExecutor.java b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelReplaceExecutor.java index e6acf113..20a1253f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelReplaceExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelReplaceExecutor.java @@ -1,114 +1,82 @@ 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; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.block.BlockTypes; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; import com.thevoxelbox.voxelsniper.brush.property.BrushPattern; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; -import com.thevoxelbox.voxelsniper.command.TabCompleter; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.config.VoxelSniperConfig; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; import com.thevoxelbox.voxelsniper.sniper.toolkit.BlockTracer; import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.Messenger; -import com.thevoxelbox.voxelsniper.util.minecraft.Identifiers; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.List; -import java.util.Locale; - -public class VoxelReplaceExecutor implements CommandExecutor, TabCompleter { - - private static final List BLOCKS = BlockType.REGISTRY.values().stream() - .map(blockType -> blockType.getId().substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH)) - .toList(); +@RequireToolkit +@CommandMethod(value = "voxel_replace|voxelreplace|vr|voxel_ink_replace|voxelinkreplace|vir") +@CommandDescription("VoxelReplace input.") +@CommandPermission("voxelsniper.sniper") +public class VoxelReplaceExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; + private final VoxelSniperConfig config; public VoxelReplaceExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; + this.config = plugin.getVoxelSniperConfig(); } - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Player player = (Player) sender; - Sniper sniper = sniperRegistry.registerAndGetSniper(player); - if (sniper == null) { - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - return; - } + @CommandMethod("[block]") + public void onVoxelReplace( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit, + final @Nullable @Argument(value = "block", parserName = "block_parser") BrushPattern brushPattern + ) { + Player player = sniper.getPlayer(); ToolkitProperties toolkitProperties = toolkit.getProperties(); - if (toolkitProperties == null) { - return; - } - Messenger messenger = new Messenger(plugin, sender); - VoxelSniperConfig config = this.plugin.getVoxelSniperConfig(); - List liteSniperRestrictedPatterns = config.getLitesniperRestrictedMaterials(); - if (arguments.length == 0) { + + if (brushPattern == null) { BlockTracer blockTracer = toolkitProperties.createBlockTracer(player); BlockVector3 targetBlock = blockTracer.getTargetBlock(); if (targetBlock != null) { - BlockType targetBlockType = BukkitAdapter.asBlockType( + BlockState targetBlockState = BukkitAdapter.adapt( player.getWorld().getBlockAt( targetBlock.getX(), targetBlock.getY(), targetBlock.getZ() - ).getType() - ); - if (targetBlockType == null) { - sniper.print(Caption.of("voxelsniper.command.invalid-block")); + ).getBlockData()); + if (targetBlockState == null) { + sniper.print(Caption.of("voxelsniper.command.invalid-target-block")); return; } - if (!sender.hasPermission("voxelsniper.ignorelimitations") && liteSniperRestrictedPatterns.contains( - targetBlockType.getResource())) { + + BlockType targetBlockType = targetBlockState.getBlockType(); + if (!player.hasPermission("voxelsniper.ignorelimitations") && config + .getLitesniperRestrictedMaterials() + .contains(targetBlockType.getResource())) { sniper.print(Caption.of("voxelsniper.command.not-allowed", targetBlockType.getId())); return; } - toolkitProperties.setReplacePattern(new BrushPattern(targetBlockType)); - messenger.sendReplacePatternMessage(toolkitProperties.getReplacePattern()); - } - } else { - BlockType blockType = BlockTypes.get(arguments[0]); - if (blockType == null) { - sniper.print(Caption.of("voxelsniper.command.voxel-replace-executor.invalid-block", arguments[0])); - return; + toolkitProperties.setReplacePattern(new BrushPattern(targetBlockState)); } - if (!sender.hasPermission("voxelsniper.ignorelimitations") && liteSniperRestrictedPatterns.contains( - blockType.getResource())) { - sniper.print(Caption.of("voxelsniper.command.not-allowed", blockType.getId())); - return; - } - - toolkitProperties.setReplacePattern(new BrushPattern(blockType)); - messenger.sendReplacePatternMessage(toolkitProperties.getReplacePattern()); + } else { + toolkitProperties.setReplacePattern(brushPattern); } - } - @Override - public List complete(CommandSender sender, String[] arguments) { - if (arguments.length == 1) { - String argument = arguments[0]; - String argumentLowered = (argument.startsWith(Identifiers.MINECRAFT_IDENTIFIER) - ? argument.substring(Identifiers.MINECRAFT_IDENTIFIER_LENGTH) - : argument) - .toLowerCase(Locale.ROOT); - return BLOCKS.stream() - .filter(id -> id.startsWith(argumentLowered)) - .toList(); - } - return Collections.emptyList(); + Messenger messenger = new Messenger(plugin, player); + messenger.sendReplacePatternMessage(toolkitProperties.getReplacePattern()); } } 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 29c9e58d..428982b3 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelSniperExecutor.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/executor/VoxelSniperExecutor.java @@ -1,34 +1,38 @@ 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; +import cloud.commandframework.annotations.specifier.Range; import com.fastasyncworldedit.core.Fawe; import com.fastasyncworldedit.core.configuration.Caption; import com.intellectualsites.paster.IncendoPaster; import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; import com.thevoxelbox.voxelsniper.VoxelSniperPlugin; import com.thevoxelbox.voxelsniper.brush.property.BrushProperties; -import com.thevoxelbox.voxelsniper.command.CommandExecutor; -import com.thevoxelbox.voxelsniper.command.TabCompleter; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; +import com.thevoxelbox.voxelsniper.command.argument.annotation.RequireToolkit; import com.thevoxelbox.voxelsniper.performer.Performer; import com.thevoxelbox.voxelsniper.performer.property.PerformerProperties; import com.thevoxelbox.voxelsniper.sniper.Sniper; -import com.thevoxelbox.voxelsniper.sniper.SniperRegistry; +import com.thevoxelbox.voxelsniper.sniper.SniperCommander; import com.thevoxelbox.voxelsniper.sniper.toolkit.Toolkit; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; -import com.thevoxelbox.voxelsniper.util.text.NumericParser; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.Locale; import java.util.Map; -import java.util.stream.Stream; -public class VoxelSniperExecutor implements CommandExecutor, TabCompleter { +@CommandMethod("voxel_sniper|voxelsniper|vs|favs|fastasyncvoxelsniper") +@CommandDescription("FastAsyncVoxelSniper Settings.") +@CommandPermission("voxelsniper.sniper") +public class VoxelSniperExecutor implements VoxelCommandElement { private final VoxelSniperPlugin plugin; @@ -36,187 +40,172 @@ public VoxelSniperExecutor(VoxelSniperPlugin plugin) { this.plugin = plugin; } + @CommandMethod(value = "") + public void onVoxelSniper( + final @NotNull Sniper sniper + ) { + sniper.print(Caption.of("voxelsniper.command.voxel-sniper.info")); + sniper.sendInfo(false); + } + + @CommandMethod("brushes") + public void onVoxelSniperBrushes( + final @NotNull SniperCommander commander + ) { + Toolkit toolkit = commander instanceof Sniper sniper ? sniper.getCurrentToolkit() : null; + BrushProperties brushProperties = toolkit == null ? null : toolkit.getCurrentBrushProperties(); + + commander.print(VoxelSniperText.formatListWithCurrent( + this.plugin.getBrushRegistry().getBrushesProperties().entrySet(), + (entry, entry2) -> entry.getKey().compareTo(entry2.getKey()), + entry -> TextComponent.of(entry.getKey()), + Map.Entry::getValue, + brushProperties, + "voxelsniper.command.voxel-sniper.brushes" + )); + } + + @CommandMethod("brusheslong") + public void onVoxelSniperBrusheslong( + final @NotNull SniperCommander commander + ) { + Toolkit toolkit = commander instanceof Sniper sniper ? sniper.getCurrentToolkit() : null; + BrushProperties brushProperties = toolkit == null ? null : toolkit.getCurrentBrushProperties(); + + commander.print(VoxelSniperText.formatListWithCurrent( + this.plugin.getBrushRegistry().getUniqueBrushesProperties(), + (properties, properties2) -> properties.getName().compareTo(properties2.getName()), + entry -> TextComponent.of(entry.getName()), + properties -> properties, + brushProperties, + "voxelsniper.command.voxel-sniper.brushes-long" + )); + } + + @RequireToolkit + @CommandMethod(value = "range [range]") + public void onVoxelSniperRange( + final @NotNull Sniper sniper, + final @NotNull Toolkit toolkit, + final @Nullable @Argument("range") @Range(min = "1") Integer range + ) { + ToolkitProperties toolkitProperties = toolkit.getProperties(); + toolkitProperties.setBlockTracerRange(range); + + sniper.print(Caption.of( + "voxelsniper.command.voxel-sniper.distance-restriction", + VoxelSniperText.getStatus(range != null), range == null ? -1 : range + )); + } + + @CommandMethod("perf|performer") + public void onVoxelSniperPerformer( + final @NotNull SniperCommander commander + ) { + Toolkit toolkit = commander instanceof Sniper sniper ? sniper.getCurrentToolkit() : null; + PerformerProperties performerProperties = toolkit == null ? null : + toolkit.getCurrentBrush() instanceof Performer performer ? performer.getProperties() : null; + + commander.print(VoxelSniperText.formatListWithCurrent( + this.plugin.getPerformerRegistry().getPerformerProperties().keySet(), + String::compareTo, + TextComponent::of, + name -> name, + performerProperties == null ? null : performerProperties.getName(), + "voxelsniper.command.voxel-sniper.performer" + )); + } + + @CommandMethod("perflong|performerlong") + public void onVoxelSniperPerformerlong( + final @NotNull SniperCommander commander + ) { + Toolkit toolkit = commander instanceof Sniper sniper ? sniper.getCurrentToolkit() : null; + PerformerProperties performerProperties = toolkit == null ? null : + toolkit.getCurrentBrush() instanceof Performer performer ? performer.getProperties() : null; + + commander.print(VoxelSniperText.formatListWithCurrent( + this.plugin.getPerformerRegistry().getUniquePerformerProperties(), + (properties, properties2) -> properties.getName().compareTo(properties2.getName()), + properties -> TextComponent.of(properties.getName()), + properties -> properties, + performerProperties == null ? null : performerProperties.getName(), + "voxelsniper.command.voxel-sniper.performer-long" + )); + } + + @CommandMethod(value = "enable") + public void onVoxelSniperEnable( + final @NotNull Sniper sniper + ) { + sniper.setEnabled(true); + sniper.print(Caption.of( + "voxelsniper.command.voxel-sniper.toggle", + VoxelSniperText.getStatus(sniper.isEnabled()) + )); + } + + @CommandMethod(value = "disable") + public void onVoxelSniperDisable( + final @NotNull Sniper sniper + ) { + sniper.setEnabled(false); + sniper.print(Caption.of( + "voxelsniper.command.voxel-sniper.toggle", + VoxelSniperText.getStatus(sniper.isEnabled()) + )); + } + + @CommandMethod(value = "toggle") + public void onVoxelSniperToggle( + final @NotNull Sniper sniper + ) { + sniper.setEnabled(!sniper.isEnabled()); + sniper.print(Caption.of( + "voxelsniper.command.voxel-sniper.toggle", + VoxelSniperText.getStatus(sniper.isEnabled()) + )); + } + @SuppressWarnings("deprecation") // Paper deprecation - @Override - public void executeCommand(CommandSender sender, String[] arguments) { - SniperRegistry sniperRegistry = this.plugin.getSniperRegistry(); - Sniper sniper = (sender instanceof Player) ? sniperRegistry.registerAndGetSniper((Player) sender) : null; - - if (arguments.length >= 1) { - String firstArgument = arguments[0]; - if (firstArgument.equalsIgnoreCase("brushes")) { - Toolkit toolkit = sniper == null ? null : sniper.getCurrentToolkit(); - BrushProperties brushProperties = toolkit == null ? null : toolkit.getCurrentBrushProperties(); - - VoxelSniperText.print( - sender, - VoxelSniperText.formatListWithCurrent( - this.plugin.getBrushRegistry().getBrushesProperties().entrySet(), - (entry, entry2) -> entry.getKey().compareTo(entry2.getKey()), - entry -> TextComponent.of(entry.getKey()), - Map.Entry::getValue, - brushProperties, - "voxelsniper.command.voxel-sniper.brush" - ) - ); - return; - } else if (firstArgument.equalsIgnoreCase("range")) { - if (sniper == null) { - return; - } - Toolkit toolkit = sniper.getCurrentToolkit(); - if (toolkit == null) { - return; - } - ToolkitProperties toolkitProperties = toolkit.getProperties(); - if (toolkitProperties == null) { - return; - } - if (arguments.length == 2) { - Integer range = NumericParser.parseInteger(arguments[1]); - if (range != null) { - if (range < 1) { - sniper.print(Caption.of("voxelsniper.command.voxel-sniper.invalid-range")); - return; - } else { - toolkitProperties.setBlockTracerRange(range); - } - } else { - sniper.print(Caption.of("voxelsniper.error.invalid-number", arguments[1])); - return; - } - } else { - toolkitProperties.setBlockTracerRange(0); - } - Integer blockTracerRange = toolkitProperties.getBlockTracerRange(); - sniper.print(Caption.of("voxelsniper.command.voxel-sniper.distance-restriction", - VoxelSniperText.getStatus(blockTracerRange != null), blockTracerRange == null ? -1 : blockTracerRange - )); - return; - } else if (firstArgument.equalsIgnoreCase("perf")) { - Toolkit toolkit = sniper == null ? null : sniper.getCurrentToolkit(); - PerformerProperties performerProperties = toolkit == null ? null : - toolkit.getCurrentBrush() instanceof Performer performer ? performer.getProperties() : null; - - VoxelSniperText.print( - sender, - VoxelSniperText.formatListWithCurrent( - this.plugin.getPerformerRegistry().getPerformerProperties().keySet(), - String::compareTo, - TextComponent::of, - name -> name, - performerProperties == null ? null : performerProperties.getName(), - "voxelsniper.command.voxel-sniper.performer" - ) - ); - return; - } else if (firstArgument.equalsIgnoreCase("perflong")) { - Toolkit toolkit = sniper == null ? null : sniper.getCurrentToolkit(); - PerformerProperties performerProperties = toolkit == null ? null : - toolkit.getCurrentBrush() instanceof Performer performer ? performer.getProperties() : null; - - VoxelSniperText.print( - sender, - VoxelSniperText.formatListWithCurrent( - this.plugin.getPerformerRegistry().getPerformerProperties().values(), - (properties, properties2) -> properties.getName().compareTo(properties2.getName()), - properties -> TextComponent.of(properties.getName()), - properties -> properties, - performerProperties == null ? null : performerProperties.getName(), - "voxelsniper.command.voxel-sniper.performer-long" - ) - ); - return; - } else if (firstArgument.equalsIgnoreCase("enable")) { - if (sniper == null) { - return; - } - sniper.setEnabled(true); - sniper.print(Caption.of( - "voxelsniper.command.voxel-sniper.toggle", - VoxelSniperText.getStatus(sniper.isEnabled()) - )); - return; - } else if (firstArgument.equalsIgnoreCase("disable")) { - if (sniper == null) { - return; - } - sniper.setEnabled(false); - sniper.print(Caption.of( - "voxelsniper.command.voxel-sniper.toggle", - VoxelSniperText.getStatus(sniper.isEnabled()) - )); - - return; - } else if (firstArgument.equalsIgnoreCase("toggle")) { - if (sniper == null) { - return; - } - sniper.setEnabled(!sniper.isEnabled()); - sniper.print(Caption.of( - "voxelsniper.command.voxel-sniper.toggle", - VoxelSniperText.getStatus(sniper.isEnabled()) - )); - return; - } else if (firstArgument.equalsIgnoreCase("info")) { - PluginDescriptionFile description = plugin.getDescription(); - VoxelSniperText.print(sender, Caption.of("voxelsniper.command.voxel-sniper.admin-info", - description.getName(), description.getVersion(), description.getDescription(), - description.getWebsite(), "https://intellectualsites.gitbook.io/fastasyncvoxelsniper/", - "https://discord.gg/intellectualsites" - )); - return; - } else if (firstArgument.equalsIgnoreCase("reload")) { - if (sender.hasPermission("voxelsniper.admin")) { - plugin.reload(); - VoxelSniperText.print(sender, Caption.of("voxelsniper.command.voxel-sniper.config-reload")); - } else { - VoxelSniperText.print(sender, Caption.of( - "voxelsniper.command.missing-permission", - "voxelsniper.admin" - )); - } - return; - } else if (firstArgument.equalsIgnoreCase("debugpaste")) { - if (sender.hasPermission("voxelsniper.admin")) { - String destination; - try { - final File logFile = new File("logs/latest.log"); - final File config = new File(plugin.getDataFolder(), "config.yml"); - destination = IncendoPaster.debugPaste(logFile, Fawe.platform().getDebugInfo(), config); - } catch (IOException e) { - VoxelSniperText.print(sender, Caption.of("voxelsniper.command.voxel-sniper.debugpaste-fail", e)); - return; - } - sender.sendMessage(destination); - } else { - VoxelSniperText.print(sender, Caption.of( - "voxelsniper.command.missing-permission", - "voxelsniper.admin" - )); - } - return; - } - } - if (sniper != null) { - sniper.print(Caption.of("voxelsniper.command.voxel-sniper.info")); - sniper.sendInfo(sender, false); - } + @CommandMethod("info") + public void onVoxelSniperInfo( + final @NotNull SniperCommander commander + ) { + PluginDescriptionFile description = plugin.getDescription(); + commander.print(Caption.of("voxelsniper.command.voxel-sniper.admin-info", + description.getName(), description.getVersion(), description.getDescription(), + description.getWebsite(), "https://intellectualsites.gitbook.io/fastasyncvoxelsniper/", + "https://discord.gg/intellectualsites" + )); + } + + @CommandMethod("reload") + @CommandPermission("voxelsniper.admin") + public void onVoxelSniperReload( + final @NotNull SniperCommander commander + ) { + plugin.reload(); + commander.print(Caption.of("voxelsniper.command.voxel-sniper.config-reload")); } - @Override - public List complete(CommandSender sender, String[] arguments) { - if (arguments.length == 1) { - String argument = arguments[0]; - String argumentLowered = argument.toLowerCase(Locale.ROOT); - return Stream.concat( - Stream.of("brushes", "range", "perf", "perflong", "enable", "disable", "toggle", "info"), - sender.hasPermission("voxelsniper.admin") ? Stream.of("reload", "debugpaste") : Stream.empty() - ) - .filter(subCommand -> subCommand.startsWith(argumentLowered)) - .toList(); + @CommandMethod("debugpaste") + @CommandPermission("voxelsniper.admin") + public void onVoxelSniperDebugpaste( + final @NotNull SniperCommander commander + ) { + try { + final File logFile = new File("logs/latest.log"); + final File config = new File(plugin.getDataFolder(), "config.yml"); + final String destination = IncendoPaster.debugPaste(logFile, Fawe.platform().getDebugInfo(), config); + commander.print(Caption.of( + "voxelsniper.command.voxel-sniper.debugpaste-written", + TextComponent.of(destination) + .clickEvent(ClickEvent.of(ClickEvent.Action.OPEN_URL, destination)) + )); + } catch (IOException e) { + commander.print(Caption.of("voxelsniper.command.voxel-sniper.debugpaste-fail", e)); } - return Collections.emptyList(); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/property/CommandProperties.java b/src/main/java/com/thevoxelbox/voxelsniper/command/property/CommandProperties.java deleted file mode 100644 index 2d04f782..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/property/CommandProperties.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.thevoxelbox.voxelsniper.command.property; - -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class CommandProperties { - - private static final String DEFAULT_DESCRIPTION = ""; - private static final Class DEFAULT_SENDER_TYPE = CommandSender.class; - - private final String name; - @Nullable - private final String description; - @Nullable - private final String permission; - private final List aliases; - private final List usageLines; - @Nullable - private final Class senderType; - - CommandProperties( - String name, - @Nullable String description, - @Nullable String permission, - List aliases, - List usageLines, - @Nullable Class senderType - ) { - this.name = name; - this.description = description; - this.permission = permission; - this.aliases = aliases; - this.usageLines = usageLines; - this.senderType = senderType; - } - - public static CommandPropertiesBuilder builder() { - return new CommandPropertiesBuilder(); - } - - public String getDescriptionOrDefault() { - return this.description == null ? DEFAULT_DESCRIPTION : this.description; - } - - public String getUsage() { - return String.join("\n", this.usageLines); - } - - public Class getSenderTypeOrDefault() { - return this.senderType == null ? DEFAULT_SENDER_TYPE : this.senderType; - } - - public String getName() { - return this.name; - } - - @Nullable - public String getDescription() { - return this.description; - } - - @Nullable - public String getPermission() { - return this.permission; - } - - public List getAliases() { - return this.aliases; - } - - public List getUsageLines() { - return this.usageLines; - } - - @Nullable - public Class getSenderType() { - return this.senderType; - } - -} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/property/CommandPropertiesBuilder.java b/src/main/java/com/thevoxelbox/voxelsniper/command/property/CommandPropertiesBuilder.java deleted file mode 100644 index 65483907..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/property/CommandPropertiesBuilder.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.thevoxelbox.voxelsniper.command.property; - -import org.bukkit.command.CommandSender; - -import java.util.ArrayList; -import java.util.List; - -public class CommandPropertiesBuilder { - - private final List aliases = new ArrayList<>(0); - private final List usageMessages = new ArrayList<>(1); - private String name; - private String description; - private String permission; - private Class senderType; - - public CommandPropertiesBuilder name(String name) { - this.name = name; - return this; - } - - public CommandPropertiesBuilder description(String description) { - this.description = description; - return this; - } - - public CommandPropertiesBuilder permission(String permission) { - this.permission = permission; - return this; - } - - public CommandPropertiesBuilder alias(String alias) { - this.aliases.add(alias); - return this; - } - - public CommandPropertiesBuilder usage(String message) { - this.usageMessages.add(message); - return this; - } - - public CommandPropertiesBuilder sender(Class senderType) { - this.senderType = senderType; - return this; - } - - public CommandProperties build() { - if (this.name == null) { - throw new RuntimeException("Command name must be specified."); - } - return new CommandProperties( - this.name, - this.description, - this.permission, - this.aliases, - this.usageMessages, - this.senderType - ); - } - -} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/listener/PlayerJoinListener.java b/src/main/java/com/thevoxelbox/voxelsniper/listener/PlayerJoinListener.java index 1e17d562..63722eae 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/listener/PlayerJoinListener.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/listener/PlayerJoinListener.java @@ -45,7 +45,7 @@ public void listen(PlayerJoinEvent event) { } } if (config.isMessageOnLoginEnabled() && player.hasPermission("voxelsniper.sniper")) { - sniper.sendInfo(player, true); + sniper.sendInfo(true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/Performer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/Performer.java index c5f4343e..87c26a26 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/Performer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/Performer.java @@ -2,10 +2,11 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.world.block.BlockState; +import com.thevoxelbox.voxelsniper.command.VoxelCommandElement; import com.thevoxelbox.voxelsniper.performer.property.PerformerProperties; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; -public interface Performer { +public interface Performer extends VoxelCommandElement { /** * Initialize performer data. diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/PerformerRegistry.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/PerformerRegistry.java index f6bdb745..664a0b6a 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/PerformerRegistry.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/PerformerRegistry.java @@ -5,20 +5,38 @@ import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; public class PerformerRegistry { + private final Set uniquePerformerProperties = new HashSet<>(); private final Map performerProperties = new HashMap<>(); public void register(PerformerProperties properties) { + // Registers unique performers properties. + uniquePerformerProperties.add(properties); + + // Registers all aliases. + List aliases = properties.getAliases(); for (String alias : aliases) { this.performerProperties.put(alias, properties); } } + /** + * Return the unique performer properties. + * + * @return the unique performer properties + * @since TODO + */ + public Set getUniquePerformerProperties() { + return uniquePerformerProperties; + } + @Nullable public PerformerProperties getPerformerProperties(String alias) { return this.performerProperties.get(alias); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/AbstractPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/AbstractPerformer.java index 05807f76..41a979c6 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/AbstractPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/AbstractPerformer.java @@ -7,12 +7,22 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; +import com.thevoxelbox.voxelsniper.brush.Brush; import com.thevoxelbox.voxelsniper.performer.Performer; import com.thevoxelbox.voxelsniper.performer.property.PerformerProperties; +import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; public abstract class AbstractPerformer implements Performer { - private PerformerProperties properties; + protected PerformerProperties properties; + + protected void onPerformerCommand(PerformerSnipe snipe) { + // Sends information about the brush and the performer. + Brush brush = snipe.getBrush(); + Performer performer = snipe.getPerformer(); + this.sendInfo(snipe); + performer.sendInfo(snipe); + } public void setBlock(EditSession editSession, int x, int y, int z, Pattern pattern) { if (pattern instanceof BlockType blockType) { diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboComboNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboComboNoPhysicsPerformer.java index 2e71b43d..51ffa936 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboComboNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboComboNoPhysicsPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.combo; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p combo-combo-nophys|ccp") +@CommandPermission("voxelsniper.sniper") public class ComboComboNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull ComboComboNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboComboPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboComboPerformer.java index 84434c3b..9a1e7230 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboComboPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboComboPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.combo; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p combo-combo|cc") +@CommandPermission("voxelsniper.sniper") public class ComboComboPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull ComboComboPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboInkNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboInkNoPhysicsPerformer.java index 7a257b39..f2ab64d4 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboInkNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboInkNoPhysicsPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.combo; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p combo-ink-nophys|cip") +@CommandPermission("voxelsniper.sniper") public class ComboInkNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull ComboInkNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboInkPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboInkPerformer.java index 5257a086..8fe3b204 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboInkPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboInkPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.combo; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p combo-ink|ci") +@CommandPermission("voxelsniper.sniper") public class ComboInkPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull ComboInkPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboMaterialNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboMaterialNoPhysicsPerformer.java index f0dc0d28..8418e559 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboMaterialNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboMaterialNoPhysicsPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.combo; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p combo-mat-nophys|cmp") +@CommandPermission("voxelsniper.sniper") public class ComboMaterialNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull ComboMaterialNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboMaterialPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboMaterialPerformer.java index 70b6e4c8..9869a76b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboMaterialPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboMaterialPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.combo; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p combo-mat|cm") +@CommandPermission("voxelsniper.sniper") public class ComboMaterialPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull ComboMaterialPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboNoPhysicsPerformer.java index 47752781..d788ea4d 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboNoPhysicsPerformer.java @@ -1,16 +1,29 @@ package com.thevoxelbox.voxelsniper.performer.type.combo; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p combo-nophys|cp") +@CommandPermission("voxelsniper.sniper") public class ComboNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull ComboNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboPerformer.java index 7120685a..cbb05a6a 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ComboPerformer.java @@ -1,16 +1,29 @@ package com.thevoxelbox.voxelsniper.performer.type.combo; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p combo|c") +@CommandPermission("voxelsniper.sniper") public class ComboPerformer extends AbstractPerformer { private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull ComboPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ExcludeComboPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ExcludeComboPerformer.java index 4a24438e..8ef6b151 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ExcludeComboPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/ExcludeComboPerformer.java @@ -1,19 +1,32 @@ package com.thevoxelbox.voxelsniper.performer.type.combo; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; -import java.util.List; +import java.util.Collection; +@CommandMethod(value = "performer|perf|p exclude-combo|xc") +@CommandPermission("voxelsniper.sniper") public class ExcludeComboPerformer extends AbstractPerformer { - private List excludeList; + private Collection excludeList; private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull ExcludeComboPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/IncludeComboPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/IncludeComboPerformer.java index c83a37ff..1ec316d5 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/IncludeComboPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/combo/IncludeComboPerformer.java @@ -1,19 +1,33 @@ package com.thevoxelbox.voxelsniper.performer.type.combo; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; -import java.util.List; +import java.util.Collection; +@CommandMethod(value = "performer|perf|p include-combo|nc") +@CommandPermission("voxelsniper.sniper") public class IncludeComboPerformer extends AbstractPerformer { - private List includeList; + private Collection includeList; private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull IncludeComboPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/ExcludeInkPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/ExcludeInkPerformer.java index 57da3724..3ff54028 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/ExcludeInkPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/ExcludeInkPerformer.java @@ -1,19 +1,32 @@ package com.thevoxelbox.voxelsniper.performer.type.ink; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; -import java.util.List; +import java.util.Collection; +@CommandMethod(value = "performer|perf|p exclude-ink|xi") +@CommandPermission("voxelsniper.sniper") public class ExcludeInkPerformer extends AbstractPerformer { - private List excludeList; + private Collection excludeList; private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull ExcludeInkPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/IncludeInkPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/IncludeInkPerformer.java index 4ba8c950..93919ad0 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/IncludeInkPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/IncludeInkPerformer.java @@ -1,19 +1,32 @@ package com.thevoxelbox.voxelsniper.performer.type.ink; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; -import java.util.List; +import java.util.Collection; +@CommandMethod(value = "performer|perf|p include-ink|ni") +@CommandPermission("voxelsniper.sniper") public class IncludeInkPerformer extends AbstractPerformer { - private List includeList; + private Collection includeList; private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull IncludeInkPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkComboNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkComboNoPhysicsPerformer.java index ee5d8757..78396577 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkComboNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkComboNoPhysicsPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.ink; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p ink-combo-nophys|icp") +@CommandPermission("voxelsniper.sniper") public class InkComboNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull InkComboNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkComboPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkComboPerformer.java index 1db0014f..ae038ca9 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkComboPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkComboPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.ink; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p ink-combo|ic") +@CommandPermission("voxelsniper.sniper") public class InkComboPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull InkComboPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkInkNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkInkNoPhysicsPerformer.java index 4305275f..098bf5fb 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkInkNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkInkNoPhysicsPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.ink; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p ink-ink-nophys|iip") +@CommandPermission("voxelsniper.sniper") public class InkInkNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull InkInkNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkInkPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkInkPerformer.java index 20d608b0..82817ba7 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkInkPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkInkPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.ink; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p ink-ink|ii") +@CommandPermission("voxelsniper.sniper") public class InkInkPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull InkInkPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkMaterialNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkMaterialNoPhysicsPerformer.java index 8cf8996e..5502f63b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkMaterialNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkMaterialNoPhysicsPerformer.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.performer.type.ink; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; @@ -7,12 +9,23 @@ import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p ink-mat-nophys|imp") +@CommandPermission("voxelsniper.sniper") public class InkMaterialNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; private BlockType replaceType; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull InkMaterialNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkMaterialPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkMaterialPerformer.java index 72df08dd..1adfa5ea 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkMaterialPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkMaterialPerformer.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.performer.type.ink; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; @@ -7,12 +9,23 @@ import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p ink-mat|im") +@CommandPermission("voxelsniper.sniper") public class InkMaterialPerformer extends AbstractPerformer { private Pattern pattern; private BlockType replaceType; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull InkMaterialPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkNoPhysicsPerformer.java index bfba69bb..6868e47a 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkNoPhysicsPerformer.java @@ -1,16 +1,29 @@ package com.thevoxelbox.voxelsniper.performer.type.ink; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p ink-nophys|ip") +@CommandPermission("voxelsniper.sniper") public class InkNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull InkNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkPerformer.java index a8faf639..b40408cb 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/ink/InkPerformer.java @@ -1,16 +1,29 @@ package com.thevoxelbox.voxelsniper.performer.type.ink; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p ink|i") +@CommandPermission("voxelsniper.sniper") public class InkPerformer extends AbstractPerformer { private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull InkPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/ExcludeMaterialPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/ExcludeMaterialPerformer.java index eda42004..886e9bed 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/ExcludeMaterialPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/ExcludeMaterialPerformer.java @@ -1,19 +1,32 @@ package com.thevoxelbox.voxelsniper.performer.type.material; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; -import java.util.List; +import java.util.Collection; +@CommandMethod(value = "performer|perf|p exclude-mat|xm") +@CommandPermission("voxelsniper.sniper") public class ExcludeMaterialPerformer extends AbstractPerformer { - private List excludeList; + private Collection excludeList; private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull ExcludeMaterialPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/IncludeMaterialPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/IncludeMaterialPerformer.java index f097f203..d9b122e0 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/IncludeMaterialPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/IncludeMaterialPerformer.java @@ -1,19 +1,32 @@ package com.thevoxelbox.voxelsniper.performer.type.material; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; -import java.util.List; +import java.util.Collection; +@CommandMethod(value = "performer|perf|p include-mat|nm") +@CommandPermission("voxelsniper.sniper") public class IncludeMaterialPerformer extends AbstractPerformer { - private List includeList; + private Collection includeList; private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull IncludeMaterialPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialComboNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialComboNoPhysicsPerformer.java index 9ba2b43d..3be00cd5 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialComboNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialComboNoPhysicsPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.material; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p mat-combo-nophys|mcp") +@CommandPermission("voxelsniper.sniper") public class MaterialComboNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull MaterialComboNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialComboPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialComboPerformer.java index 3f3057b1..fac4285b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialComboPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialComboPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.material; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p mat-combo|mc") +@CommandPermission("voxelsniper.sniper") public class MaterialComboPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull MaterialComboPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialInkNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialInkNoPhysicsPerformer.java index c7d9aa58..d96df629 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialInkNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialInkNoPhysicsPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.material; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p mat-ink-nophys|mip") +@CommandPermission("voxelsniper.sniper") public class MaterialInkNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull MaterialInkNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialInkPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialInkPerformer.java index 3a0723de..b216198a 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialInkPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialInkPerformer.java @@ -1,17 +1,30 @@ package com.thevoxelbox.voxelsniper.performer.type.material; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p mat-ink|mi") +@CommandPermission("voxelsniper.sniper") public class MaterialInkPerformer extends AbstractPerformer { private Pattern pattern; private BlockState replaceBlockData; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull MaterialInkPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialMaterialNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialMaterialNoPhysicsPerformer.java index 8b2f0bf8..eb8c4299 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialMaterialNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialMaterialNoPhysicsPerformer.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.performer.type.material; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; @@ -7,12 +9,23 @@ import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p mat-mat-nophys|mmp") +@CommandPermission("voxelsniper.sniper") public class MaterialMaterialNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; private BlockType replaceType; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull MaterialMaterialNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialMaterialPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialMaterialPerformer.java index 2c86faf8..57947ae7 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialMaterialPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialMaterialPerformer.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.performer.type.material; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockState; @@ -7,12 +9,23 @@ import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p mat-mat|mm") +@CommandPermission("voxelsniper.sniper") public class MaterialMaterialPerformer extends AbstractPerformer { private Pattern pattern; private BlockType replaceType; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull MaterialMaterialPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialNoPhysicsPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialNoPhysicsPerformer.java index b269864c..98bdf76f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialNoPhysicsPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialNoPhysicsPerformer.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.performer.type.material; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BaseBlock; @@ -7,11 +9,22 @@ import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p mat-nophys|mp") +@CommandPermission("voxelsniper.sniper") public class MaterialNoPhysicsPerformer extends AbstractPerformer { private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull MaterialNoPhysicsPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialPerformer.java b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialPerformer.java index b154d711..e3ee54cb 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialPerformer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/performer/type/material/MaterialPerformer.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.performer.type.material; +import cloud.commandframework.annotations.CommandMethod; +import cloud.commandframework.annotations.CommandPermission; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BaseBlock; @@ -7,11 +9,22 @@ import com.thevoxelbox.voxelsniper.performer.type.AbstractPerformer; import com.thevoxelbox.voxelsniper.sniper.snipe.performer.PerformerSnipe; import com.thevoxelbox.voxelsniper.sniper.toolkit.ToolkitProperties; +import org.jetbrains.annotations.NotNull; +@CommandMethod(value = "performer|perf|p material|mat|m") +@CommandPermission("voxelsniper.sniper") public class MaterialPerformer extends AbstractPerformer { private Pattern pattern; + @CommandMethod("") + public void onPerformer( + final @NotNull PerformerSnipe snipe, + final @NotNull MaterialPerformer performer + ) { + performer.onPerformerCommand(snipe); + } + @Override public void initialize(PerformerSnipe snipe) { ToolkitProperties toolkitProperties = snipe.getToolkitProperties(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/sniper/Sniper.java b/src/main/java/com/thevoxelbox/voxelsniper/sniper/Sniper.java index 1abff047..c0dbfa78 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/sniper/Sniper.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/sniper/Sniper.java @@ -7,7 +7,6 @@ import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.util.formatting.text.Component; @@ -42,16 +41,29 @@ import java.util.List; import java.util.UUID; -public class Sniper { - - private static final String DEFAULT_TOOLKIT_NAME = "default"; +public class Sniper implements SniperCommander { private final UUID uuid; + private Player player; private final List toolkits = new ArrayList<>(); private boolean enabled = true; public Sniper(UUID uuid) { this.uuid = uuid; + this.player = null; + Toolkit defaultToolkit = createDefaultToolkit(); + this.toolkits.add(defaultToolkit); + } + + /** + * Create a sniper from a player. + * + * @param player the player + * @since TODO + */ + public Sniper(Player player) { + this.uuid = player.getUniqueId(); + this.player = player; Toolkit defaultToolkit = createDefaultToolkit(); this.toolkits.add(defaultToolkit); } @@ -64,13 +76,20 @@ private Toolkit createDefaultToolkit() { } public Player getPlayer() { - Player player = Bukkit.getPlayer(this.uuid); + if (player == null || !player.isValid()) { + player = Bukkit.getPlayer(this.uuid); + } if (player == null) { throw new UnknownSniperPlayerException(); } return player; } + @Override + public CommandSender getCommandSender() { + return getPlayer(); + } + @Nullable public Toolkit getCurrentToolkit() { Player player = getPlayer(); @@ -78,7 +97,7 @@ public Toolkit getCurrentToolkit() { ItemStack itemInHand = inventory.getItemInMainHand(); ItemType itemType = BukkitAdapter.asItemType(itemInHand.getType()); if (itemType == ItemTypes.AIR) { - return getToolkit(DEFAULT_TOOLKIT_NAME); + return getToolkit(Toolkit.DEFAULT_NAME); } return getToolkit(itemType); } @@ -125,13 +144,11 @@ public boolean snipe( ) { { switch (action) { - case LEFT_CLICK_AIR: - case LEFT_CLICK_BLOCK: - case RIGHT_CLICK_AIR: - case RIGHT_CLICK_BLOCK: - break; - default: + case LEFT_CLICK_AIR, LEFT_CLICK_BLOCK, RIGHT_CLICK_AIR, RIGHT_CLICK_BLOCK -> { + } + default -> { return false; + } } if (toolkits.isEmpty()) { return false; @@ -151,7 +168,7 @@ public boolean snipe( print(Caption.of("voxelsniper.sniper.missing-permission", permission)); return false; } - BukkitPlayer wePlayer = BukkitAdapter.adapt(player); + com.sk89q.worldedit.entity.Player wePlayer = BukkitAdapter.adapt(player); LocalSession session = wePlayer.getSession(); QueueHandler queue = Fawe.instance().getQueueHandler(); queue.async(() -> { @@ -175,7 +192,7 @@ public boolean snipe( } public synchronized boolean snipeOnCurrentThread( - com.sk89q.worldedit.entity.Player fp, + com.sk89q.worldedit.entity.Player wePlayer, Player player, Action action, @Nullable Block clickedBlock, @@ -184,9 +201,9 @@ public synchronized boolean snipeOnCurrentThread( ToolAction toolAction, BrushProperties currentBrushProperties ) { - LocalSession session = fp.getSession(); + LocalSession session = wePlayer.getSession(); synchronized (session) { - EditSession editSession = session.createEditSession(fp); + EditSession editSession = session.createEditSession(wePlayer); try { ToolkitProperties toolkitProperties = toolkit.getProperties(); @@ -306,26 +323,27 @@ public synchronized boolean snipeOnCurrentThread( return false; } catch (Throwable t) { t.printStackTrace(); + print(Caption.of("voxelsniper.error.unexpected")); return false; } finally { session.remember(editSession); editSession.flushQueue(); - WorldEdit.getInstance().flushBlockBag(fp, editSession); + WorldEdit.getInstance().flushBlockBag(wePlayer, editSession); } } } - public void sendInfo(CommandSender sender, boolean prefix) { + public void sendInfo(boolean prefix) { Toolkit toolkit = getCurrentToolkit(); if (toolkit == null) { - VoxelSniperText.print(sender, Caption.of("voxelsniper.sniper.current-toolkit-none")); + print(Caption.of("voxelsniper.sniper.current-toolkit-none"), true); return; } - VoxelSniperText.print(sender, Caption.of("voxelsniper.sniper.current-toolkit", toolkit.getToolkitName()), prefix); + print(Caption.of("voxelsniper.sniper.current-toolkit", toolkit.getToolkitName()), prefix); BrushProperties brushProperties = toolkit.getCurrentBrushProperties(); Brush brush = toolkit.getCurrentBrush(); if (brush == null) { - VoxelSniperText.print(sender, Caption.of("voxelsniper.sniper.no-brush-selected", toolkit.getToolkitName()), false); + print(Caption.of("voxelsniper.sniper.no-brush-selected", toolkit.getToolkitName()), false); return; } ToolkitProperties toolkitProperties = toolkit.getProperties(); @@ -336,23 +354,7 @@ public void sendInfo(CommandSender sender, boolean prefix) { } } - /** - * Sends a component to a sniper. This method adds the prefix and handle translations. - * - * @param component component - * @since 2.7.0 - */ - public void print(Component component) { - print(component, true); - } - - /** - * Sends a component to a sniper. This method potentially adds the prefix and handle translations. - * - * @param component component - * @param prefix prefix - * @since 2.7.0 - */ + @Override public void print(Component component, boolean prefix) { Player player = getPlayer(); VoxelSniperText.print(player, component, prefix); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/sniper/SniperCommander.java b/src/main/java/com/thevoxelbox/voxelsniper/sniper/SniperCommander.java new file mode 100644 index 00000000..6f1746d3 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/sniper/SniperCommander.java @@ -0,0 +1,56 @@ +package com.thevoxelbox.voxelsniper.sniper; + +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.util.formatting.text.Component; +import org.bukkit.command.CommandSender; + +public interface SniperCommander { + + /** + * Return the command sender + * + * @return the command sender + * @since TODO + */ + CommandSender getCommandSender(); + + /** + * Create a parser context from the sniper commander. + * + * @return the parser context + * @since TODO + */ + default ParserContext createParserContext() { + CommandSender sender = getCommandSender(); + Actor actor = BukkitAdapter.adapt(sender); + ParserContext parserContext = new ParserContext(); + parserContext.setSession(actor.getSession()); + parserContext.setWorld(actor instanceof Player wePlayer ? wePlayer.getWorld() : null); + parserContext.setActor(actor); + parserContext.setRestricted(false); + return parserContext; + } + + /** + * Sends a component to a sniper. This method adds the prefix and handle translations. + * + * @param component component + * @since 2.7.0 + */ + default void print(Component component) { + print(component, true); + } + + /** + * Sends a component to a sniper. This method potentially adds the prefix and handle translations. + * + * @param component component + * @param prefix prefix + * @since 2.7.0 + */ + void print(Component component, boolean prefix); + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/sniper/SniperRegistry.java b/src/main/java/com/thevoxelbox/voxelsniper/sniper/SniperRegistry.java index 0a84e28f..6691769e 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/sniper/SniperRegistry.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/sniper/SniperRegistry.java @@ -1,5 +1,6 @@ package com.thevoxelbox.voxelsniper.sniper; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; @@ -32,6 +33,20 @@ public void unregister(Sniper sniper) { this.snipers.remove(uuid); } + /** + * Return the associated sniper commander. + * This method returns the usual sniper and registers, if necessary, for a player. + * + * @param commandSender the command sender + * @return the sniper commander + * @since TODO + */ + public SniperCommander getSniperCommander(CommandSender commandSender) { + return commandSender instanceof Player player + ? registerAndGetSniper(player) + : new SniperSender(commandSender); + } + /** * Register the player as a sniper if not already done. * Return the sniper directly or after registration. @@ -43,7 +58,7 @@ public Sniper registerAndGetSniper(Player player) { UUID uuid = player.getUniqueId(); Sniper sniper = getSniper(uuid); if (sniper == null) { - sniper = new Sniper(uuid); + sniper = new Sniper(player); register(sniper); } return sniper; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/sniper/SniperSender.java b/src/main/java/com/thevoxelbox/voxelsniper/sniper/SniperSender.java new file mode 100644 index 00000000..ad258dea --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/sniper/SniperSender.java @@ -0,0 +1,31 @@ +package com.thevoxelbox.voxelsniper.sniper; + +import com.sk89q.worldedit.util.formatting.text.Component; +import com.thevoxelbox.voxelsniper.util.message.VoxelSniperText; +import org.bukkit.command.CommandSender; + +public class SniperSender implements SniperCommander { + + protected final CommandSender commandSender; + + /** + * Create a sniper sender from a command sender. + * + * @param commandSender the command sender + * @since TODO + */ + public SniperSender(CommandSender commandSender) { + this.commandSender = commandSender; + } + + @Override + public CommandSender getCommandSender() { + return commandSender; + } + + @Override + public void print(Component component, boolean prefix) { + VoxelSniperText.print(commandSender, component, prefix); + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/Snipe.java b/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/Snipe.java index 45348f70..fe9de917 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/Snipe.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/Snipe.java @@ -61,4 +61,15 @@ public Brush getBrush() { return this.brush; } + /** + * Return the brush as a specific type + * + * @param the brush type + * @return the typed brush + */ + @SuppressWarnings("unchecked") + public T getTypedBrush() { + return (T) this.brush; + } + } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/message/SnipeMessageSender.java b/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/message/SnipeMessageSender.java index 875170ba..05dfef7a 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/message/SnipeMessageSender.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/message/SnipeMessageSender.java @@ -8,7 +8,7 @@ import com.thevoxelbox.voxelsniper.util.message.MessageSender; import org.bukkit.entity.Player; -import java.util.List; +import java.util.Collection; public class SnipeMessageSender { @@ -59,7 +59,7 @@ public SnipeMessageSender voxelHeightMessage() { } public SnipeMessageSender voxelListMessage() { - List voxelList = this.toolkitProperties.getVoxelList(); + Collection voxelList = this.toolkitProperties.getVoxelList(); this.messageSender.voxelListMessage(voxelList); return this; } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/message/SnipeMessenger.java b/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/message/SnipeMessenger.java index 2825d3da..52c59b32 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/message/SnipeMessenger.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/message/SnipeMessenger.java @@ -8,7 +8,7 @@ import com.thevoxelbox.voxelsniper.util.message.Messenger; import org.bukkit.entity.Player; -import java.util.List; +import java.util.Collection; public class SnipeMessenger { @@ -51,7 +51,7 @@ public void sendVoxelHeightMessage() { } public void sendVoxelListMessage() { - List voxelList = this.toolkitProperties.getVoxelList(); + Collection voxelList = this.toolkitProperties.getVoxelList(); this.messenger.sendVoxelListMessage(voxelList); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/performer/PerformerSnipe.java b/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/performer/PerformerSnipe.java index fc957313..1b910b11 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/performer/PerformerSnipe.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/sniper/snipe/performer/PerformerSnipe.java @@ -69,4 +69,15 @@ public Performer getPerformer() { return this.performer; } + /** + * Return the performer as a specific type + * + * @param the performer type + * @return the typed performer + */ + @SuppressWarnings("unchecked") + public T getTypedPerformer() { + return (T) this.performer; + } + } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/BlockTracer.java b/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/BlockTracer.java index 93edb95d..a8b8d011 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/BlockTracer.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/BlockTracer.java @@ -13,8 +13,8 @@ public class BlockTracer { private final BlockVector3 lastBlock; public BlockTracer(Player player, int distance) { - com.sk89q.worldedit.entity.Player fp = BukkitAdapter.adapt(player); - TargetBlock tracer = new TargetBlock(fp, distance, 0.2); + com.sk89q.worldedit.entity.Player wePlayer = BukkitAdapter.adapt(player); + TargetBlock tracer = new TargetBlock(wePlayer, distance, 0.2); Location targetLocation = tracer.getAnyTargetBlock(); Location lastLocation = tracer.getPreviousBlock(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/Toolkit.java b/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/Toolkit.java index 1559736b..4a42d15e 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/Toolkit.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/Toolkit.java @@ -5,6 +5,9 @@ import com.thevoxelbox.voxelsniper.brush.Brush; import com.thevoxelbox.voxelsniper.brush.property.BrushCreator; import com.thevoxelbox.voxelsniper.brush.property.BrushProperties; +import com.thevoxelbox.voxelsniper.performer.Performer; +import com.thevoxelbox.voxelsniper.performer.property.PerformerCreator; +import com.thevoxelbox.voxelsniper.performer.property.PerformerProperties; import org.jetbrains.annotations.Nullable; import java.util.Collections; @@ -13,6 +16,7 @@ public class Toolkit { + public static final String DEFAULT_NAME = "default"; private static final BrushProperties DEFAULT_BRUSH_PROPERTIES = BrushRegistrar.DEFAULT_BRUSH_PROPERTIES; private final String toolkitName; @@ -64,6 +68,17 @@ public Brush useBrush(BrushProperties properties) { return brush; } + /** + * Use a performer. Initializes and returns it. + * + * @param properties the properties + * @return the performer + * @since TODO + */ + public Performer usePerformer(PerformerProperties properties) { + return createPerformer(properties); + } + private Brush createBrush(BrushProperties properties) { BrushCreator creator = properties.getCreator(); Brush brush = creator.create(); @@ -73,6 +88,14 @@ private Brush createBrush(BrushProperties properties) { return brush; } + private Performer createPerformer(PerformerProperties properties) { + PerformerCreator performerCreator = properties.getCreator(); + Performer performer = performerCreator.create(); + performer.setProperties(properties); + performer.loadProperties(); + return performer; + } + @Nullable public Brush getCurrentBrush() { return getBrush(this.currentBrushProperties); @@ -87,6 +110,15 @@ public String getToolkitName() { return this.toolkitName; } + /** + * Return whether the toolkit is the default one or not. + * + * @return whether the toolkit is the default one or not + */ + public boolean isDefault() { + return toolkitName.equals(DEFAULT_NAME); + } + public BrushProperties getCurrentBrushProperties() { return this.currentBrushProperties; } @@ -103,4 +135,5 @@ public ToolkitProperties getProperties() { return this.properties; } + } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/ToolkitProperties.java b/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/ToolkitProperties.java index 45d43f7f..669c61be 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/ToolkitProperties.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/sniper/toolkit/ToolkitProperties.java @@ -8,15 +8,16 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; -import java.util.List; +import java.util.HashSet; +import java.util.Set; public class ToolkitProperties { private static final VoxelSniperPlugin plugin = VoxelSniperPlugin.plugin; - private final List voxelList = new ArrayList<>(); + private final Set voxelList = new HashSet<>(); private BrushPattern pattern; private BrushPattern replacePattern; private int brushSize; @@ -171,8 +172,14 @@ public void setLightningEnabled(boolean lightningEnabled) { this.lightningEnabled = lightningEnabled; } - public List getVoxelList() { - return Collections.unmodifiableList(this.voxelList); + /** + * Return the voxel list. + * + * @return the voxel list + * @since TODO + */ + public Collection getVoxelList() { + return Collections.unmodifiableCollection(this.voxelList); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/ArtHelper.java b/src/main/java/com/thevoxelbox/voxelsniper/util/ArtHelper.java index c2732a6e..0387344f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/util/ArtHelper.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/util/ArtHelper.java @@ -27,6 +27,7 @@ private ArtHelper() { public static void paint(Player player, Art art) { Painting bestMatch = matchPainting(player); if (bestMatch == null) { + VoxelSniperText.print(player, Caption.of("voxelsniper.art.paint.no-match")); return; } if (art == null) { @@ -40,12 +41,13 @@ public static void paint(Player player, Art art) { public static void paintAuto(Player player, boolean back) { Painting bestMatch = matchPainting(player); if (bestMatch == null) { + VoxelSniperText.print(player, Caption.of("voxelsniper.art.paint.no-match")); return; } Art bestMatchArt = bestMatch.getArt(); int ordinal = bestMatchArt.ordinal() + (back ? -1 : 1); if (ordinal < 0 || ordinal >= Art.values().length) { - VoxelSniperText.print(player, Caption.of("voxelsniper.art.paint.final-paiting")); + VoxelSniperText.print(player, Caption.of("voxelsniper.art.paint.final-painting")); return; } Art ordinalArt = Art.values()[ordinal]; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/ReflectionsUtils.java b/src/main/java/com/thevoxelbox/voxelsniper/util/ReflectionsUtils.java new file mode 100644 index 00000000..872d3c1b --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/util/ReflectionsUtils.java @@ -0,0 +1,19 @@ +package com.thevoxelbox.voxelsniper.util; + +import java.lang.reflect.Field; + +public class ReflectionsUtils { + + public static Field getField(Class clazz, String name) { + do { + try { + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + return field; + } catch (NoSuchFieldException ignored) { + } + } while (clazz.getSuperclass() != Object.class && ((clazz = clazz.getSuperclass()) != null)); + return null; + } + +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/math/MathHelper.java b/src/main/java/com/thevoxelbox/voxelsniper/util/math/MathHelper.java index 02dcb950..40e777b9 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/util/math/MathHelper.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/util/math/MathHelper.java @@ -1,5 +1,7 @@ package com.thevoxelbox.voxelsniper.util.math; +import org.apache.commons.lang3.ClassUtils; + public final class MathHelper { private MathHelper() { @@ -30,4 +32,56 @@ public static double cube(double number) { return number * number * number; } + /** + * Return the min number for a given type. + * + * @param clazz the class + * @return the min number or NaN + * @since TODO + */ + public static Number minNumberType(Class clazz) { + clazz = ClassUtils.primitiveToWrapper(clazz); + + if (clazz == Byte.class) { + return Byte.MIN_VALUE; + } else if (clazz == Short.class) { + return Short.MIN_VALUE; + } else if (clazz == Integer.class) { + return Integer.MIN_VALUE; + } else if (clazz == Long.class) { + return Long.MIN_VALUE; + } else if (clazz == Float.class) { + return Float.MIN_VALUE; + } else if (clazz == Double.class) { + return Double.MIN_VALUE; + } + return Double.NaN; + } + + /** + * Return the max number for a given type. + * + * @param clazz the class + * @return the max number or NaN + * @since TODO + */ + public static Number maxNumberType(Class clazz) { + clazz = ClassUtils.primitiveToWrapper(clazz); + + if (clazz == Byte.class) { + return Byte.MAX_VALUE; + } else if (clazz == Short.class) { + return Short.MAX_VALUE; + } else if (clazz == Integer.class) { + return Integer.MAX_VALUE; + } else if (clazz == Long.class) { + return Long.MAX_VALUE; + } else if (clazz == Float.class) { + return Float.MAX_VALUE; + } else if (clazz == Double.class) { + return Double.MAX_VALUE; + } + return Double.NaN; + } + } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/message/MessageSender.java b/src/main/java/com/thevoxelbox/voxelsniper/util/message/MessageSender.java index 17b18977..8a03147b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/util/message/MessageSender.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/util/message/MessageSender.java @@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender; import java.util.ArrayList; +import java.util.Collection; import java.util.List; public class MessageSender { @@ -60,7 +61,7 @@ public MessageSender voxelHeightMessage(int voxelHeight) { return this; } - public MessageSender voxelListMessage(List voxelList) { + public MessageSender voxelListMessage(Collection voxelList) { if (voxelList.isEmpty()) { this.messages.add(Caption.of("voxelsniper.messenger.voxel.list-empty")); return this; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/message/Messenger.java b/src/main/java/com/thevoxelbox/voxelsniper/util/message/Messenger.java index 04edbfa4..5b877f5c 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/util/message/Messenger.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/util/message/Messenger.java @@ -8,7 +8,7 @@ import com.thevoxelbox.voxelsniper.brush.property.BrushPattern; import org.bukkit.command.CommandSender; -import java.util.List; +import java.util.Collection; public class Messenger { @@ -53,7 +53,7 @@ public void sendVoxelHeightMessage(int voxelHeight) { sendMessage(Caption.of("voxelsniper.messenger.voxel-height", voxelHeight)); } - public void sendVoxelListMessage(List voxelList) { + public void sendVoxelListMessage(Collection voxelList) { if (voxelList.isEmpty()) { sendMessage(Caption.of("voxelsniper.messenger.voxel.list-empty")); return; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/text/NumericParser.java b/src/main/java/com/thevoxelbox/voxelsniper/util/text/NumericParser.java deleted file mode 100644 index c6f43b84..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/util/text/NumericParser.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.thevoxelbox.voxelsniper.util.text; - -import org.jetbrains.annotations.Nullable; - -public final class NumericParser { - - private NumericParser() { - throw new UnsupportedOperationException("Cannot create an instance of this class"); - } - - @Nullable - public static Integer parseInteger(String integerString) { - try { - return Integer.parseInt(integerString); - } catch (NumberFormatException exception) { - return null; - } - } - - @Nullable - public static Double parseDouble(String doubleString) { - try { - return Double.parseDouble(doubleString); - } catch (NumberFormatException exception) { - return null; - } - } - -} diff --git a/src/main/resources/lang/strings.json b/src/main/resources/lang/strings.json index 017747d4..95f41146 100644 --- a/src/main/resources/lang/strings.json +++ b/src/main/resources/lang/strings.json @@ -24,70 +24,86 @@ "voxelsniper.messenger.replace-pattern": "&bPerformer: &c{0}", "voxelsniper.messenger.brush-size": "&aBrush Size: &4{0}", "voxelsniper.messenger.large-brush-size": "&cWARNING: Large brush size selected!", - "voxelsniper.messenger.cylinder-center": "&9Brush Center: : &4{0}", + "voxelsniper.messenger.cylinder-center": "&9Brush Center: &4{0}", "voxelsniper.messenger.voxel-height": "&3Brush Height: &4{0}", - "voxelsniper.messenger.voxel.list-prefix": "&2Block Types Selected: {0}", - "voxelsniper.messenger.voxel.list-empty": "&2No blocks selected!", + "voxelsniper.messenger.voxel.list-prefix": "&2Voxel List: {0}", + "voxelsniper.messenger.voxel.list-empty": "&2Empty Voxel List!", "voxelsniper.messenger.list-element": "&b{0}", "voxelsniper.messenger.list-current": "&6{0}", "voxelsniper.messenger.list-other": "&7{0}", "voxelsniper.messenger.list-delimiter": "&f, ", + "voxelsniper.art.paint.no-match": "&cNo suitable painting around you.", "voxelsniper.art.paint.invalid-input": "&cYour input was invalid somewhere.", - "voxelsniper.art.paint.final-paiting": "&cThis is the final painting, try scrolling to the other direction.", + "voxelsniper.art.paint.final-painting": "&cThis is the final painting, try scrolling to the other direction.", "voxelsniper.art.paint.set": "&aPainting set to: &b{0}", - "voxelsniper.command.no-parameters": "&cThis brush does not accept additional parameters.", - "voxelsniper.command.wrong-sender-type": "&cOnly &b{0} &ccan execute this command.", + "voxelsniper.command.invalid-command-syntax": "&cInvalid command syntax. Expected &b/{0}&c.", + "voxelsniper.command.invalid-sender-type": "&cOnly &b{0} &ccan execute this command.", "voxelsniper.command.missing-permission": "&cYou are lacking the permission node: &b{0}", "voxelsniper.command.missing-sniper": "&cSniper not found.", "voxelsniper.command.missing-toolkit": "&cCurrent toolkit not found.", - "voxelsniper.command.invalid-block": "&cYou have selected an invalid block.", + "voxelsniper.command.invalid-target-block": "&cYou have selected an invalid block.", "voxelsniper.command.not-allowed": "&cYou are not allowed to use &b{0}&c.", "voxelsniper.command.cannot-parse-input": "Could not parse block data input.", - "voxelsniper.command.brush.invalid-size": "&cSize must be a positive integer.", + "voxelsniper.command.invalid-no_input_was_provided": "&cNo input was provided.", + "voxelsniper.command.invalid-boolean": "&cInvalid boolean: &b{0}&c.", + "voxelsniper.command.invalid-number": "&cInvalid number: &b{0}&c, must be in the range &b{1} &cto &b{2}&c.", + "voxelsniper.command.invalid-char": "&cInvalid character: &b{0}&c.", + "voxelsniper.command.invalid-string": "&cInvalid string: &b{0}&c, must be of type &b{1}&c.", + "voxelsniper.command.invalid-uuid": "&cInvalid UUID: &b{0}&c.", + "voxelsniper.command.invalid-enum": "&cInvalid value: &b{0}&c, must be one of the following. {1}", + "voxelsniper.command.invalid-enum.list-prefix": "&bAvailable values: {0}", + "voxelsniper.command.invalid-regex": "&cInvalid value: &b{0}&c, must match &b{1}&c.", + "voxelsniper.command.invalid-flag.unknown": "&cInvalid flag: &b{0}&c, unknown.", + "voxelsniper.command.invalid-flag.duplicate_flag": "&cInvalid flag: &b{0}&c, duplicate.", + "voxelsniper.command.invalid-flag.no_flag_started": "&cInvalid input: &b{0}&c, no flag started.", + "voxelsniper.command.invalid-flag.missing_argument": "&cInvalid flag: &b{0}&c, missing argument.", + "voxelsniper.command.invalid-flag.no_permission": "&cInvalid flag: &b{0}&c, missing permission.", + "voxelsniper.command.invalid-color": "&cInvalid color: &b{0}&c.", + "voxelsniper.command.invalid-duration": "&cInvalid duration: &b{0}&c.", + "voxelsniper.command.invalid-player": "&cInvalid player: &b{0}&c.", + + "voxelsniper.command.invalid-file": "&cInvalid file: &b{0}&c.", + "voxelsniper.command.invalid-biome": "&cInvalid biome type: &b{0}&c.", + "voxelsniper.command.invalid-block": "&cInvalid block: &b{0}&c.", + "voxelsniper.command.invalid-block-type": "&cInvalid block type: &b{0}&c.", + "voxelsniper.command.invalid-entity-class": "&cInvalid entity class: &b{0}&c.", + "voxelsniper.command.invalid-entity": "&cInvalid entity type: &b{0}&c.", + "voxelsniper.command.invalid-pattern": "&cInvalid pattern: &b{0}&c.", + "voxelsniper.command.brush.restricted-size": "&cSize is restricted to &b{0} &cfor you.", "voxelsniper.command.brush.no-alias": "&cCould not find brush for alias &b{0}&c.", "voxelsniper.command.toolkit.assign-help": "/btool assign ", "voxelsniper.command.toolkit.remove-help-1": "/btool remove ", "voxelsniper.command.toolkit.remove-help-2": "/btool remove", - "voxelsniper.command.toolkit.assigned": "&b{0} &f has been assigned to &b'{1}' &fas action &a{2}&f.", + "voxelsniper.command.toolkit.assigned": "&b{0} &fhas been assigned to &b'{1}' &fas action &a{2}&f.", + "voxelsniper.command.toolkit.unassigned": "&b{0} &fhas been unassigned from &b'{1}'&f.", + "voxelsniper.command.toolkit.removed": "&fToolkit &b{0} &fhas been removed&f.", "voxelsniper.command.toolkit.not-found": "&cToolkit &b{0} &cnot found.", "voxelsniper.command.toolkit.empty-hands": "&cCan't unassign empty hands.", "voxelsniper.command.toolkit.default-tool": "&cCan't unassign default tool.", "voxelsniper.command.default.reset": "&bBrush settings reset to their default values.", - "voxelsniper.command.goto.invalid-syntax": "&cInvalid syntax. Must be a coordinate, not: {0}, {1}", "voxelsniper.command.goto.woosh": "&aWoosh!", - "voxelsniper.command.paint.invalid-art": "&cInvalid art name: &b{0}", - "voxelsniper.command.performer.invalid-brush": "&cThis brush is not a performer brush.", - "voxelsniper.command.voxel-center.invalid-input": "&cInvalid input. Must be a number, not: &b{0}", - "voxelsniper.command.voxel-center.invalid-input-none": "&cInvalid input. Must be a number, not &bnone", - "voxelsniper.command.voxel-chunk.refreshed": "&9Chunk has been refreshed.", - "voxelsniper.command.voxel-executor.invalid-pattern": "&cYou have entered an invalid pattern: &b{0}", - - "voxelsniper.command.voxel-height.invalid-input": "&cInvalid input. Must be a number, not: &b{0}", - "voxelsniper.command.voxel-height.invalid-input-none": "&cInvalid input. Must be a number, not &bnone", - - "voxelsniper.command.voxel-replace-executor.invalid-block": "&cYou have entered an invalid block type: &b{0}", - - "voxelsniper.command.voxel-sniper.brush.list-prefix": "&bAvailable brushes: {0}", - "voxelsniper.command.voxel-sniper.invalid-range": "&cValues less than 1 are not allowed.", + "voxelsniper.command.voxel-sniper.brushes.list-prefix": "&bAvailable brushes (abbreviated): {0}", + "voxelsniper.command.voxel-sniper.brushes-long.list-prefix": "&bAvailable brushes: {0}", "voxelsniper.command.voxel-sniper.distance-restriction": "&6Distance Restriction toggled {0}&6. Range is &d{1}", "voxelsniper.command.voxel-sniper.performer.list-prefix": "&bAvailable performers (abbreviated): {0}", "voxelsniper.command.voxel-sniper.performer-long.list-prefix": "&bAvailable performers: {0}", "voxelsniper.command.voxel-sniper.toggle": "FastAsyncVoxelSniper is {0}", "voxelsniper.command.voxel-sniper.admin-info": "{0} version {1}\n{2}\nWebsite: {3}\nWiki: {4}\nDiscord: {5}", "voxelsniper.command.voxel-sniper.config-reload": "&aFastAsyncVoxelSniper config reloaded!", + "voxelsniper.command.voxel-sniper.debugpaste-written": "&7FAVS report written to {0}", "voxelsniper.command.voxel-sniper.debugpaste-fail": "&cFailed to upload debugpaste because of &b{0}", "voxelsniper.command.voxel-sniper.info": "&4FastAsyncVoxelSniper - Current Brush Settings:", @@ -106,7 +122,6 @@ "voxelsniper.brush.clean-snow.info": "&6Clean Snow Brush Parameters:\n&b/b cls [true|false] -- Uses a true sphere algorithm instead of the skinnier version with classic sniper nubs. Default is false.", "voxelsniper.brush.comet.info": "&cWarning: This brush is not undo-able! You can use //ex to extinguish the fire it creates.\n&6Comet Brush Parameters:\n&b/b com balls [big|small] -- Sets your ball size.", - "voxelsniper.brush.comet.invalid-size": "&cInvalid ball size: &b{0}", "voxelsniper.brush.comet.set-size": "&6Ball size set to: &b{0}", "voxelsniper.brush.copy-pasta.info": "&6CopyPasta Brush Parameters:\n&b/b cp air -- Toggles include (default) or exclude air during paste.\n&b/b cp [0|90|180|270] -- Toggles rotation. Default is 0.", @@ -123,7 +138,6 @@ "voxelsniper.brush.erode.info": "&6Erode Brush Parameters:\n&b/b e f [n] -- Sets erosion faces to n.\n&b/b e e [n] -- Sets fill faces to n.\n&b/b e F [n] -- Sets erosion recursions to n.\n&b/b e E [n] -- Sets fill recursions to n.\n&6Erode Brush Presets:\n&b/b eb default -- Sets erosion faces to 0, erosion recursions to 1, fill faces to 0 and fill recursions to 1.\n&b/b eb melt -- Sets erosion faces to 2, erosion recursions to 1, fill faces to 5 and fill recursions to 1.\n&b/b eb fill -- Sets erosion faces to 5, erosion recursions to 1, fill faces to 2 and fill recursions to 1.\n&b/b eb smooth -- Sets erosion faces to 3, erosion recursions to 1, fill faces to 3 and fill recursions to 1.\n&b/b eb lift -- Sets erosion faces to 6, erosion recursions to 0, fill faces to 1 and fill recursions to 1.\n&b/b eb floatclean -- Sets erosion faces to 0, erosion recursions to 1, fill faces to 6 and fill recursions to 1.", "voxelsniper.brush.erode.set-preset": "&dBrush preset set to: &5{0}", - "voxelsniper.brush.erode.invalid-preset": "&cInvalid preset: &b{0}", "voxelsniper.brush.erode.set-erosion-faces": "&bErosion faces set to: &f{0}", "voxelsniper.brush.erode.set-fill-faces": "&9Fill faces set to: &f{0}", "voxelsniper.brush.erode.set-erosion-recursions": "&9Erosion recursions set to: &f{0}", @@ -143,9 +157,7 @@ "voxelsniper.brush.generate-tree.info": "&6Generate Tree Brush Parameters:x\n&b/b gt default -- Restores default parameters.\n&b/b gt lt [t] -- Sets leaf type to t. (e.g. oak_leaves)\n&b/b gt wt [t] -- Sets wood type to t. (e.g. oak_log)\n&b/b gt tt [n] -- Sets tree thickness to n. (whole number)\n&b/b gt rf [true|false] -- Sets root float.\n&b/b gt sh [n] -- Sets starting height to n. (whole number)\n&b/b gt rl [n] -- Sets root length to n. (whole number)\n&b/b gt ts [n] -- Sets trunk slope chance to n. (0-100)\n&b/b gt bl [n] -- Sets branch length to n. (whole number)\n&b/b gt minr [n] -- Sets minimum roots to n. (whole number)\n&b/b gt maxr [n] -- Sets maximum roots to n. (whole number)\n&b/b gt minh [n] -- Sets minimum height to n. (whole number)\n&b/b gt maxh [n] -- Sets maximum height to n. (whole number)\n&b/b gt minl [n] -- Sets minimum leaf node size to n. (whole number)\n&b/b gt maxl [n] -- Sets maximum leaf node size to n. (whole number)", "voxelsniper.brush.generate-tree.set-leaf-type": "&9Leaf Type set to: &f{0}", - "voxelsniper.brush.generate-tree.invalid-leaf-type": "&cInvalid leaf type: &b{0}", "voxelsniper.brush.generate-tree.set-wood-type": "&9Wood Type set to: &f{0}", - "voxelsniper.brush.generate-tree.invalid-wood-type": "&cInvalid wood type: &b{0}", "voxelsniper.brush.generate-tree.set-thickness": "&9Thickness Type set to: &f{0}", "voxelsniper.brush.generate-tree.set-floating-roots": "&9Floating Roots set to: &f{0}", "voxelsniper.brush.generate-tree.set-start-height": "&9Starting Height set to: &f{0}", @@ -153,22 +165,19 @@ "voxelsniper.brush.generate-tree.set-trunk-slope": "&9Trunk Slope set to: &f{0}", "voxelsniper.brush.generate-tree.set-branch-length": "&9Branch Length set to: &f{0}", "voxelsniper.brush.generate-tree.set-minimum-roots": "&9Minimum Roots set to: &f{0}", - "voxelsniper.brush.generate-tree.invalid-minimum-roots": "&cMinimum Roots cannot exceed Maximum Roots, set to: &f{0}", "voxelsniper.brush.generate-tree.set-maximum-roots": "&9Maximum Roots set to: &f{0}", - "voxelsniper.brush.generate-tree.invalid-maximum-roots": "&cMaximum Roots cannot be lower than Minimum Roots, set to: &f{0}", "voxelsniper.brush.generate-tree.set-minimum-height": "&9Minimum Height set to: &f{0}", - "voxelsniper.brush.generate-tree.invalid-minimum-height": "&cMinimum Height cannot exceed Maximum Height, set to: &f{0}", "voxelsniper.brush.generate-tree.set-maximum-height": "&9Maximum Height set to: &f{0}", - "voxelsniper.brush.generate-tree.invalid-maximum-height": "&cMaximum Height cannot be lower than Minimum Height, set to: &f{0}", "voxelsniper.brush.generate-tree.set-minimum-leaf-thickness": "&9Minimum Leaf Thickness set to: &f{0}", "voxelsniper.brush.generate-tree.set-maximum-leaf-thickness": "&9Maximum Leaf Thickness set to: &f{0}", "voxelsniper.brush.heat-ray.info": "&6Heat Ray Brush Parameters:\n&b/b hr oct [n] -- Sets octave parameter to n for the noise generator.\n&b/b hr amp [n] -- Sets amplitude parameter to n for the noise generator.\n&b/b hr freq [n] -- Sets frequency parameter to n for the noise generator.", + "voxelsniper.brush.heat-ray.set-soul-fire": "&bSoul fire mode is {0}", "voxelsniper.brush.heat-ray.set-octaves": "&aOctaves set to: &f{0}", "voxelsniper.brush.heat-ray.set-amplitude": "&aAmplitude set to: &f{0}", "voxelsniper.brush.heat-ray.set-frequency": "&aFrequency set to: &f{0}", - "voxelsniper.brush.jockey.info": "&6Jockey Brush Parameters:\n&b/b jockey [true|false] [true|false] [true|false] -- Sets whether players only or entities should be affected, whether entities should be inverted and whether entities should be stacked.", + "voxelsniper.brush.jockey.info": "&6Jockey Brush Parameters:\n&b/b jockey t [t] -- Sets the selected jockey type to t.\n&b/b jockey [true|false] [true|false] [true|false] -- Sets whether players only or entities should be affected, whether entities should be inverted and whether entities should be stacked.", "voxelsniper.brush.jockey.set-mode": "&6Jockey mode set to: &a{0}", "voxelsniper.brush.jockey.top-ejected": "&6The guy on top of you has been ejected!", "voxelsniper.brush.jockey.ejected": "&6You have been ejected!", @@ -194,7 +203,7 @@ "voxelsniper.brush.ocean.set-water-level": "&9Water level set to: &a{0}", "voxelsniper.brush.ocean.set-floor-cover": "&9Floor cover {0}", - "voxelsniper.brush.pull.info": "&6Pull Brush Parameters:\n&b/b pull [n] -- Sets pinch and bubble to n.", + "voxelsniper.brush.pull.info": "&6Pull Brush Parameters:\n&b/b pull [p] [b] -- Sets pinch to p and bubble to b.", "voxelsniper.brush.pull.set-pinch": "&bPinch set to: &f{0}", "voxelsniper.brush.pull.set-bubble": "&bBubble set to: &f{0}", @@ -228,12 +237,11 @@ "voxelsniper.brush.sign-overwrite.info": "&3The arrow writes the internal line buffer to the target sign.\n&3The gunpowder reads the text of the target sign into the internal buffer.\n&3Colors can be used using the \"&\" symbol.\n&6Sign Overwrite Brush Parameters:\n&b/b sio 1 [set|toggle] (...) -- Sets the text of the first sign line. (e.g. /b sio 1 set Blah Blah | /b sio 1 toggle)\n&b/b sio 2 [set|toggle] (...) -- Sets the text of the second sign line. (e.g. /b sio 2 set Blah Blah | /b sio 2 toggle\n&b/b sio 3 [set|toggle] (...) -- Sets the text of the third sign line. (e.g. /b sio 3 set Blah Blah | /b sio 3 toggle\n&b/b sio 4 [set|toggle] (...) -- Sets the text of the fourth sign line. (e.g. /b sio 4 set Blah Blah | /b sio 4 toggle\n&b/b sio clear -- Clears the line buffer. (Alias: /b sio c)\n&b/b sio clearall -- Clears the line buffer and sets all lines back to enabled (Alias: /b sio ca)\n&b/b sio side [s] -- Sets the sign side to s. (not available in versions prior to 1.20)\n&b/b sio multiple [true|false] -- Enables or disables ranged mode. (see Wiki for more information) (Alias: /b sio m [true|false])\n&b/b sio save [n] -- Save you buffer to a file named n. (Alias: /b sio s [n])\n&b/b sio open [n] -- Loads a buffer from a file named n. (Alias: /b sio o [n])", "voxelsniper.brush.sign-overwrite.list-prefix": "&bAvailable sides: {0}", "voxelsniper.brush.sign-overwrite.cleared": "&9Internal text buffer cleared.", - "voxelsniper.brush.sign-overwrite.cleared-reset": "&9Internal text buffer cleard and states back to enabled.", + "voxelsniper.brush.sign-overwrite.cleared-reset": "&9Internal text buffer cleared and states back to enabled.", "voxelsniper.brush.sign-overwrite.invalid-length": "&cWarning: Text on line &b{0} &cexceeds the maximum line length of &b{1} &ccharacters. Your text will be cut.", "voxelsniper.brush.sign-overwrite.set-line": "&bLine {0} set to: &f{1}", "voxelsniper.brush.sign-overwrite.line-status": "&9Line &b{0} &9is {1}", "voxelsniper.brush.sign-overwrite.set-side": "&9Side set to: &f{0}", - "voxelsniper.brush.sign-overwrite.invalid-side": "&cInvalid side: &b{0}", "voxelsniper.brush.sign-overwrite.legacy-side": "&cWarning: Two-sided signs are not available in your version.", "voxelsniper.brush.sign-overwrite.set-ranged-mode": "&9Ranged mode is {0}", "voxelsniper.brush.sign-overwrite.brush-size": "&aBrush size set to: &c{0}", @@ -242,7 +250,6 @@ "voxelsniper.brush.sign-overwrite.no-sign": "&cDid not found any sign in selection box.", "voxelsniper.brush.sign-overwrite.set-buffer": "&9Buffer text set to: ", "voxelsniper.brush.sign-overwrite.buffer-line": "&bLine {0} ({1}&b): &7{2}", - "voxelsniper.brush.sign-overwrite.file-exists": "&cThis file already exists.", "voxelsniper.brush.sign-overwrite.file-saved": "&9File saved successfully.", "voxelsniper.brush.sign-overwrite.file-save-failed": "&cFailed to save file: &f{0}", "voxelsniper.brush.sign-overwrite.file-missing": "&cThis file does not exist.", @@ -261,11 +268,10 @@ "voxelsniper.brush.spiral-staircase.type.step": "Step", "voxelsniper.brush.spiral-staircase.type.stair": "Stair", - "voxelsniper.brush.tree-sniper.info": "&6Tree Snipe Brush Parameters:\n&b/b t [t] -- Sets the selected tree type to t.\n&b/b t list -- Lists all available trees.", - "voxelsniper.brush.tree-sniper.list-prefix": "&bAvailable biomes: {0}", - "voxelsniper.brush.tree-sniper.set-tree": "&6Tree type set to: &2{0}", - "voxelsniper.brush.tree-sniper.invalid-tree": "&cInvalid tree type: &b{0}", - "voxelsniper.brush.tree-sniper.generate-failed": "&cFailed to generate a tree!", + "voxelsniper.brush.tree-snipe.info": "&6Tree Snipe Brush Parameters:\n&b/b t [t] -- Sets the selected tree type to t.\n&b/b t list -- Lists all available trees.", + "voxelsniper.brush.tree-snipe.list-prefix": "&bAvailable biomes: {0}", + "voxelsniper.brush.tree-snipe.set-tree": "&6Tree type set to: &2{0}", + "voxelsniper.brush.tree-snipe.generate-failed": "&cFailed to generate a tree!", "voxelsniper.brush.voltmeter.data": "&bBlocks until repeater needed: &f{0}", "voxelsniper.brush.voltmeter.direct": "&bDirect Power: &c{0} &bIndirect Power: &c{1}", @@ -282,12 +288,12 @@ "voxelsniper.brush.disc-face.info": "&6Disc Brush Parameters:\n&b/b d [true|false] -- Uses a true circle algorithm instead of the skinnier version with classic sniper nubs. (false is default)", "voxelsniper.brush.splatter-ball.info": "&6Splatter Ball Brush Parameters:\n&b/b sb s [n] -- Sets a seed percentage to n (1-9999). 100 = 1% Default is 1000.\n&b/b sb g [n] -- Sets a growth percentage to n (1-9999). Default is 1000.\n&b/b sb r [n] -- Sets a recursion i (1-10). Default is 3.", - "voxelsniper.brush.splatter-ball.set-seed-parcent": "&bSeed percent set to: &f{0}%", + "voxelsniper.brush.splatter-ball.set-seed-percent": "&bSeed percent set to: &f{0}%", "voxelsniper.brush.splatter-ball.set-growth-percent": "&bGrowth percent set to: &f{0}%", "voxelsniper.brush.splatter-ball.set-splatter-recursions": "&bSplatter recursions set to: &f{0}", "voxelsniper.brush.splatter-disc.info": "&6Splatter Disc Brush Parameters:\n&b/b sd s [n] -- Sets a seed percentage to n (1-9999). 100 = 1% Default is 1000.\n&b/b sd g [n] -- Sets a growth percentage to n (1-9999). Default is 1000.\n&b/b sd r [n] -- Sets a recursion i (1-10). Default is 3.", - "voxelsniper.brush.splatter-disc.set-seed-parcent": "&bSeed percent set to: &f{0}%", + "voxelsniper.brush.splatter-disc.set-seed-percent": "&bSeed percent set to: &f{0}%", "voxelsniper.brush.splatter-disc.set-growth-percent": "&bGrowth percent set to: &f{0}%", "voxelsniper.brush.splatter-disc.set-splatter-recursions": "&bSplatter recursions set to: &f{0}", @@ -296,18 +302,18 @@ "voxelsniper.brush.splatter-overlay.set-overlay-natural": "&9Overlay only natural block types is {0}", "voxelsniper.brush.splatter-overlay.set-randomize-height": "&cRandomize height is: {0}", "voxelsniper.brush.splatter-overlay.set-depth": "&bDepth set to: &f{0}", - "voxelsniper.brush.splatter-overlay.set-seed-parcent": "&bSeed percent set to: &f{0}%", + "voxelsniper.brush.splatter-overlay.set-seed-percent": "&bSeed percent set to: &f{0}%", "voxelsniper.brush.splatter-overlay.set-growth-percent": "&bGrowth percent set to: &f{0}%", "voxelsniper.brush.splatter-overlay.set-splatter-recursions": "&bSplatter recursions set to: &f{0}", "voxelsniper.brush.splatter-overlay.set-y-offset": "&bY-Offset set to: &f{0}", "voxelsniper.brush.splatter-voxel.info": "&6Splatter Voxel Brush Parameters:\n&b/b sv s [n] -- Sets a seed percentage to n (1-9999). 100 = 1% Default is 1000.\n&b/b sv g [n] -- Sets a growth percentage to n (1-9999). Default is 1000.\n&b/b sv r [n] -- Sets a recursion i (1-10). Default is 3.", - "voxelsniper.brush.splatter-voxel.set-seed-parcent": "&bSeed percent set to: &f{0}%", + "voxelsniper.brush.splatter-voxel.set-seed-percent": "&bSeed percent set to: &f{0}%", "voxelsniper.brush.splatter-voxel.set-growth-percent": "&bGrowth percent set to: &f{0}%", "voxelsniper.brush.splatter-voxel.set-splatter-recursions": "&bSplatter recursions set to: &f{0}", "voxelsniper.brush.splatter-voxel-disc.info": "&6Splatter Voxel Disc Brush Parameters:\n&b/b svd s [n] -- Sets a seed percentage to n (1-9999). 100 = 1% Default is 1000.\n&b/b svd g [n] -- Sets a growth percentage to n (1-9999). Default is 1000.\n&b/b svd r [n] -- Sets a recursion i (1-10). Default is 3.", - "voxelsniper.brush.splatter-voxel-disc.set-seed-parcent": "&bSeed percent set to: &f{0}%", + "voxelsniper.brush.splatter-voxel-disc.set-seed-percent": "&bSeed percent set to: &f{0}%", "voxelsniper.brush.splatter-voxel-disc.set-growth-percent": "&bGrowth percent set to: &f{0}%", "voxelsniper.brush.splatter-voxel-disc.set-splatter-recursions": "&bSplatter recursions set to: &f{0}", @@ -327,14 +333,12 @@ "voxelsniper.brush.entity.info": "&6Entity Brush Parameters:\n&b/b en [t] -- Sets the selected entity type to t.\n&b/b en list -- Lists all available entities.", "voxelsniper.brush.entity.list-prefix": "&bAvailable entity types: {0}", "voxelsniper.brush.entity.set-entity-type": "&aEntity Type set to: &2{0}", - "voxelsniper.brush.entity.invalid-entity-type": "&cInvalid entity type: &b{0}", "voxelsniper.brush.entity.cannot-spawn": "&cCannot spawn entity!", "voxelsniper.brush.entity-removal.info": "&6Entity Removal Brush Parameters:\n&b/b er + [t] -- Adds an exemption.\n&b/b er - [t] -- Removes an exemption.\n&b/b er list -- Lists all exemptions.", "voxelsniper.brush.entity-removal.list-prefix": "&bExemptions: {0}", "voxelsniper.brush.entity-removal.add-entity-class": "&aAdded &b\"{0}\" &ato entity exemptions list.", "voxelsniper.brush.entity-removal.remove-entity-class": "&eRemoved v\"{0}\" &efrom entity exemptions list.", - "voxelsniper.brush.entity-removal.invalid-entity-class": "&cInvalid entity class: &b{0}", "voxelsniper.brush.entity-removal.removed": "&aRemoved &c{0} &aentities our of &9{1} &achunk(s).", "voxelsniper.brush.set-redstone-flip.info": "&6Set Redstone Flip Brush Parameters:\n&b/b setrf [d] -- Valid direction inputs are: n, s, ns, e, w, ew. Sets the direction that you wish to flip your repeaters, defaults to north/south.", @@ -365,12 +369,12 @@ "voxelsniper.brush.stencil.pasted": "&b\"{0}\" &9pasted. Volume is &b{1} &9blocks.", "voxelsniper.brush.stencil.saved": "&9Saved as &b\"{0}\"&9. Volume is &b{1} &9blocks.", - "voxelsniper.brush.stencil-list.missing-file": "&cYou did not specify a filename for the list. This is required.", + "voxelsniper.brush.stencil-list.missing-file": "&cYou did not specify a filename for the stencil(s). This is required.", "voxelsniper.brush.stencil.info": "&6Stencil Brush Parameters:\n&b/b st (full|fill|replace) [s] -- Loads the specified stencil s. Full/fill/replace must come first. Full = paste all blocks, fill = paste only into air blocks, replace = paste full blocks in only, but replace anything in their way.", "voxelsniper.brush.stencil.loaded": "&9Stencil &b\"{0}\" &9exists and is loaded. Make sure you are using gunpowder if you do not want any chance of overwriting the file.", "voxelsniper.brush.stencil.missing": "&cStencil &b\"{0}\" &cdoes not exist. Ready to be saved to, but cannot be pasted.", - "voxelsniper.brush.stencil.wrong-stencil-name": "&cYou need to type a valid stencil name.", + "voxelsniper.brush.stencil.invalid-stencil-name": "&cYou need to type a valid stencil name.", "voxelsniper.brush.stencil.coordinates": "&9X: &b{1} &9Z: &b{2} &9Y: &b{3}", "voxelsniper.brush.stencil.area-too-large": "&cArea selected is too large. (Limit is {0} blocks)", "voxelsniper.brush.stencil.paste-point": "&7Paste Reference point.", @@ -379,7 +383,7 @@ "voxelsniper.brush.stencil-list.info": "&6Stencil List Brush Parameters:\n&b/b sl (full|fill|replace) [s] -- Loads the specified stencil list s. Full/fill/replace must come first. Full = paste all blocks, fill = paste only into air blocks, replace = paste full blocks in only, but replace anything in their way.", "voxelsniper.brush.stencil-list.loaded": "&9Stencil List &b\"{0}\" &9exists and is loaded.", "voxelsniper.brush.stencil-list.missing": "&cStencil List &b\"{0}\" &cdoes not exist. This brush will not function without a valid stencil list.", - "voxelsniper.brush.stencil-list.wrong-stencil-list-name": "&cYou need to type a valid stencil list name.", + "voxelsniper.brush.stencil-list.invalid-stencil-list-name": "&cYou need to type a valid stencil list name.", "voxelsniper.brush.stencil-list.stencil-loaded": "&9Stencil &b\"{0}\" &9is loaded.", "voxelsniper.performer-brush.ball.info": "&6Ball Brush Parameters:\n&b/b b [true|false] -- Uses a true sphere algorithm instead of the skinnier version with classic sniper nubs. Default is false.", @@ -427,11 +431,10 @@ "voxelsniper.performer-brush.punish.info": "&6Punish Brush Parameters:\n&b/vc [n] -- Sets Punishment level to n.\n&b/vh [n] -- Sets Punishment duration to n.\n&b/b p [p] -- Sets Punishment to p.\n&b/b p toggleSM [s] -- Makes Punish Brush only affect s player name.\n&b/b p toggleSelf -- Toggles whether you get hit as well.\n&b/b p toggleHypnoLandscape -- Makes Hypno punishment only affect landscape.\n&b/b p list -- Lists all available punishments.", "voxelsniper.performer-brush.punish.list-prefix": "&bAvailable punishments: {0}", "voxelsniper.performer-brush.punish.set-punishment": "&9Punishment set to: &f{0}", - "voxelsniper.performer-brush.punish.invalid-punishment": "&cInvalid punishment: &b{0}", "voxelsniper.performer-brush.punish.hit-self": "&bYour punishments will now affect you too!", "voxelsniper.performer-brush.punish.hit-other": "&bYour punishments will no longer affect you!", + "voxelsniper.performer-brush.punish.hypno-affect-landscape": "&bHypno affect landscape is {0}", "voxelsniper.performer-brush.punish.hit-player": "&bYour punishments will now only affect: &f{0}", - "voxelsniper.performer-brush.punish.invalid-player": "&cInvalid player: &b{0}", "voxelsniper.performer-brush.punish.applied": "&4Punishment applied to &c{0} &4living entities.", "voxelsniper.performer-brush.punish.type.fire": "Fire", "voxelsniper.performer-brush.punish.type.lightning": "Lightning", @@ -484,7 +487,6 @@ "voxelsniper.performer-brush.three-point-circle.info": "&3Select three corners with the arrow brush, then generate the Circle with the gunpowder brush.\n&6Three Point Circle Brush Parameters:\n&b/b tpc [t] -- Sets the calculations to emphasize accuracy or smoothness to t.", "voxelsniper.performer-brush.three-point-circle.list-prefix": "&bAvailable tolerances: {0}", "voxelsniper.performer-brush.three-point-circle.set-tolerance": "&9Tolerance set to: &f{0}", - "voxelsniper.performer-brush.three-point-circle.invalid-tolerance": "&cInvalid tolerance: &b{0}", "voxelsniper.performer-brush.three-point-circle.first-corner": "&7First corner set.", "voxelsniper.performer-brush.three-point-circle.second-corner": "&7Second corner set.", "voxelsniper.performer-brush.three-point-circle.third-corner": "&7Third corner set.", @@ -506,18 +508,9 @@ "voxelsniper.warning.brush.off-world-end": "&5Warning: off-world end position.", "voxelsniper.warning.brush.first-coordinate": "&cWarning: You did not select a first coordinate with the arrow.", - "voxelsniper.error.unexpected": "&cAn unexpected error occured.", - "voxelsniper.error.invalid-number": "&cInvalid number: &b{0}&c.", - "voxelsniper.error.invalid-number-between": "&cInvalid number: &b{0}&c, must be {1}-{2}.", - "voxelsniper.error.invalid-number-greater": "&cInvalid number: &b{0}&c, must be greater than &b{1}.", - "voxelsniper.error.invalid-number-greater-equal": "&cInvalid number: &b{0}&c, must be greater than or equal to &b{1}.", - "voxelsniper.error.invalid-number-lower": "&cInvalid number: &b{0}&c, must be lower than &b{1}.", - "voxelsniper.error.invalid-number-lower-equal": "&cInvalid number: &b{0}&c, must be lower than or equal to &b{1}.", - - "voxelsniper.error.brush.invalid-parameters": "&cInvalid brush parameters! Use the \"info\" parameter to display parameter info.", - "voxelsniper.error.brush.invalid-parameters-length": "&cInvalid brush parameters length! Use the \"info\" parameter to display parameter info.", "voxelsniper.error.brush.invalid-voxel-height": "&cInvalid voxel height: &b{0}", - "voxelsniper.error.brush.invalid-biome": "&cInvalid biome type: &b{0}", "voxelsniper.error.brush.invalid-selection": "&cSelection size above {0} limit, please use a smaller selection.", - "voxelsniper.error.brush.different-world": "&cYou selected points in different worlds!" + "voxelsniper.error.brush.different-world": "&cYou selected points in different worlds!", + + "voxelsniper.error.unexpected": "&cAn unexpected error occurred." }