Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-19 09:20:08 +01:00
Perform part of the move of //fast to //perf (#1377)
This re-adds a deprecated `//fast` and moves the current logic to `//perf`. Later `//perf` will have its syntax reworked, when Piston finally supports sub-commands properly!
Dieser Commit ist enthalten in:
Ursprung
097f3ec473
Commit
008238c686
@ -28,6 +28,7 @@ import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.RandomTextureUtil;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.boydti.fawe.util.TextureUtil;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -36,6 +37,7 @@ 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.HookMode;
|
||||
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.DisallowedUsageException;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
@ -44,6 +46,8 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
|
||||
import com.sk89q.worldedit.internal.command.CommandUtil;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.util.formatting.component.PaginationBox;
|
||||
@ -54,6 +58,9 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import org.enginehub.piston.CommandManager;
|
||||
import org.enginehub.piston.CommandManagerService;
|
||||
import org.enginehub.piston.CommandParameters;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import org.enginehub.piston.annotation.CommandContainer;
|
||||
import org.enginehub.piston.annotation.param.Arg;
|
||||
@ -65,8 +72,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -76,6 +85,62 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
||||
public class GeneralCommands {
|
||||
|
||||
public static void register(CommandRegistrationHandler registration,
|
||||
CommandManager commandManager,
|
||||
CommandManagerService commandManagerService,
|
||||
WorldEdit worldEdit) {
|
||||
// Collect the tool commands
|
||||
CommandManager collect = commandManagerService.newCommandManager();
|
||||
|
||||
registration.register(
|
||||
collect,
|
||||
GeneralCommandsRegistration.builder(),
|
||||
new GeneralCommands(worldEdit)
|
||||
);
|
||||
|
||||
|
||||
Set<org.enginehub.piston.Command> commands = collect.getAllCommands()
|
||||
.collect(Collectors.toSet());
|
||||
for (org.enginehub.piston.Command command : commands) {
|
||||
if (command.getName().equals("/fast")) {
|
||||
// deprecate to `//perf`
|
||||
commandManager.register(CommandUtil.deprecate(
|
||||
command, "//fast duplicates //perf " +
|
||||
"and will be removed in WorldEdit 8",
|
||||
GeneralCommands::replaceFastForPerf
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
commandManager.register(command);
|
||||
}
|
||||
}
|
||||
|
||||
private static Component replaceFastForPerf(org.enginehub.piston.Command oldCmd,
|
||||
CommandParameters oldParams) {
|
||||
if (oldParams.getMetadata() == null) {
|
||||
return CommandUtil.createNewCommandReplacementText("//perf");
|
||||
}
|
||||
ImmutableList<String> args = oldParams.getMetadata().getArguments();
|
||||
if (args.isEmpty()) {
|
||||
return TextComponent.of("There is not yet a replacement for //fast" +
|
||||
" with no arguments");
|
||||
}
|
||||
String arg0 = args.get(0).toLowerCase(Locale.ENGLISH);
|
||||
String flipped;
|
||||
switch (arg0) {
|
||||
case "on":
|
||||
flipped = "off";
|
||||
break;
|
||||
case "off":
|
||||
flipped = "on";
|
||||
break;
|
||||
default:
|
||||
return TextComponent.of("There is no replacement for //fast " + arg0);
|
||||
}
|
||||
return CommandUtil.createNewCommandReplacementText("//perf " + flipped);
|
||||
}
|
||||
|
||||
private final WorldEdit worldEdit;
|
||||
|
||||
/**
|
||||
@ -145,22 +210,48 @@ public class GeneralCommands {
|
||||
|
||||
@Command(
|
||||
name = "/fast",
|
||||
desc = "Toggle fast mode side effects"
|
||||
desc = "Toggle fast mode"
|
||||
)
|
||||
@CommandPermissions("worldedit.fast")
|
||||
public void fast(Actor actor, LocalSession session,
|
||||
@Arg(desc = "The side effect", def = "")
|
||||
SideEffect sideEffect,
|
||||
@Arg(desc = "The new side effect state", def = "")
|
||||
SideEffect.State newState,
|
||||
@Switch(name = 'h', desc = "Show the info box")
|
||||
boolean showInfoBox) throws WorldEditException {
|
||||
@Deprecated
|
||||
void fast(Actor actor, LocalSession session,
|
||||
@Arg(desc = "The new fast mode state", def = "")
|
||||
Boolean fastMode) {
|
||||
boolean hasFastMode = session.hasFastMode();
|
||||
if (fastMode != null && fastMode == hasFastMode) {
|
||||
actor.printError(TranslatableComponent.of(fastMode ? "worldedit.fast.enabled.already" : "worldedit.fast.disabled.already"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasFastMode) {
|
||||
session.setFastMode(false);
|
||||
actor.printInfo(TranslatableComponent.of("worldedit.fast.disabled"));
|
||||
} else {
|
||||
session.setFastMode(true);
|
||||
actor.printInfo(TranslatableComponent.of("worldedit.fast.enabled"));
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "/perf",
|
||||
desc = "Toggle side effects for performance",
|
||||
descFooter = "Note that this command is GOING to change in the future." +
|
||||
" Do not depend on the exact format of this command yet."
|
||||
)
|
||||
@CommandPermissions("worldedit.perf")
|
||||
void perf(Actor actor, LocalSession session,
|
||||
@Arg(desc = "The side effect", def = "")
|
||||
SideEffect sideEffect,
|
||||
@Arg(desc = "The new side effect state", def = "")
|
||||
SideEffect.State newState,
|
||||
@Switch(name = 'h', desc = "Show the info box")
|
||||
boolean showInfoBox) throws WorldEditException {
|
||||
if (sideEffect != null) {
|
||||
SideEffect.State currentState = session.getSideEffectSet().getState(sideEffect);
|
||||
if (newState != null && newState == currentState) {
|
||||
if (!showInfoBox) {
|
||||
actor.printError(TranslatableComponent.of(
|
||||
"worldedit.fast.sideeffect.already-set",
|
||||
"worldedit.perf.sideeffect.already-set",
|
||||
TranslatableComponent.of(sideEffect.getDisplayName()),
|
||||
TranslatableComponent.of(newState.getDisplayName())
|
||||
));
|
||||
@ -172,14 +263,14 @@ public class GeneralCommands {
|
||||
session.setSideEffectSet(session.getSideEffectSet().with(sideEffect, newState));
|
||||
if (!showInfoBox) {
|
||||
actor.printInfo(TranslatableComponent.of(
|
||||
"worldedit.fast.sideeffect.set",
|
||||
"worldedit.perf.sideeffect.set",
|
||||
TranslatableComponent.of(sideEffect.getDisplayName()),
|
||||
TranslatableComponent.of(newState.getDisplayName())
|
||||
));
|
||||
}
|
||||
} else {
|
||||
actor.printInfo(TranslatableComponent.of(
|
||||
"worldedit.fast.sideeffect.get",
|
||||
"worldedit.perf.sideeffect.get",
|
||||
TranslatableComponent.of(sideEffect.getDisplayName()),
|
||||
TranslatableComponent.of(currentState.getDisplayName())
|
||||
));
|
||||
@ -192,7 +283,7 @@ public class GeneralCommands {
|
||||
session.setSideEffectSet(applier);
|
||||
if (!showInfoBox) {
|
||||
actor.printInfo(TranslatableComponent.of(
|
||||
"worldedit.fast.sideeffect.set-all",
|
||||
"worldedit.perf.sideeffect.set-all",
|
||||
TranslatableComponent.of(newState.getDisplayName())
|
||||
));
|
||||
}
|
||||
@ -331,7 +422,7 @@ public class GeneralCommands {
|
||||
@ArgFlag(name = 'p', desc = "Page of results to return", def = "1")
|
||||
int page,
|
||||
@Arg(desc = "Search query", variable = true)
|
||||
List<String> query) throws Exception {
|
||||
List<String> query) {
|
||||
String search = String.join(" ", query);
|
||||
if (search.length() <= 2) {
|
||||
actor.printError(TranslatableComponent.of("worldedit.searchitem.too-short"));
|
||||
@ -342,7 +433,8 @@ public class GeneralCommands {
|
||||
return;
|
||||
}
|
||||
|
||||
actor.print(new ItemSearcher(search, blocksOnly, itemsOnly, page).call());
|
||||
WorldEditAsyncCommandBuilder.createAndSendMessage(actor, new ItemSearcher(search, blocksOnly, itemsOnly, page),
|
||||
TranslatableComponent.of("worldedit.searchitem.searching"));
|
||||
}
|
||||
|
||||
private static class ItemSearcher implements Callable<Component> {
|
||||
@ -361,7 +453,7 @@ public class GeneralCommands {
|
||||
@Override
|
||||
public Component call() throws Exception {
|
||||
String command = "/searchitem " + (blocksOnly ? "-b " : "") + (itemsOnly ? "-i " : "") + "-p %page% " + search;
|
||||
Map<String, String> results = new TreeMap<>();
|
||||
Map<String, Component> results = new TreeMap<>();
|
||||
String idMatch = search.replace(' ', '_');
|
||||
String nameMatch = search.toLowerCase(Locale.ROOT);
|
||||
for (ItemType searchType : ItemType.REGISTRY) {
|
||||
@ -373,15 +465,17 @@ public class GeneralCommands {
|
||||
continue;
|
||||
}
|
||||
final String id = searchType.getId();
|
||||
String name = searchType.getName();
|
||||
final boolean hasName = !name.equals(id);
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
if (id.contains(idMatch) || (hasName && name.contains(nameMatch))) {
|
||||
results.put(id, name + (hasName ? " (" + id + ")" : ""));
|
||||
if (id.contains(idMatch)) {
|
||||
Component name = searchType.getRichName();
|
||||
results.put(id, TextComponent.builder()
|
||||
.append(name)
|
||||
.append(" (" + id + ")")
|
||||
.build());
|
||||
}
|
||||
}
|
||||
List<String> list = new ArrayList<>(results.values());
|
||||
return PaginationBox.fromStrings("Search results for '" + search + "'", command, list).create(page);
|
||||
List<Component> list = new ArrayList<>(results.values());
|
||||
return PaginationBox.fromComponents("Search results for '" + search + "'", command, list)
|
||||
.create(page);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.command.tool.BlockDataCyler;
|
||||
import com.sk89q.worldedit.command.tool.BlockReplacer;
|
||||
import com.sk89q.worldedit.command.tool.DistanceWand;
|
||||
@ -35,19 +36,23 @@ import com.sk89q.worldedit.command.tool.LongRangeBuildTool;
|
||||
import com.sk89q.worldedit.command.tool.NavigationWand;
|
||||
import com.sk89q.worldedit.command.tool.QueryTool;
|
||||
import com.sk89q.worldedit.command.tool.SelectionWand;
|
||||
import com.sk89q.worldedit.command.tool.StackTool;
|
||||
import com.sk89q.worldedit.command.tool.Tool;
|
||||
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.command.util.SubCommandPermissionCondition;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
|
||||
import com.sk89q.worldedit.internal.command.CommandUtil;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import org.enginehub.piston.CommandManager;
|
||||
import org.enginehub.piston.CommandManagerService;
|
||||
import org.enginehub.piston.CommandMetadata;
|
||||
@ -82,14 +87,19 @@ public class ToolCommands {
|
||||
.collect(Collectors.toSet());
|
||||
for (org.enginehub.piston.Command command : commands) {
|
||||
if (command.getAliases().contains("unbind")) {
|
||||
// Don't register new /tool unbind alias
|
||||
// Don't register new /tool <whatever> alias
|
||||
command = command.toBuilder().aliases(
|
||||
Collections2.filter(command.getAliases(), alias -> !"unbind".equals(alias))
|
||||
).build();
|
||||
}
|
||||
if (command.getName().equals("stacker")) {
|
||||
// Don't register /stacker
|
||||
continue;
|
||||
}
|
||||
commandManager.register(CommandUtil.deprecate(
|
||||
command, "Global tool names cause conflicts "
|
||||
+ "and will be removed in WorldEdit 8", ToolCommands::asNonGlobal
|
||||
+ "and will be removed in WorldEdit 8",
|
||||
CommandUtil.ReplacementMessageGenerator.forNewCommand(ToolCommands::asNonGlobal)
|
||||
));
|
||||
}
|
||||
|
||||
@ -110,6 +120,8 @@ public class ToolCommands {
|
||||
.required()
|
||||
.build());
|
||||
command.description(TextComponent.of("Binds a tool to the item in your hand"));
|
||||
|
||||
command.condition(new SubCommandPermissionCondition.Generator(nonGlobalCommands).build());
|
||||
});
|
||||
}
|
||||
|
||||
@ -124,15 +136,32 @@ public class ToolCommands {
|
||||
|
||||
static void setToolNone(Player player, LocalSession session, boolean isBrush)
|
||||
throws InvalidToolBindException {
|
||||
session.setTool(player, null);
|
||||
session.setTool(player.getItemInHand(HandSide.MAIN_HAND).getType(), null);
|
||||
player.printInfo(TranslatableComponent.of(isBrush ? "worldedit.brush.none.equip" : "worldedit.tool.none.equip"));
|
||||
}
|
||||
|
||||
private static void setTool(Player player, LocalSession session, Tool tool,
|
||||
String translationKey) throws InvalidToolBindException {
|
||||
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
session.setTool(itemStack.getType(), tool);
|
||||
player.printInfo(TranslatableComponent.of(translationKey, itemStack.getRichName()));
|
||||
}
|
||||
|
||||
private final WorldEdit we;
|
||||
|
||||
public ToolCommands(WorldEdit we) {
|
||||
this.we = we;
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "none",
|
||||
aliases = "unbind",
|
||||
desc = "Unbind a bound tool from your current item"
|
||||
)
|
||||
public void none(Player player, LocalSession session) throws WorldEditException {
|
||||
setToolNone(player, session, false);
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "selwand",
|
||||
aliases = "/selwand",
|
||||
@ -140,9 +169,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.setwand")
|
||||
public void selwand(Player player, LocalSession session) throws WorldEditException {
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(player, SelectionWand.INSTANCE);
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.selwand.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, SelectionWand.INSTANCE, "worldedit.tool.selwand.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -152,10 +179,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.setwand")
|
||||
public void navwand(Player player, LocalSession session) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(player, NavigationWand.INSTANCE);
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.navwand.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, NavigationWand.INSTANCE, "worldedit.tool.navwand.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -165,10 +189,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.tool.info")
|
||||
public void info(Player player, LocalSession session) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(player, new QueryTool());
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.info.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new QueryTool(), "worldedit.tool.info.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -178,9 +199,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.tool.inspect")
|
||||
public void inspectBrush(Player player, LocalSession session) throws WorldEditException {
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(player, new InspectBrush());
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.inspect.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new InspectBrush(), "worldedit.tool.info.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -192,10 +211,20 @@ public class ToolCommands {
|
||||
public void tree(Player player, LocalSession session,
|
||||
@Arg(desc = "Type of tree to generate", def = "tree")
|
||||
TreeGenerator.TreeType type) throws WorldEditException {
|
||||
setTool(player, session, new TreePlanter(type), "worldedit.tool.tree.equip");
|
||||
}
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(player, new TreePlanter(type));
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.tree.equip", TextComponent.of(itemType.getName())));
|
||||
@Command(
|
||||
name = "stacker",
|
||||
desc = "Block stacker tool"
|
||||
)
|
||||
@CommandPermissions("worldedit.tool.stack")
|
||||
public void stacker(Player player, LocalSession session,
|
||||
@Arg(desc = "The max range of the stack", def = "10")
|
||||
int range,
|
||||
@Arg(desc = "The mask to stack until", def = "!#existing")
|
||||
Mask mask) throws WorldEditException {
|
||||
setTool(player, session, new StackTool(range, mask), "worldedit.tool.stack.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -207,10 +236,7 @@ public class ToolCommands {
|
||||
public void repl(Player player, LocalSession session,
|
||||
@Arg(desc = "The pattern of blocks to place")
|
||||
Pattern pattern) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(player, new BlockReplacer(pattern));
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.repl.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new BlockReplacer(pattern), "worldedit.tool.repl.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -220,10 +246,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.tool.data-cycler")
|
||||
public void cycler(Player player, LocalSession session) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(player, new BlockDataCyler());
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.data-cycler.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new BlockDataCyler(), "worldedit.tool.data-cycler.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -241,13 +264,10 @@ public class ToolCommands {
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
if (range > config.maxSuperPickaxeSize) {
|
||||
player.printError(TranslatableComponent.of("worldedit.superpickaxe.max-range", TextComponent.of(config.maxSuperPickaxeSize)));
|
||||
player.printError(TranslatableComponent.of("worldedit.tool.superpickaxe.max-range", TextComponent.of(config.maxSuperPickaxeSize)));
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(player, new FloodFillTool(range, pattern));
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.floodfill.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new FloodFillTool(range, pattern), "worldedit.tool.floodfill.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -257,10 +277,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.tool.deltree")
|
||||
public void deltree(Player player, LocalSession session) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(player, new FloatingTreeRemover());
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.deltree.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new FloatingTreeRemover(), "worldedit.tool.deltree.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -270,9 +287,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.tool.farwand")
|
||||
public void farwand(Player player, LocalSession session) throws WorldEditException {
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(player, new DistanceWand());
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.farwand.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new DistanceWand(), "worldedit.tool.farwand.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -286,18 +301,19 @@ public class ToolCommands {
|
||||
Pattern primary,
|
||||
@Arg(desc = "Pattern to set on right-click")
|
||||
Pattern secondary) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(player, new LongRangeBuildTool(primary, secondary));
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.lrbuild.equip", TextComponent.of(itemType.getName())));
|
||||
String primaryName = "pattern";
|
||||
String secondaryName = "pattern";
|
||||
setTool(player, session, new LongRangeBuildTool(primary, secondary), "worldedit.tool.lrbuild.equip");
|
||||
Component primaryName;
|
||||
Component secondaryName;
|
||||
if (primary instanceof BlockStateHolder) {
|
||||
primaryName = ((BlockStateHolder<?>) primary).getBlockType().getName();
|
||||
primaryName = ((BlockStateHolder<?>) primary).getBlockType().getRichName();
|
||||
} else {
|
||||
primaryName = TextComponent.of("pattern");
|
||||
}
|
||||
if (secondary instanceof BlockStateHolder) {
|
||||
secondaryName = ((BlockStateHolder<?>) secondary).getBlockType().getName();
|
||||
secondaryName = ((BlockStateHolder<?>) secondary).getBlockType().getRichName();
|
||||
} else {
|
||||
secondaryName = TextComponent.of("pattern");
|
||||
}
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.lrbuild.set", TextComponent.of(primaryName), TextComponent.of(secondaryName)));
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.lrbuild.set", primaryName, secondaryName));
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,7 @@ 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.Chunk3dVectorConverter;
|
||||
import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter;
|
||||
import com.sk89q.worldedit.command.argument.DirectionConverter;
|
||||
import com.sk89q.worldedit.command.argument.DirectionVectorConverter;
|
||||
@ -90,7 +91,9 @@ import com.sk89q.worldedit.command.argument.EntityRemoverConverter;
|
||||
import com.sk89q.worldedit.command.argument.EnumConverter;
|
||||
import com.sk89q.worldedit.command.argument.ExpressionConverter;
|
||||
import com.sk89q.worldedit.command.argument.FactoryConverter;
|
||||
import com.sk89q.worldedit.command.argument.HeightConverter;
|
||||
import com.sk89q.worldedit.command.argument.LocationConverter;
|
||||
import com.sk89q.worldedit.command.argument.OffsetConverter;
|
||||
import com.sk89q.worldedit.command.argument.RegionFactoryConverter;
|
||||
import com.sk89q.worldedit.command.argument.RegistryConverter;
|
||||
import com.sk89q.worldedit.command.argument.SideEffectConverter;
|
||||
@ -250,6 +253,7 @@ public final class PlatformCommandManager {
|
||||
);
|
||||
}
|
||||
VectorConverter.register(commandManager);
|
||||
Chunk3dVectorConverter.register(commandManager);
|
||||
EnumConverter.register(commandManager);
|
||||
RegistryConverter.register(commandManager);
|
||||
ZonedDateTimeConverter.register(commandManager);
|
||||
@ -260,6 +264,8 @@ public final class PlatformCommandManager {
|
||||
LocationConverter.register(commandManager);
|
||||
ExpressionConverter.register(commandManager);
|
||||
SideEffectConverter.register(commandManager);
|
||||
HeightConverter.register(commandManager);
|
||||
OffsetConverter.register(worldEdit, commandManager);
|
||||
|
||||
registerBindings(new ConsumeBindings(worldEdit, this));
|
||||
registerBindings(new PrimitiveBindings(worldEdit));
|
||||
@ -359,9 +365,8 @@ public final class PlatformCommandManager {
|
||||
}
|
||||
|
||||
private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
|
||||
CommandManager commandManager,
|
||||
Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance,
|
||||
@NotNull Consumer<CommandManager> additionalConfig) {
|
||||
Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance,
|
||||
@NotNull Consumer<CommandManager> additionalConfig) {
|
||||
commandManager.register(name, cmd -> {
|
||||
cmd.aliases(aliases);
|
||||
cmd.description(TextComponent.of(desc));
|
||||
@ -438,8 +443,8 @@ public final class PlatformCommandManager {
|
||||
"brush",
|
||||
Lists.newArrayList("br", "/brush", "/br", "/tool", "tool"),
|
||||
"Brushing commands",
|
||||
commandManager,
|
||||
c -> {
|
||||
// TODO find out what's going on here
|
||||
c.accept(BrushCommandsRegistration.builder(), new BrushCommands(worldEdit));
|
||||
c.accept(ToolCommandsRegistration.builder(), new ToolCommands(worldEdit));
|
||||
c.accept(ToolUtilCommandsRegistration.builder(), new ToolUtilCommands(worldEdit));
|
||||
@ -491,10 +496,11 @@ public final class PlatformCommandManager {
|
||||
GeneralCommandsRegistration.builder(),
|
||||
new GeneralCommands(worldEdit)
|
||||
);
|
||||
this.registration.register(
|
||||
GeneralCommands.register(
|
||||
registration,
|
||||
commandManager,
|
||||
GenerationCommandsRegistration.builder(),
|
||||
new GenerationCommands(worldEdit)
|
||||
commandManagerService,
|
||||
worldEdit
|
||||
);
|
||||
HistoryCommands history = new HistoryCommands(worldEdit);
|
||||
this.registration.register(
|
||||
|
@ -52,14 +52,12 @@ public class CommandUtil {
|
||||
|
||||
private static final Component DEPRECATION_MARKER = TextComponent.of("This command is deprecated.");
|
||||
|
||||
private static Component makeDeprecatedFooter(String reason, Component newCommand) {
|
||||
private static Component makeDeprecatedFooter(String reason, Component replacement) {
|
||||
return TextComponent.builder()
|
||||
.append(DEPRECATION_MARKER)
|
||||
.append(" " + reason + ".")
|
||||
.append(TextComponent.newline())
|
||||
.append(TextComponent.of("Use ", TextColor.GOLD, TextDecoration.ITALIC))
|
||||
.append(newCommand)
|
||||
.append(TextComponent.of(" instead.", TextColor.GOLD, TextDecoration.ITALIC))
|
||||
.append(replacement.color(TextColor.GOLD).decoration(TextDecoration.ITALIC, true))
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -69,20 +67,48 @@ public class CommandUtil {
|
||||
|
||||
}
|
||||
|
||||
public interface ReplacementMessageGenerator {
|
||||
|
||||
/**
|
||||
* Generate text that says "Please use [cmd] instead." and allows clicking to dump
|
||||
* the command to the text box.
|
||||
*/
|
||||
static ReplacementMessageGenerator forNewCommand(NewCommandGenerator generator) {
|
||||
return (oldCommand, oldParameters) -> {
|
||||
String suggestedCommand = generator.newCommand(oldCommand, oldParameters);
|
||||
return createNewCommandReplacementText(suggestedCommand);
|
||||
};
|
||||
}
|
||||
|
||||
Component getReplacement(Command oldCommand, CommandParameters oldParameters);
|
||||
|
||||
}
|
||||
|
||||
public static Component createNewCommandReplacementText(String suggestedCommand) {
|
||||
return TextComponent.builder("Please use ", TextColor.GOLD)
|
||||
.append(TextComponent.of(suggestedCommand)
|
||||
.decoration(TextDecoration.UNDERLINED, true)
|
||||
.clickEvent(ClickEvent.suggestCommand(suggestedCommand)))
|
||||
.append(" instead.")
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Command deprecate(Command command, String reason,
|
||||
NewCommandGenerator newCommandGenerator) {
|
||||
ReplacementMessageGenerator replacementMessageGenerator) {
|
||||
Component deprecatedWarning = makeDeprecatedFooter(
|
||||
reason,
|
||||
newCommandSuggestion(newCommandGenerator,
|
||||
NoInputCommandParameters.builder().build(),
|
||||
command)
|
||||
replacementMessageGenerator.getReplacement(
|
||||
command,
|
||||
NoInputCommandParameters.builder().build()
|
||||
)
|
||||
);
|
||||
return command.toBuilder()
|
||||
.action(parameters ->
|
||||
deprecatedCommandWarning(parameters, command, reason, newCommandGenerator))
|
||||
deprecatedCommandWarning(parameters, command, reason, replacementMessageGenerator))
|
||||
.footer(command.getFooter()
|
||||
.map(existingFooter -> existingFooter
|
||||
.append(TextComponent.newline()).append(deprecatedWarning))
|
||||
.append(TextComponent.newline())
|
||||
.append(deprecatedWarning))
|
||||
.orElse(deprecatedWarning))
|
||||
.build();
|
||||
}
|
||||
@ -139,26 +165,28 @@ public class CommandUtil {
|
||||
CommandParameters parameters,
|
||||
Command command,
|
||||
String reason,
|
||||
NewCommandGenerator generator
|
||||
ReplacementMessageGenerator generator
|
||||
) throws Exception {
|
||||
parameters.injectedValue(Key.of(Actor.class))
|
||||
.ifPresent(actor -> {
|
||||
Component suggestion = newCommandSuggestion(generator, parameters, command);
|
||||
actor.print(TextComponent.of(reason + ". Please use ", TextColor.GOLD)
|
||||
.append(suggestion)
|
||||
.append(TextComponent.of(" instead."))
|
||||
);
|
||||
});
|
||||
.ifPresent(actor ->
|
||||
sendDeprecationMessage(parameters, command, reason, generator, actor)
|
||||
);
|
||||
return command.getAction().run(parameters);
|
||||
}
|
||||
|
||||
private static Component newCommandSuggestion(NewCommandGenerator generator,
|
||||
CommandParameters parameters,
|
||||
Command command) {
|
||||
String suggestedCommand = generator.newCommand(command, parameters);
|
||||
return TextComponent.of(suggestedCommand)
|
||||
.decoration(TextDecoration.UNDERLINED, true)
|
||||
.clickEvent(ClickEvent.suggestCommand(suggestedCommand));
|
||||
private static void sendDeprecationMessage(
|
||||
CommandParameters parameters,
|
||||
Command command,
|
||||
String reason,
|
||||
ReplacementMessageGenerator generator,
|
||||
Actor actor
|
||||
) {
|
||||
Component replacement = generator.getReplacement(command, parameters);
|
||||
actor.print(
|
||||
TextComponent.builder(reason + ". ", TextColor.GOLD)
|
||||
.append(replacement)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public static Map<String, Command> getSubCommands(Command currentCommand) {
|
||||
|
@ -213,10 +213,10 @@
|
||||
"worldedit.fast.enabled": "Fast mode enabled. Lighting in the affected chunks may be wrong and/or you may need to rejoin to see changes.",
|
||||
"worldedit.fast.disabled.already": "Fast mode already disabled.",
|
||||
"worldedit.fast.enabled.already": "Fast mode already enabled.",
|
||||
"worldedit.fast.sideeffect.set": "Side effect \"{0}\" set to {1}",
|
||||
"worldedit.fast.sideeffect.get": "Side effect \"{0}\" is set to {1}",
|
||||
"worldedit.fast.sideeffect.already-set": "Side effect \"{0}\" is already {1}",
|
||||
"worldedit.fast.sideeffect.set-all": "All side effects set to {0}",
|
||||
"worldedit.perf.sideeffect.set": "Side effect \"{0}\" set to {1}",
|
||||
"worldedit.perf.sideeffect.get": "Side effect \"{0}\" is set to {1}",
|
||||
"worldedit.perf.sideeffect.already-set": "Side effect \"{0}\" is already {1}",
|
||||
"worldedit.perf.sideeffect.set-all": "All side effects set to {0}",
|
||||
"worldedit.reorder.current": "The reorder mode is {0}",
|
||||
"worldedit.reorder.set": "The reorder mode is now {0}",
|
||||
"worldedit.gmask.disabled": "Global mask disabled.",
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren