From e447ac55dbd369b5bfb4412f5199aad660a8cac7 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Wed, 24 Apr 2019 00:00:56 -0700 Subject: [PATCH] Port super pickaxe commands --- .../command/SuperPickaxeCommands.java | 42 +++++++++---------- .../argument/ZonedDateTimeConverter.java | 19 +++++++++ .../platform/PlatformCommandMananger.java | 27 +++++++++--- 3 files changed, 59 insertions(+), 29 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SuperPickaxeCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SuperPickaxeCommands.java index a3e21db8a..754473a9a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SuperPickaxeCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SuperPickaxeCommands.java @@ -19,9 +19,6 @@ package com.sk89q.worldedit.command; -import com.sk89q.minecraft.util.commands.Command; -import com.sk89q.minecraft.util.commands.CommandContext; -import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; @@ -29,8 +26,14 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.tool.AreaPickaxe; import com.sk89q.worldedit.command.tool.RecursivePickaxe; import com.sk89q.worldedit.command.tool.SinglePickaxe; +import com.sk89q.worldedit.command.util.CommandPermissions; +import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.entity.Player; +import org.enginehub.piston.annotation.Command; +import org.enginehub.piston.annotation.CommandContainer; +import org.enginehub.piston.annotation.param.Arg; +@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class SuperPickaxeCommands { private final WorldEdit we; @@ -39,32 +42,26 @@ public class SuperPickaxeCommands { } @Command( - aliases = { "single" }, - usage = "", - desc = "Enable the single block super pickaxe mode", - min = 0, - max = 0 + name = "single", + desc = "Enable the single block super pickaxe mode" ) @CommandPermissions("worldedit.superpickaxe") public void single(Player player, LocalSession session) throws WorldEditException { - session.setSuperPickaxe(new SinglePickaxe()); session.enableSuperPickAxe(); player.print("Mode changed. Left click with a pickaxe. // to disable."); } @Command( - aliases = { "area" }, - usage = "", - desc = "Enable the area super pickaxe pickaxe mode", - min = 1, - max = 1 + name = "area", + desc = "Enable the area super pickaxe pickaxe mode" ) @CommandPermissions("worldedit.superpickaxe.area") - public void area(Player player, LocalSession session, CommandContext args) throws WorldEditException { + public void area(Player player, LocalSession session, + @Arg(desc = "The range of the area pickaxe") + int range) throws WorldEditException { LocalConfiguration config = we.getConfiguration(); - int range = args.getInteger(0); if (range > config.maxSuperPickaxeSize) { player.printError("Maximum range: " + config.maxSuperPickaxeSize); @@ -77,17 +74,16 @@ public class SuperPickaxeCommands { } @Command( - aliases = { "recur", "recursive" }, - usage = "", - desc = "Enable the recursive super pickaxe pickaxe mode", - min = 1, - max = 1 + name = "recursive", + aliases = { "recur" }, + desc = "Enable the recursive super pickaxe pickaxe mode" ) @CommandPermissions("worldedit.superpickaxe.recursive") - public void recursive(Player player, LocalSession session, CommandContext args) throws WorldEditException { + public void recursive(Player player, LocalSession session, + @Arg(desc = "The range of the recursive pickaxe") + double range) throws WorldEditException { LocalConfiguration config = we.getConfiguration(); - double range = args.getDouble(0); if (range > config.maxSuperPickaxeSize) { player.printError("Maximum range: " + config.maxSuperPickaxeSize); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ZonedDateTimeConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ZonedDateTimeConverter.java index 5d96c28ab..4efd97555 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ZonedDateTimeConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ZonedDateTimeConverter.java @@ -1,3 +1,22 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + package com.sk89q.worldedit.command.argument; import com.sk89q.worldedit.LocalSession; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java index 795d8cddb..b6c2b6c89 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java @@ -54,6 +54,8 @@ import com.sk89q.worldedit.command.SnapshotCommands; import com.sk89q.worldedit.command.SnapshotCommandsRegistration; import com.sk89q.worldedit.command.SnapshotUtilCommands; import com.sk89q.worldedit.command.SnapshotUtilCommandsRegistration; +import com.sk89q.worldedit.command.SuperPickaxeCommands; +import com.sk89q.worldedit.command.SuperPickaxeCommandsRegistration; import com.sk89q.worldedit.command.argument.Arguments; import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter; import com.sk89q.worldedit.command.argument.DirectionConverter; @@ -257,7 +259,7 @@ public final class PlatformCommandMananger { .build()); }); commandManager.register("snapshot", cmd -> { - cmd.aliases(ImmutableList.of("snapshot", "snap")); + cmd.aliases(ImmutableList.of("snap")); cmd.description("Snapshot commands for saving/loading snapshots"); cmd.action(Command.Action.NULL_ACTION); @@ -274,6 +276,24 @@ public final class PlatformCommandMananger { .required() .build()); }); + commandManager.register("superpickaxe", cmd -> { + cmd.aliases(ImmutableList.of("pickaxe", "sp")); + cmd.description("Super-pickaxe commands"); + cmd.action(Command.Action.NULL_ACTION); + + CommandManager manager = DefaultCommandManagerService.getInstance() + .newCommandManager(); + register( + manager, + SuperPickaxeCommandsRegistration.builder(), + new SuperPickaxeCommands(worldEdit) + ); + + cmd.addPart(SubCommandPart.builder("action", "Sub-command to run.") + .withCommands(manager.getAllCommands().collect(Collectors.toList())) + .required() + .build()); + }); commandManager.register("brush", cmd -> { cmd.aliases(ImmutableList.of("br")); cmd.description("Brushing commands"); @@ -353,7 +373,6 @@ public final class PlatformCommandMananger { dispatcher = new CommandGraph() .builder(builder) .commands() - .registerMethods(new SnapshotUtilCommands(worldEdit)) .registerMethods(new ToolUtilCommands(worldEdit)) .registerMethods(new ToolCommands(worldEdit)) .registerMethods(new UtilityCommands(worldEdit)) @@ -372,10 +391,6 @@ public final class PlatformCommandMananger { .register(adapt(new ShapedBrushCommand(ProvidedValue.create(new Deform("y-=1", Mode.RAW_COORD), "Raise one block"), "worldedit.brush.raise")), "raise") .register(adapt(new ShapedBrushCommand(ProvidedValue.create(new Deform("y+=1", Mode.RAW_COORD), "Lower one block"), "worldedit.brush.lower")), "lower") .parent() - .group("superpickaxe", "pickaxe", "sp") - .describeAs("Super-pickaxe commands") - .registerMethods(new SuperPickaxeCommands(worldEdit)) - .parent() .group("tool") .describeAs("Bind functions to held items") .registerMethods(new ToolCommands(worldEdit))