Port worldedit commands

This commit is contained in:
Kenzie Togami 2019-04-25 21:03:28 -07:00
parent 9b0fda9f83
commit d8290cbd8f
No known key found for this signature in database
GPG Key ID: 5D200B325E157A81
3 changed files with 60 additions and 45 deletions

View File

@ -509,8 +509,8 @@ public class UtilityCommands {
@Arg(desc = "The page to retrieve", def = "1")
int page,
@Arg(desc = "The command to retrieve help for", def = "", variable = true)
List<String> commandPath) throws WorldEditException {
PrintCommandHelp.help(commandPath, page, we, actor);
List<String> command) throws WorldEditException {
PrintCommandHelp.help(command, page, we, actor);
}

View File

@ -20,12 +20,12 @@
package com.sk89q.worldedit.command;
import com.google.common.io.Files;
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.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.PrintCommandHelp;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent;
import com.sk89q.worldedit.extension.platform.Actor;
@ -36,6 +36,10 @@ import com.sk89q.worldedit.util.paste.ActorCallbackPaste;
import com.sk89q.worldedit.util.report.ConfigReport;
import com.sk89q.worldedit.util.report.ReportList;
import com.sk89q.worldedit.util.report.SystemInfoReport;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.Switch;
import java.io.File;
import java.io.IOException;
@ -44,8 +48,10 @@ import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.util.List;
import java.util.Locale;
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class WorldEditCommands {
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
@ -56,11 +62,9 @@ public class WorldEditCommands {
}
@Command(
aliases = { "version", "ver" },
usage = "",
desc = "Get WorldEdit version",
min = 0,
max = 0
name = "version",
aliases = { "ver" },
desc = "Get WorldEdit version"
)
public void version(Actor actor) throws WorldEditException {
actor.print("WorldEdit version " + WorldEdit.getVersion());
@ -81,11 +85,8 @@ public class WorldEditCommands {
}
@Command(
aliases = { "reload" },
usage = "",
desc = "Reload configuration",
min = 0,
max = 0
name = "reload",
desc = "Reload configuration"
)
@CommandPermissions("worldedit.reload")
public void reload(Actor actor) throws WorldEditException {
@ -94,9 +95,14 @@ public class WorldEditCommands {
actor.print("Configuration reloaded!");
}
@Command(aliases = {"report"}, desc = "Writes a report on WorldEdit", flags = "p", max = 0)
@Command(
name = "report",
desc = "Writes a report on WorldEdit"
)
@CommandPermissions({"worldedit.report"})
public void report(Actor actor, CommandContext args) throws WorldEditException {
public void report(Actor actor,
@Switch(name = 'p', desc = "Pastebins the report")
boolean pastebin) throws WorldEditException {
ReportList report = new ReportList("Report");
report.add(new SystemInfoReport());
report.add(new ConfigReport());
@ -110,7 +116,7 @@ public class WorldEditCommands {
actor.printError("Failed to write report: " + e.getMessage());
}
if (args.hasFlag('p')) {
if (pastebin) {
actor.checkPermission("worldedit.report.pastebin");
ActorCallbackPaste.pastebin(
we.getSupervisor(), actor, result, "WorldEdit report: %s.report",
@ -120,11 +126,8 @@ public class WorldEditCommands {
}
@Command(
aliases = { "cui" },
usage = "",
desc = "Complete CUI handshake (internal usage)",
min = 0,
max = 0
name = "cui",
desc = "Complete CUI handshake (internal usage)"
)
public void cui(Player player, LocalSession session) throws WorldEditException {
session.setCUISupport(true);
@ -132,14 +135,13 @@ public class WorldEditCommands {
}
@Command(
aliases = { "tz" },
usage = "[timezone]",
desc = "Set your timezone for snapshots",
min = 1,
max = 1
name = "tz",
desc = "Set your timezone for snapshots"
)
public void tz(Player player, LocalSession session, CommandContext args) throws WorldEditException {
ZoneId tz = ZoneId.of(args.getString(0));
public void tz(Player player, LocalSession session,
@Arg(desc = "The timezone to set")
String timezone) throws WorldEditException {
ZoneId tz = ZoneId.of(timezone);
session.setTimezone(tz);
player.print("Timezone set for this session to: " + tz.getDisplayName(
TextStyle.FULL, Locale.ENGLISH
@ -149,13 +151,15 @@ public class WorldEditCommands {
}
@Command(
aliases = { "help" },
usage = "[<command>]",
desc = "Displays help for WorldEdit commands",
min = 0,
max = -1
name = "help",
desc = "Displays help for WorldEdit commands"
)
@CommandPermissions("worldedit.help")
public void help(Actor actor, CommandContext args) throws WorldEditException {
public void help(Actor actor,
@Arg(desc = "The page to retrieve", def = "1")
int page,
@Arg(desc = "The command to retrieve help for", def = "", variable = true)
List<String> command) throws WorldEditException {
PrintCommandHelp.help(command, page, we, actor);
}
}

View File

@ -62,6 +62,8 @@ import com.sk89q.worldedit.command.ToolUtilCommands;
import com.sk89q.worldedit.command.ToolUtilCommandsRegistration;
import com.sk89q.worldedit.command.UtilityCommands;
import com.sk89q.worldedit.command.UtilityCommandsRegistration;
import com.sk89q.worldedit.command.WorldEditCommands;
import com.sk89q.worldedit.command.WorldEditCommandsRegistration;
import com.sk89q.worldedit.command.argument.Arguments;
import com.sk89q.worldedit.command.argument.BooleanConverter;
import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter;
@ -311,6 +313,24 @@ public final class PlatformCommandMananger {
.required()
.build());
});
commandManager.register("worldedit", cmd -> {
cmd.aliases(ImmutableList.of("we"));
cmd.description("WorldEdit commands");
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = DefaultCommandManagerService.getInstance()
.newCommandManager();
register(
manager,
WorldEditCommandsRegistration.builder(),
new WorldEditCommands(worldEdit)
);
cmd.addPart(SubCommandPart.builder("action", "Sub-command to run.")
.withCommands(manager.getAllCommands().collect(Collectors.toList()))
.required()
.build());
});
register(
commandManager,
BiomeCommandsRegistration.builder(),
@ -388,10 +408,6 @@ public final class PlatformCommandMananger {
.builder(builder)
.commands()
.register(adapt(new SelectionCommand(new ApplyCommand(new ReplaceParser(), "Set all blocks within selection"), "worldedit.region.set")), "/set")
.group("worldedit", "we")
.describeAs("WorldEdit commands")
.registerMethods(new WorldEditCommands(worldEdit))
.parent()
.group("brush", "br")
.describeAs("Brushing commands")
.register(adapt(new ShapedBrushCommand(new DeformCommand(), "worldedit.brush.deform")), "deform")
@ -402,11 +418,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("tool")
.describeAs("Bind functions to held items")
.registerMethods(new ToolCommands(worldEdit))
.parent()
.graph()
.getDispatcher();
*/
}