3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 18:40:05 +01:00

Port GeneralCommands

Dieser Commit ist enthalten in:
Kenzie Togami 2019-04-21 13:10:20 -07:00
Ursprung f481f7d26d
Commit 51be16ad81
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D200B325E157A81
2 geänderte Dateien mit 63 neuen und 72 gelöschten Zeilen

Datei anzeigen

@ -19,28 +19,31 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
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.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.DisallowedUsageException; import com.sk89q.worldedit.extension.input.DisallowedUsageException;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.util.command.parametric.Optional;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.item.ItemTypes;
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 static com.google.common.base.Preconditions.checkNotNull;
/** /**
* General WorldEdit commands. * General WorldEdit commands.
*/ */
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class GeneralCommands { public class GeneralCommands {
private final WorldEdit worldEdit; private final WorldEdit worldEdit;
@ -56,19 +59,18 @@ public class GeneralCommands {
} }
@Command( @Command(
aliases = { "/limit" }, name = "/limit",
usage = "[limit]", desc = "Modify block change limit"
desc = "Modify block change limit",
min = 0,
max = 1
) )
@CommandPermissions("worldedit.limit") @CommandPermissions("worldedit.limit")
public void limit(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void limit(Player player, LocalSession session,
@Arg(desc = "The limit to set", def = "")
Integer limit) throws WorldEditException {
LocalConfiguration config = worldEdit.getConfiguration(); LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted"); boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted");
int limit = args.argsLength() == 0 ? config.defaultChangeLimit : Math.max(-1, args.getInteger(0)); limit = limit == null ? config.defaultChangeLimit : Math.max(-1, limit);
if (!mayDisable && config.maxChangeLimit > -1) { if (!mayDisable && config.maxChangeLimit > -1) {
if (limit > config.maxChangeLimit) { if (limit > config.maxChangeLimit) {
player.printError("Your maximum allowable limit is " + config.maxChangeLimit + "."); player.printError("Your maximum allowable limit is " + config.maxChangeLimit + ".");
@ -86,19 +88,18 @@ public class GeneralCommands {
} }
@Command( @Command(
aliases = { "/timeout" }, name = "/timeout",
usage = "[time]", desc = "Modify evaluation timeout time."
desc = "Modify evaluation timeout time.",
min = 0,
max = 1
) )
@CommandPermissions("worldedit.timeout") @CommandPermissions("worldedit.timeout")
public void timeout(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void timeout(Player player, LocalSession session,
@Arg(desc = "The timeout time to set", def = "")
Integer limit) throws WorldEditException {
LocalConfiguration config = worldEdit.getConfiguration(); LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.timeout.unrestricted"); boolean mayDisable = player.hasPermission("worldedit.timeout.unrestricted");
int limit = args.argsLength() == 0 ? config.calculationTimeout : Math.max(-1, args.getInteger(0)); limit = limit == null ? config.calculationTimeout : Math.max(-1, limit);
if (!mayDisable && config.maxCalculationTimeout > -1) { if (!mayDisable && config.maxCalculationTimeout > -1) {
if (limit > config.maxCalculationTimeout) { if (limit > config.maxCalculationTimeout) {
player.printError("Your maximum allowable timeout is " + config.maxCalculationTimeout + " ms."); player.printError("Your maximum allowable timeout is " + config.maxCalculationTimeout + " ms.");
@ -116,16 +117,14 @@ public class GeneralCommands {
} }
@Command( @Command(
aliases = { "/fast" }, name = "/fast",
usage = "[on|off]", desc = "Toggle fast mode"
desc = "Toggle fast mode",
min = 0,
max = 1
) )
@CommandPermissions("worldedit.fast") @CommandPermissions("worldedit.fast")
public void fast(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void fast(Player player, LocalSession session,
@Arg(name = "on|off", desc = "The new fast mode state", def = "toggle")
String newState) throws WorldEditException {
String newState = args.getString(0, null);
if (session.hasFastMode()) { if (session.hasFastMode()) {
if ("on".equals(newState)) { if ("on".equals(newState)) {
player.printError("Fast mode already enabled."); player.printError("Fast mode already enabled.");
@ -146,15 +145,13 @@ public class GeneralCommands {
} }
@Command( @Command(
aliases = { "/reorder" }, name = "/reorder",
usage = "[multi|fast|none]", desc = "Sets the reorder mode of WorldEdit"
desc = "Sets the reorder mode of WorldEdit",
min = 0,
max = 1
) )
@CommandPermissions("worldedit.reorder") @CommandPermissions("worldedit.reorder")
public void reorderMode(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void reorderMode(Player player, LocalSession session,
String newState = args.getString(0, null); @Arg(name = "multi|fast|none", desc = "The reorder mode", def = "")
String newState) throws WorldEditException {
if (newState == null) { if (newState == null) {
player.print("The reorder mode is " + session.getReorderMode().getDisplayName()); player.print("The reorder mode is " + session.getReorderMode().getDisplayName());
} else { } else {
@ -171,19 +168,16 @@ public class GeneralCommands {
} }
@Command( @Command(
aliases = { "/drawsel" }, name = "/drawsel",
usage = "[on|off]", desc = "Toggle drawing the current selection"
desc = "Toggle drawing the current selection",
min = 0,
max = 1
) )
@CommandPermissions("worldedit.drawsel") @CommandPermissions("worldedit.drawsel")
public void drawSelection(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void drawSelection(Player player, LocalSession session,
@Arg(name = "on|off", desc = "The new fast mode state", def = "toggle")
String newState) throws WorldEditException {
if (!WorldEdit.getInstance().getConfiguration().serverSideCUI) { if (!WorldEdit.getInstance().getConfiguration().serverSideCUI) {
throw new DisallowedUsageException("This functionality is disabled in the configuration!"); throw new DisallowedUsageException("This functionality is disabled in the configuration!");
} }
String newState = args.getString(0, null);
if (session.shouldUseServerCUI()) { if (session.shouldUseServerCUI()) {
if ("on".equals(newState)) { if ("on".equals(newState)) {
player.printError("Server CUI already enabled."); player.printError("Server CUI already enabled.");
@ -206,14 +200,14 @@ public class GeneralCommands {
} }
@Command( @Command(
aliases = { "/gmask", "gmask" }, name = "gmask",
usage = "[mask]", aliases = {"/gmask"},
desc = "Set the global mask", desc = "Set the global mask"
min = 0,
max = -1
) )
@CommandPermissions("worldedit.global-mask") @CommandPermissions("worldedit.global-mask")
public void gmask(Player player, LocalSession session, @Optional Mask mask) throws WorldEditException { public void gmask(Player player, LocalSession session,
@Arg(desc = "The mask to set", def = "")
Mask mask) throws WorldEditException {
if (mask == null) { if (mask == null) {
session.setMask((Mask) null); session.setMask((Mask) null);
player.print("Global mask disabled."); player.print("Global mask disabled.");
@ -224,11 +218,9 @@ public class GeneralCommands {
} }
@Command( @Command(
aliases = { "/toggleplace", "toggleplace" }, name = "toggleplace",
usage = "", aliases = {"/toggleplace"},
desc = "Switch between your position and pos1 for placement", desc = "Switch between your position and pos1 for placement"
min = 0,
max = 0
) )
public void togglePlace(Player player, LocalSession session) throws WorldEditException { public void togglePlace(Player player, LocalSession session) throws WorldEditException {
@ -240,24 +232,17 @@ public class GeneralCommands {
} }
@Command( @Command(
aliases = { "/searchitem", "/l", "/search", "searchitem" }, name = "searchitem",
usage = "<query>", aliases = {"/searchitem", "/l", "/search"},
flags = "bi", desc = "Search for an item"
desc = "Search for an item",
help =
"Searches for an item.\n" +
"Flags:\n" +
" -b only search for blocks\n" +
" -i only search for items",
min = 1,
max = 1
) )
public void searchItem(Actor actor, CommandContext args) throws WorldEditException { public void searchItem(Actor actor,
@Arg(desc = "Item query")
String query = args.getString(0).trim().toLowerCase(); String query,
boolean blocksOnly = args.hasFlag('b'); @Switch(name = 'b', desc = "Only search for blocks")
boolean itemsOnly = args.hasFlag('i'); boolean blocksOnly,
@Switch(name = 'i', desc = "Only search for items")
boolean itemsOnly) throws WorldEditException {
ItemType type = ItemTypes.get(query); ItemType type = ItemTypes.get(query);
if (type != null) { if (type != null) {

Datei anzeigen

@ -33,6 +33,8 @@ import com.sk89q.worldedit.command.ChunkCommands;
import com.sk89q.worldedit.command.ChunkCommandsRegistration; import com.sk89q.worldedit.command.ChunkCommandsRegistration;
import com.sk89q.worldedit.command.ClipboardCommands; import com.sk89q.worldedit.command.ClipboardCommands;
import com.sk89q.worldedit.command.ClipboardCommandsRegistration; import com.sk89q.worldedit.command.ClipboardCommandsRegistration;
import com.sk89q.worldedit.command.GeneralCommands;
import com.sk89q.worldedit.command.GeneralCommandsRegistration;
import com.sk89q.worldedit.command.SchematicCommands; import com.sk89q.worldedit.command.SchematicCommands;
import com.sk89q.worldedit.command.SchematicCommandsRegistration; import com.sk89q.worldedit.command.SchematicCommandsRegistration;
import com.sk89q.worldedit.command.argument.Arguments; import com.sk89q.worldedit.command.argument.Arguments;
@ -251,13 +253,17 @@ public final class PlatformCommandMananger {
ClipboardCommandsRegistration.builder(), ClipboardCommandsRegistration.builder(),
new ClipboardCommands() new ClipboardCommands()
); );
register(
commandManager,
GeneralCommandsRegistration.builder(),
new GeneralCommands(worldEdit)
);
// Unported commands are below. Delete once they're added to the main manager above. // Unported commands are below. Delete once they're added to the main manager above.
/* /*
dispatcher = new CommandGraph() dispatcher = new CommandGraph()
.builder(builder) .builder(builder)
.commands() .commands()
.registerMethods(new GeneralCommands(worldEdit))
.registerMethods(new GenerationCommands(worldEdit)) .registerMethods(new GenerationCommands(worldEdit))
.registerMethods(new HistoryCommands(worldEdit)) .registerMethods(new HistoryCommands(worldEdit))
.registerMethods(new NavigationCommands(worldEdit)) .registerMethods(new NavigationCommands(worldEdit))