Determine if a player has an item bound for unbind

This commit is contained in:
Octavia Togami 2020-07-27 22:29:30 -07:00
parent cbe788c9a3
commit 1083a36df5
2 changed files with 12 additions and 2 deletions

View File

@ -52,6 +52,7 @@
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;
@ -135,8 +136,16 @@ private static String asNonGlobal(org.enginehub.piston.Command oldCommand,
static void setToolNone(Player player, LocalSession session, boolean isBrush)
throws InvalidToolBindException {
session.setTool(player.getItemInHand(HandSide.MAIN_HAND).getType(), null);
player.printInfo(TranslatableComponent.of(isBrush ? "worldedit.brush.none.equip" : "worldedit.tool.none.equip"));
ItemType type = player.getItemInHand(HandSide.MAIN_HAND).getType();
boolean set = session.getTool(type) != null
|| type.getId().equals(session.getWandItem())
|| type.getId().equals(session.getNavWandItem());
if (set) {
session.setTool(type, null);
player.printInfo(TranslatableComponent.of(isBrush ? "worldedit.brush.none.equip" : "worldedit.tool.none.equip"));
} else {
player.printInfo(TranslatableComponent.of("worldedit.tool.none.to.unequip"));
}
}
private static void setTool(Player player, LocalSession session, Tool tool,

View File

@ -262,6 +262,7 @@
"worldedit.tool.info.legacy.hover": "Legacy id:data",
"worldedit.tool.info.light.hover": "Block Light/Light Above",
"worldedit.tool.none.equip": "Tool unbound from your current item.",
"worldedit.tool.none.to.unequip": "Your current item is not bound.",
"worldedit.tool.selwand.equip": "Selection wand bound to {0}.",
"worldedit.tool.navwand.equip": "Navigation wand bound to {0}.",
"worldedit.tool.floodfill.equip": "Block flood fill tool bound to {0}.",