Add instructions for unbinding tools/brushes on equip. (#1595)

* Add unbind instructions to tool/brush commands.

* Switch to suggest.

* Make component final.

* Start suggesting the unbind alias instead.
This commit is contained in:
wizjany 2020-11-28 09:13:03 -05:00 committed by GitHub
parent cc1f530aa4
commit d6b42a4816
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -66,8 +66,11 @@
import com.sk89q.worldedit.util.asset.AssetLoadTask;
import com.sk89q.worldedit.util.asset.AssetLoader;
import com.sk89q.worldedit.util.asset.holder.ImageHeightmap;
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.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.enginehub.piston.annotation.Command;
@ -88,6 +91,10 @@ public class BrushCommands {
private final WorldEdit worldEdit;
private static final Component UNBIND_COMMAND_COMPONENT = TextComponent.builder("/brush unbind", TextColor.AQUA)
.clickEvent(ClickEvent.suggestCommand("/brush unbind"))
.build();
/**
* Create a new instance.
*
@ -133,6 +140,7 @@ public void sphereBrush(Player player, LocalSession session,
}
player.printInfo(TranslatableComponent.of("worldedit.brush.sphere.equip", TextComponent.of(String.format("%.0f", radius))));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
@Command(
@ -164,6 +172,7 @@ public void cylinderBrush(Player player, LocalSession session,
}
player.printInfo(TranslatableComponent.of("worldedit.brush.cylinder.equip", TextComponent.of((int) radius), TextComponent.of(height)));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
@Command(
@ -200,6 +209,7 @@ public void clipboardBrush(Player player, LocalSession session,
tool.setBrush(new ClipboardBrush(newHolder, ignoreAir, usingOrigin, pasteEntities, pasteBiomes, sourceMask), "worldedit.brush.clipboard");
player.printInfo(TranslatableComponent.of("worldedit.brush.clipboard.equip"));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
@Command(
@ -227,6 +237,7 @@ public void smoothBrush(Player player, LocalSession session,
TextComponent.of(iterations),
TextComponent.of(mask == null ? "any block" : "filter")
));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
@Command(
@ -247,6 +258,7 @@ public void extinguishBrush(Player player, LocalSession session,
tool.setBrush(new SphereBrush(), "worldedit.brush.ex");
player.printInfo(TranslatableComponent.of("worldedit.brush.extinguish.equip", TextComponent.of((int) radius)));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
@Command(
@ -274,6 +286,7 @@ public void gravityBrush(Player player, LocalSession session,
tool.setBrush(new GravityBrush(height), "worldedit.brush.gravity");
player.printInfo(TranslatableComponent.of("worldedit.brush.gravity.equip", TextComponent.of((int) radius)));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
@Command(
@ -333,6 +346,7 @@ public void butcherBrush(Player player, LocalSession session,
tool.setBrush(new ButcherBrush(flags), "worldedit.brush.butcher");
player.printInfo(TranslatableComponent.of("worldedit.brush.butcher.equip", TextComponent.of((int) radius)));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
@Command(
@ -367,6 +381,7 @@ void heightmapBrush(Player player, LocalSession session,
.onSuccess(TranslatableComponent.of("worldedit.brush.heightmap.equip", TextComponent.of((int) radius)), heightmap -> {
tool.setSize(radius);
tool.setBrush(new ImageHeightmapBrush(heightmap, intensity, erase, flatten, randomize), "worldedit.brush.heightmap");
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
})
.onFailure(TranslatableComponent.of("worldedit.asset.load.failed"), worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter())
.buildAndExec(worldEdit.getExecutorService());
@ -514,5 +529,6 @@ static void setOperationBasedBrush(Player player, LocalSession session, double r
tool.setBrush(new OperationFactoryBrush(factory, shape, session), permission);
player.printInfo(TranslatableComponent.of("worldedit.brush.operation.equip", TextComponent.of(factory.toString())));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
}

View File

@ -51,6 +51,8 @@
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.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.item.ItemType;
import org.enginehub.piston.CommandManager;
@ -69,6 +71,10 @@
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class ToolCommands {
private static final Component UNBIND_COMMAND_COMPONENT = TextComponent.builder("/tool unbind", TextColor.AQUA)
.clickEvent(ClickEvent.suggestCommand("/tool unbind"))
.build();
public static void register(CommandRegistrationHandler registration,
CommandManager commandManager,
CommandManagerService commandManagerService,
@ -148,11 +154,16 @@ static void setToolNone(Player player, LocalSession session, boolean isBrush)
}
}
static void sendUnbindInstruction(Player sender, Component commandComponent) {
sender.printDebug(TranslatableComponent.of("worldedit.tool.unbind-instruction", commandComponent));
}
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()));
sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
private final WorldEdit we;

View File

@ -291,6 +291,8 @@
"worldedit.tool.lrbuild.set": "Left-click set to {0}; right-click set to {1}.",
"worldedit.tool.stack.equip": "Stack tool bound to {0}.",
"worldedit.tool.unbind-instruction": "Run {0} while holding the item to unbind it.",
"worldedit.tool.superpickaxe.mode.single": "Mode is now single. Left click with a pickaxe. // to disable.",
"worldedit.tool.superpickaxe.mode.area": "Mode is now area. Left click with a pickaxe. // to disable.",
"worldedit.tool.superpickaxe.mode.recursive": "Mode is now recursive. Left click with a pickaxe. // to disable.",