3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-04 18:40:06 +01:00

Port toll / tool util commands, add more enums

Dieser Commit ist enthalten in:
Kenzie Togami 2019-04-25 12:49:03 -07:00
Ursprung e447ac55db
Commit 8c2b725f42
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D200B325E157A81
8 geänderte Dateien mit 238 neuen und 171 gelöschten Zeilen

Datei anzeigen

@ -175,15 +175,6 @@ public class EditSession implements Extent, AutoCloseable {
public String getDisplayName() { public String getDisplayName() {
return this.displayName; return this.displayName;
} }
public static Optional<ReorderMode> getFromDisplayName(String name) {
for (ReorderMode mode : values()) {
if (mode.getDisplayName().equalsIgnoreCase(name)) {
return Optional.of(mode);
}
}
return Optional.empty();
}
} }
@SuppressWarnings("ProtectedField") @SuppressWarnings("ProtectedField")

Datei anzeigen

@ -122,23 +122,18 @@ public class GeneralCommands {
) )
@CommandPermissions("worldedit.fast") @CommandPermissions("worldedit.fast")
public void fast(Player player, LocalSession session, public void fast(Player player, LocalSession session,
@Arg(name = "on|off", desc = "The new fast mode state", def = "toggle") @Arg(desc = "The new fast mode state", def = "")
String newState) throws WorldEditException { Boolean fastMode) throws WorldEditException {
boolean hasFastMode = session.hasFastMode();
if (session.hasFastMode()) { if (fastMode != null && fastMode == hasFastMode) {
if ("on".equals(newState)) { player.printError("Fast mode already " + (fastMode ? "enabled" : "disabled") + ".");
player.printError("Fast mode already enabled."); return;
return; }
}
if (hasFastMode) {
session.setFastMode(false); session.setFastMode(false);
player.print("Fast mode disabled."); player.print("Fast mode disabled.");
} else { } else {
if ("off".equals(newState)) {
player.printError("Fast mode already disabled.");
return;
}
session.setFastMode(true); session.setFastMode(true);
player.print("Fast mode enabled. Lighting in the affected chunks may be wrong and/or you may need to rejoin to see changes."); player.print("Fast mode enabled. Lighting in the affected chunks may be wrong and/or you may need to rejoin to see changes.");
} }
@ -150,18 +145,11 @@ public class GeneralCommands {
) )
@CommandPermissions("worldedit.reorder") @CommandPermissions("worldedit.reorder")
public void reorderMode(Player player, LocalSession session, public void reorderMode(Player player, LocalSession session,
@Arg(name = "multi|fast|none", desc = "The reorder mode", def = "") @Arg(desc = "The reorder mode", def = "")
String newState) throws WorldEditException { EditSession.ReorderMode reorderMode) throws WorldEditException {
if (newState == null) { if (reorderMode == null) {
player.print("The reorder mode is " + session.getReorderMode().getDisplayName()); player.print("The reorder mode is " + session.getReorderMode().getDisplayName());
} else { } else {
java.util.Optional<EditSession.ReorderMode> reorderModeOptional = EditSession.ReorderMode.getFromDisplayName(newState);
if (!reorderModeOptional.isPresent()) {
player.printError("Unknown reorder mode!");
return;
}
EditSession.ReorderMode reorderMode = reorderModeOptional.get();
session.setReorderMode(reorderMode); session.setReorderMode(reorderMode);
player.print("The reorder mode is now " + session.getReorderMode().getDisplayName()); player.print("The reorder mode is now " + session.getReorderMode().getDisplayName());
} }
@ -173,26 +161,21 @@ public class GeneralCommands {
) )
@CommandPermissions("worldedit.drawsel") @CommandPermissions("worldedit.drawsel")
public void drawSelection(Player player, LocalSession session, public void drawSelection(Player player, LocalSession session,
@Arg(name = "on|off", desc = "The new fast mode state", def = "toggle") @Arg(desc = "The new draw selection state", def = "toggle")
String newState) throws WorldEditException { Boolean drawSelection) 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!");
} }
if (session.shouldUseServerCUI()) { boolean useServerCui = session.shouldUseServerCUI();
if ("on".equals(newState)) { if (drawSelection != null && drawSelection == useServerCui) {
player.printError("Server CUI already enabled."); player.printError("Server CUI already " + (useServerCui ? "enabled" : "disabled") + ".");
return; return;
} }
if (useServerCui) {
session.setUseServerCUI(false); session.setUseServerCUI(false);
session.updateServerCUI(player); session.updateServerCUI(player);
player.print("Server CUI disabled."); player.print("Server CUI disabled.");
} else { } else {
if ("off".equals(newState)) {
player.printError("Server CUI already disabled.");
return;
}
session.setUseServerCUI(true); session.setUseServerCUI(true);
session.updateServerCUI(player); session.updateServerCUI(player);
player.print("Server CUI enabled. This only supports cuboid regions, with a maximum size of 32x32x32."); player.print("Server CUI enabled. This only supports cuboid regions, with a maximum size of 32x32x32.");

Datei anzeigen

@ -19,9 +19,6 @@
package com.sk89q.worldedit.command; 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.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
@ -35,12 +32,18 @@ import com.sk89q.worldedit.command.tool.FloodFillTool;
import com.sk89q.worldedit.command.tool.LongRangeBuildTool; import com.sk89q.worldedit.command.tool.LongRangeBuildTool;
import com.sk89q.worldedit.command.tool.QueryTool; import com.sk89q.worldedit.command.tool.QueryTool;
import com.sk89q.worldedit.command.tool.TreePlanter; import com.sk89q.worldedit.command.tool.TreePlanter;
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.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
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 ToolCommands { public class ToolCommands {
private final WorldEdit we; private final WorldEdit we;
@ -49,11 +52,8 @@ public class ToolCommands {
} }
@Command( @Command(
aliases = { "none" }, name = "none",
usage = "", desc = "Unbind a bound tool from your current item"
desc = "Unbind a bound tool from your current item",
min = 0,
max = 0
) )
public void none(Player player, LocalSession session) throws WorldEditException { public void none(Player player, LocalSession session) throws WorldEditException {
@ -62,11 +62,8 @@ public class ToolCommands {
} }
@Command( @Command(
aliases = { "info" }, name = "info",
usage = "", desc = "Block information tool"
desc = "Block information tool",
min = 0,
max = 0
) )
@CommandPermissions("worldedit.tool.info") @CommandPermissions("worldedit.tool.info")
public void info(Player player, LocalSession session) throws WorldEditException { public void info(Player player, LocalSession session) throws WorldEditException {
@ -78,49 +75,34 @@ public class ToolCommands {
} }
@Command( @Command(
aliases = { "tree" }, name = "tree",
usage = "[type]", desc = "Tree generator tool"
desc = "Tree generator tool",
min = 0,
max = 1
) )
@CommandPermissions("worldedit.tool.tree") @CommandPermissions("worldedit.tool.tree")
public void tree(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void tree(Player player, LocalSession session,
@Arg(desc = "Type of tree to generate", def = "tree")
TreeGenerator.TreeType type = args.argsLength() > 0 TreeGenerator.TreeType type) throws WorldEditException {
? TreeGenerator.lookup(args.getString(0))
: TreeGenerator.TreeType.TREE;
if (type == null) {
player.printError("Tree type '" + args.getString(0) + "' is unknown.");
return;
}
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new TreePlanter(type)); session.setTool(itemStack.getType(), new TreePlanter(type));
player.print("Tree tool bound to " + itemStack.getType().getName() + "."); player.print("Tree tool bound to " + itemStack.getType().getName() + ".");
} }
@Command( @Command(
aliases = { "repl" }, name = "repl",
usage = "<block>", desc = "Block replacer tool"
desc = "Block replacer tool",
min = 1,
max = 1
) )
@CommandPermissions("worldedit.tool.replacer") @CommandPermissions("worldedit.tool.replacer")
public void repl(Player player, LocalSession session, Pattern pattern) throws WorldEditException { public void repl(Player player, LocalSession session,
@Arg(desc = "The pattern of blocks to place")
Pattern pattern) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new BlockReplacer(pattern)); session.setTool(itemStack.getType(), new BlockReplacer(pattern));
player.print("Block replacer tool bound to " + itemStack.getType().getName() + "."); player.print("Block replacer tool bound to " + itemStack.getType().getName() + ".");
} }
@Command( @Command(
aliases = { "cycler" }, name = "cycler",
usage = "", desc = "Block data cycler tool"
desc = "Block data cycler tool",
min = 0,
max = 0
) )
@CommandPermissions("worldedit.tool.data-cycler") @CommandPermissions("worldedit.tool.data-cycler")
public void cycler(Player player, LocalSession session) throws WorldEditException { public void cycler(Player player, LocalSession session) throws WorldEditException {
@ -131,14 +113,16 @@ public class ToolCommands {
} }
@Command( @Command(
aliases = { "floodfill", "flood" }, name = "floodfill",
usage = "<pattern> <range>", aliases = { "flood" },
desc = "Flood fill tool", desc = "Flood fill tool"
min = 2,
max = 2
) )
@CommandPermissions("worldedit.tool.flood-fill") @CommandPermissions("worldedit.tool.flood-fill")
public void floodFill(Player player, LocalSession session, Pattern pattern, int range) throws WorldEditException { public void floodFill(Player player, LocalSession session,
@Arg(desc = "The pattern to flood fill")
Pattern pattern,
@Arg(desc = "The range to perform the fill")
int range) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
@ -153,11 +137,8 @@ public class ToolCommands {
} }
@Command( @Command(
aliases = { "deltree" }, name = "deltree",
usage = "", desc = "Floating tree remover tool"
desc = "Floating tree remover tool",
min = 0,
max = 0
) )
@CommandPermissions("worldedit.tool.deltree") @CommandPermissions("worldedit.tool.deltree")
public void deltree(Player player, LocalSession session) throws WorldEditException { public void deltree(Player player, LocalSession session) throws WorldEditException {
@ -169,11 +150,8 @@ public class ToolCommands {
} }
@Command( @Command(
aliases = { "farwand" }, name = "farwand",
usage = "", desc = "Wand at a distance tool"
desc = "Wand at a distance tool",
min = 0,
max = 0
) )
@CommandPermissions("worldedit.tool.farwand") @CommandPermissions("worldedit.tool.farwand")
public void farwand(Player player, LocalSession session) throws WorldEditException { public void farwand(Player player, LocalSession session) throws WorldEditException {
@ -184,14 +162,16 @@ public class ToolCommands {
} }
@Command( @Command(
aliases = { "lrbuild", "/lrbuild" }, name = "lrbuild",
usage = "<leftclick block> <rightclick block>", aliases = { "/lrbuild" },
desc = "Long-range building tool", desc = "Long-range building tool"
min = 2,
max = 2
) )
@CommandPermissions("worldedit.tool.lrbuild") @CommandPermissions("worldedit.tool.lrbuild")
public void longrangebuildtool(Player player, LocalSession session, Pattern secondary, Pattern primary) throws WorldEditException { public void longrangebuildtool(Player player, LocalSession session,
@Arg(desc = "Block to set on left-click")
Pattern primary,
@Arg(desc = "Block to set on right-click")
Pattern secondary) throws WorldEditException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new LongRangeBuildTool(primary, secondary)); session.setTool(itemStack.getType(), new LongRangeBuildTool(primary, secondary));

Datei anzeigen

@ -19,21 +19,23 @@
package com.sk89q.worldedit.command; 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.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.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.command.parametric.Optional; import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
/** /**
* Tool commands. * Tool commands.
*/ */
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class ToolUtilCommands { public class ToolUtilCommands {
private final WorldEdit we; private final WorldEdit we;
@ -42,44 +44,37 @@ public class ToolUtilCommands {
} }
@Command( @Command(
aliases = { "/", "," }, name = "/",
usage = "[on|off]", aliases = { "," },
desc = "Toggle the super pickaxe function", desc = "Toggle the super pickaxe function"
min = 0,
max = 1
) )
@CommandPermissions("worldedit.superpickaxe") @CommandPermissions("worldedit.superpickaxe")
public void togglePickaxe(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void togglePickaxe(Player player, LocalSession session,
@Arg(desc = "The new super pickaxe state", def = "")
String newState = args.getString(0, null); Boolean superPickaxe) throws WorldEditException {
if (session.hasSuperPickAxe()) { boolean hasSuperPickAxe = session.hasSuperPickAxe();
if ("on".equals(newState)) { if (superPickaxe != null && superPickaxe == hasSuperPickAxe) {
player.printError("Super pick axe already enabled."); player.printError("Super pickaxe already " + (superPickaxe ? "enabled" : "disabled") + ".");
return; return;
} }
if (hasSuperPickAxe) {
session.disableSuperPickAxe(); session.disableSuperPickAxe();
player.print("Super pick axe disabled."); player.print("Super pickaxe disabled.");
} else { } else {
if ("off".equals(newState)) {
player.printError("Super pick axe already disabled.");
return;
}
session.enableSuperPickAxe(); session.enableSuperPickAxe();
player.print("Super pick axe enabled."); player.print("Super pickaxe enabled.");
} }
} }
@Command( @Command(
aliases = { "mask" }, name = "mask",
usage = "[mask]", desc = "Set the brush mask"
desc = "Set the brush mask",
min = 0,
max = -1
) )
@CommandPermissions("worldedit.brush.options.mask") @CommandPermissions("worldedit.brush.options.mask")
public void mask(Player player, LocalSession session, @Optional Mask mask) throws WorldEditException { public void mask(Player player, LocalSession session,
@Arg(desc = "The mask to set", def = "")
Mask mask) throws WorldEditException {
if (mask == null) { if (mask == null) {
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setMask(null); session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setMask(null);
player.print("Brush mask disabled."); player.print("Brush mask disabled.");
@ -90,46 +85,41 @@ public class ToolUtilCommands {
} }
@Command( @Command(
aliases = { "mat", "material" }, name = "material",
usage = "[pattern]", aliases = { "material" },
desc = "Set the brush material", desc = "Set the brush material"
min = 1,
max = 1
) )
@CommandPermissions("worldedit.brush.options.material") @CommandPermissions("worldedit.brush.options.material")
public void material(Player player, LocalSession session, Pattern pattern) throws WorldEditException { public void material(Player player, LocalSession session,
@Arg(desc = "The pattern of blocks to use")
Pattern pattern) throws WorldEditException {
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setFill(pattern); session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setFill(pattern);
player.print("Brush material set."); player.print("Brush material set.");
} }
@Command( @Command(
aliases = { "range" }, name = "range",
usage = "[pattern]", desc = "Set the brush range"
desc = "Set the brush range", )
min = 1,
max = 1
)
@CommandPermissions("worldedit.brush.options.range") @CommandPermissions("worldedit.brush.options.range")
public void range(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void range(Player player, LocalSession session,
int range = args.getInteger(0); @Arg(desc = "The range of the brush")
int range) throws WorldEditException {
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setRange(range); session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setRange(range);
player.print("Brush range set."); player.print("Brush range set.");
} }
@Command( @Command(
aliases = { "size" }, name = "size",
usage = "[pattern]", desc = "Set the brush size"
desc = "Set the brush size",
min = 1,
max = 1
) )
@CommandPermissions("worldedit.brush.options.size") @CommandPermissions("worldedit.brush.options.size")
public void size(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void size(Player player, LocalSession session,
@Arg(desc = "The size of the brush")
int size) throws WorldEditException {
we.checkMaxBrushRadius(size);
int radius = args.getInteger(0); session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setSize(size);
we.checkMaxBrushRadius(radius);
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setSize(radius);
player.print("Brush size set."); player.print("Brush size set.");
} }
} }

Datei anzeigen

@ -0,0 +1,65 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.command.argument;
import com.google.common.collect.ImmutableSortedSet;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ConversionResult;
import org.enginehub.piston.converter.FailedConversion;
import org.enginehub.piston.converter.SuccessfulConversion;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.inject.Key;
public class BooleanConverter implements ArgumentConverter<Boolean> {
public static void register(CommandManager commandManager) {
commandManager.registerConverter(Key.of(Boolean.class), new BooleanConverter());
}
private static final ImmutableSortedSet<String> TRUE = ImmutableSortedSet
.orderedBy(String.CASE_INSENSITIVE_ORDER)
.add("on", "t", "true", "y", "yes")
.build();
private static final ImmutableSortedSet<String> FALSE = ImmutableSortedSet
.orderedBy(String.CASE_INSENSITIVE_ORDER)
.add("off", "f", "false", "n", "no")
.build();
private BooleanConverter() {
}
@Override
public String describeAcceptableArguments() {
return "on|off|true|false";
}
@Override
public ConversionResult<Boolean> convert(String argument, InjectedValueAccess context) {
if (TRUE.contains(argument)) {
return SuccessfulConversion.fromSingle(true);
}
if (FALSE.contains(argument)) {
return SuccessfulConversion.fromSingle(false);
}
return FailedConversion.from(new IllegalArgumentException("Not a strictly boolean value: " + argument));
}
}

Datei anzeigen

@ -20,7 +20,10 @@
package com.sk89q.worldedit.command.argument; package com.sk89q.worldedit.command.argument;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.util.TreeGenerator;
import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ConversionResult; import org.enginehub.piston.converter.ConversionResult;
@ -31,34 +34,74 @@ import org.enginehub.piston.inject.Key;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkState;
import static java.util.stream.Collectors.joining;
public class EnumConverter<E extends Enum<E>> implements ArgumentConverter<E> { public class EnumConverter<E extends Enum<E>> implements ArgumentConverter<E> {
public static void register(CommandManager commandManager) { public static void register(CommandManager commandManager) {
commandManager.registerConverter(Key.of(SelectorChoice.class), commandManager.registerConverter(Key.of(SelectorChoice.class),
new EnumConverter<>(SelectorChoice.class, SelectorChoice.UNKNOWN)); basic(SelectorChoice.class, SelectorChoice.UNKNOWN));
commandManager.registerConverter(Key.of(TreeGenerator.TreeType.class),
full(TreeGenerator.TreeType.class,
t -> ImmutableSet.copyOf(t.lookupKeys),
null));
commandManager.registerConverter(Key.of(EditSession.ReorderMode.class),
full(EditSession.ReorderMode.class,
r -> ImmutableSet.of(r.getDisplayName()),
null));
} }
private static <E extends Enum<E>> EnumConverter<E> basic(Class<E> enumClass) {
return full(enumClass, e -> ImmutableSet.of(e.name()), null);
}
private static <E extends Enum<E>> EnumConverter<E> basic(Class<E> enumClass, E unknownValue) {
return full(enumClass, e -> ImmutableSet.of(e.name()), unknownValue);
}
private static <E extends Enum<E>> EnumConverter<E> full(Class<E> enumClass,
Function<E, Set<String>> lookupKeys,
@Nullable E unknownValue) {
return new EnumConverter<>(enumClass, lookupKeys, unknownValue);
}
private final String choices;
private final ImmutableMap<String, E> map; private final ImmutableMap<String, E> map;
@Nullable @Nullable
private final E unknownValue; private final E unknownValue;
private EnumConverter(Class<E> enumClass, @Nullable E unknownValue) { private EnumConverter(Class<E> enumClass,
Function<E, Set<String>> lookupKeys,
@Nullable E unknownValue) {
ImmutableSortedMap.Builder<String, E> map = ImmutableSortedMap.orderedBy(String.CASE_INSENSITIVE_ORDER); ImmutableSortedMap.Builder<String, E> map = ImmutableSortedMap.orderedBy(String.CASE_INSENSITIVE_ORDER);
Stream.Builder<Set<String>> choices = Stream.builder();
EnumSet<E> validValues = EnumSet.allOf(enumClass); EnumSet<E> validValues = EnumSet.allOf(enumClass);
if (unknownValue != null) { if (unknownValue != null) {
validValues.remove(unknownValue); validValues.remove(unknownValue);
} }
for (E e : validValues) { for (E e : validValues) {
map.put(e.name(), e); Set<String> keys = lookupKeys.apply(e);
checkState(keys.size() > 0, "No lookup keys for enum value %s", e);
choices.add(keys);
for (String key : keys) {
map.put(key, e);
}
} }
this.choices = choices.build()
.map(choice -> choice.stream().collect(joining("|", "[", "]")))
.collect(joining("|"));
this.map = map.build(); this.map = map.build();
this.unknownValue = unknownValue; this.unknownValue = unknownValue;
} }
@Override @Override
public String describeAcceptableArguments() { public String describeAcceptableArguments() {
return String.join("|", map.keySet()); return choices;
} }
@Override @Override

Datei anzeigen

@ -56,7 +56,12 @@ import com.sk89q.worldedit.command.SnapshotUtilCommands;
import com.sk89q.worldedit.command.SnapshotUtilCommandsRegistration; import com.sk89q.worldedit.command.SnapshotUtilCommandsRegistration;
import com.sk89q.worldedit.command.SuperPickaxeCommands; import com.sk89q.worldedit.command.SuperPickaxeCommands;
import com.sk89q.worldedit.command.SuperPickaxeCommandsRegistration; import com.sk89q.worldedit.command.SuperPickaxeCommandsRegistration;
import com.sk89q.worldedit.command.ToolCommands;
import com.sk89q.worldedit.command.ToolCommandsRegistration;
import com.sk89q.worldedit.command.ToolUtilCommands;
import com.sk89q.worldedit.command.ToolUtilCommandsRegistration;
import com.sk89q.worldedit.command.argument.Arguments; import com.sk89q.worldedit.command.argument.Arguments;
import com.sk89q.worldedit.command.argument.BooleanConverter;
import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter; import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter;
import com.sk89q.worldedit.command.argument.DirectionConverter; import com.sk89q.worldedit.command.argument.DirectionConverter;
import com.sk89q.worldedit.command.argument.EnumConverter; import com.sk89q.worldedit.command.argument.EnumConverter;
@ -209,6 +214,7 @@ public final class PlatformCommandMananger {
EnumConverter.register(commandManager); EnumConverter.register(commandManager);
ExpandAmountConverter.register(commandManager); ExpandAmountConverter.register(commandManager);
ZonedDateTimeConverter.register(commandManager); ZonedDateTimeConverter.register(commandManager);
BooleanConverter.register(commandManager);
} }
private void registerAlwaysInjectedValues() { private void registerAlwaysInjectedValues() {
@ -367,14 +373,22 @@ public final class PlatformCommandMananger {
SnapshotUtilCommandsRegistration.builder(), SnapshotUtilCommandsRegistration.builder(),
new SnapshotUtilCommands(worldEdit) new SnapshotUtilCommands(worldEdit)
); );
register(
commandManager,
ToolCommandsRegistration.builder(),
new ToolCommands(worldEdit)
);
register(
commandManager,
ToolUtilCommandsRegistration.builder(),
new ToolUtilCommands(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 ToolUtilCommands(worldEdit))
.registerMethods(new ToolCommands(worldEdit))
.registerMethods(new UtilityCommands(worldEdit)) .registerMethods(new UtilityCommands(worldEdit))
.register(adapt(new SelectionCommand(new ApplyCommand(new ReplaceParser(), "Set all blocks within selection"), "worldedit.region.set")), "/set") .register(adapt(new SelectionCommand(new ApplyCommand(new ReplaceParser(), "Set all blocks within selection"), "worldedit.region.set")), "/set")
.group("worldedit", "we") .group("worldedit", "we")

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.util; package com.sk89q.worldedit.util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
@ -113,22 +114,22 @@ public class TreeGenerator {
private static final Set<String> primaryAliases = Sets.newHashSet(); private static final Set<String> primaryAliases = Sets.newHashSet();
private final String name; private final String name;
private final String[] lookupKeys; public final ImmutableList<String> lookupKeys;
static { static {
for (TreeType type : EnumSet.allOf(TreeType.class)) { for (TreeType type : EnumSet.allOf(TreeType.class)) {
for (String key : type.lookupKeys) { for (String key : type.lookupKeys) {
lookup.put(key, type); lookup.put(key, type);
} }
if (type.lookupKeys.length > 0) { if (type.lookupKeys.size() > 0) {
primaryAliases.add(type.lookupKeys[0]); primaryAliases.add(type.lookupKeys.get(0));
} }
} }
} }
TreeType(String name, String... lookupKeys) { TreeType(String name, String... lookupKeys) {
this.name = name; this.name = name;
this.lookupKeys = lookupKeys; this.lookupKeys = ImmutableList.copyOf(lookupKeys);
} }
public static Set<String> getAliases() { public static Set<String> getAliases() {