Search in sources :

Example 1 with Tool

use of com.sk89q.worldedit.command.tool.Tool in project FastAsyncWorldEdit by IntellectualSites.

the class PlatformManager method handlePlayerInput.

// FAWE end
@Subscribe
public void handlePlayerInput(PlayerInputEvent event) {
    // Create a proxy actor with a potentially different world for
    // making changes to the world
    Player player = createProxyActor(event.getPlayer());
    LocalSession session = worldEdit.getSessionManager().get(player);
    try {
        switch(event.getInputType()) {
            case PRIMARY:
                {
                    Tool tool = session.getTool(player);
                    if (tool instanceof DoubleActionTraceTool && tool.canUse(player)) {
                        // FAWE start - run async
                        player.runAsyncIfFree(() -> reset((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session));
                        // FAWE end
                        event.setCancelled(true);
                        return;
                    }
                    break;
                }
            case SECONDARY:
                {
                    Tool tool = session.getTool(player);
                    if (tool instanceof TraceTool && tool.canUse(player)) {
                        // FAWE start - run async
                        // todo this needs to be fixed so the event is canceled after actPrimary is used and returns true
                        player.runAction(() -> reset((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session), false, true);
                        // FAWE end
                        event.setCancelled(true);
                        return;
                    }
                    break;
                }
        }
    // FAWE start - add own message
    } catch (Throwable e) {
        FaweException faweException = FaweException.get(e);
        if (faweException != null) {
            player.print(Caption.of("fawe.cancel.reason", faweException.getComponent()));
        } else {
            player.print(Caption.of("worldedit.command.error.report"));
            player.print(TextComponent.of(e.getClass().getName() + ": " + e.getMessage()));
            e.printStackTrace();
        }
    // FAWE end
    } finally {
        Request.reset();
    }
}
Also used : TraceTool(com.sk89q.worldedit.command.tool.TraceTool) DoubleActionTraceTool(com.sk89q.worldedit.command.tool.DoubleActionTraceTool) DoubleActionTraceTool(com.sk89q.worldedit.command.tool.DoubleActionTraceTool) Player(com.sk89q.worldedit.entity.Player) LocalSession(com.sk89q.worldedit.LocalSession) FaweException(com.fastasyncworldedit.core.internal.exception.FaweException) DoubleActionBlockTool(com.sk89q.worldedit.command.tool.DoubleActionBlockTool) TraceTool(com.sk89q.worldedit.command.tool.TraceTool) BlockTool(com.sk89q.worldedit.command.tool.BlockTool) DoubleActionTraceTool(com.sk89q.worldedit.command.tool.DoubleActionTraceTool) BrushTool(com.sk89q.worldedit.command.tool.BrushTool) Tool(com.sk89q.worldedit.command.tool.Tool) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 2 with Tool

use of com.sk89q.worldedit.command.tool.Tool in project FastAsyncWorldEdit by IntellectualSites.

the class PlatformManager method handleBlockInteract.

@Subscribe
public void handleBlockInteract(BlockInteractEvent event) {
    // Create a proxy actor with a potentially different world for
    // making changes to the world
    Actor actor = createProxyActor(event.getCause());
    Location location = event.getLocation();
    // At this time, only handle interaction from players
    if (!(actor instanceof Player)) {
        return;
    }
    Player player = (Player) actor;
    LocalSession session = worldEdit.getSessionManager().get(actor);
    Request.reset();
    Request.request().setSession(session);
    Request.request().setWorld(player.getWorld());
    try {
        if (event.getType() == Interaction.HIT) {
            // in addition, it is implicitly bound to all pickaxe items, not just a single tool item
            if (session.hasSuperPickAxe() && player.isHoldingPickAxe()) {
                final BlockTool superPickaxe = session.getSuperPickaxe();
                if (superPickaxe != null && superPickaxe.canUse(player)) {
                    // FAWE start - run async
                    player.runAction(() -> reset(superPickaxe).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace()), false, true);
                    // FAWE end
                    event.setCancelled(true);
                    return;
                }
            }
            Tool tool = session.getTool(player);
            if (tool instanceof DoubleActionBlockTool && tool.canUse(player)) {
                // FAWE start - run async
                player.runAction(() -> reset((DoubleActionBlockTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace()), false, true);
                // FAWE end
                event.setCancelled(true);
            }
        } else if (event.getType() == Interaction.OPEN) {
            // FAWE start - get general tool over item in main hand & run async
            Tool tool = session.getTool(player);
            if (tool instanceof BlockTool && tool.canUse(player)) {
                if (player.checkAction()) {
                    // FAWE run async
                    player.runAction(() -> {
                        BlockTool blockTool = (BlockTool) tool;
                        if (!(tool instanceof BrushTool)) {
                            blockTool = reset(blockTool);
                        }
                        blockTool.actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace());
                    }, false, true);
                    // FAWE end
                    event.setCancelled(true);
                }
            }
        }
    } catch (Throwable e) {
        handleThrowable(e, actor);
    } finally {
        Request.reset();
    }
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) Player(com.sk89q.worldedit.entity.Player) DoubleActionBlockTool(com.sk89q.worldedit.command.tool.DoubleActionBlockTool) DoubleActionBlockTool(com.sk89q.worldedit.command.tool.DoubleActionBlockTool) BlockTool(com.sk89q.worldedit.command.tool.BlockTool) LocalSession(com.sk89q.worldedit.LocalSession) Location(com.sk89q.worldedit.util.Location) DoubleActionBlockTool(com.sk89q.worldedit.command.tool.DoubleActionBlockTool) TraceTool(com.sk89q.worldedit.command.tool.TraceTool) BlockTool(com.sk89q.worldedit.command.tool.BlockTool) DoubleActionTraceTool(com.sk89q.worldedit.command.tool.DoubleActionTraceTool) BrushTool(com.sk89q.worldedit.command.tool.BrushTool) Tool(com.sk89q.worldedit.command.tool.Tool) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 3 with Tool

use of com.sk89q.worldedit.command.tool.Tool in project FastAsyncWorldEdit by IntellectualSites.

the class ToolCommands method register.

public static void register(CommandRegistrationHandler registration, CommandManager commandManager, CommandManagerService commandManagerService, WorldEdit worldEdit) {
    // Collect the tool commands
    CommandManager collect = commandManagerService.newCommandManager();
    registration.register(collect, ToolCommandsRegistration.builder(), new ToolCommands(worldEdit));
    // Register deprecated global commands
    Set<org.enginehub.piston.Command> commands = collect.getAllCommands().collect(Collectors.toSet());
    for (org.enginehub.piston.Command command : commands) {
        if (command.getAliases().contains("unbind")) {
            // 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", CommandUtil.ReplacementMessageGenerator.forNewCommand(ToolCommands::asNonGlobal)));
    }
    // Remove aliases with / in them, since it doesn't make sense for sub-commands.
    Set<org.enginehub.piston.Command> nonGlobalCommands = commands.stream().map(command -> command.toBuilder().aliases(Collections2.filter(command.getAliases(), alias -> !alias.startsWith("/"))).build()).collect(Collectors.toSet());
    commandManager.register("tool", command -> {
        command.addPart(SubCommandPart.builder(Caption.of("tool"), TextComponent.of("The tool to bind")).withCommands(nonGlobalCommands).required().build());
        command.description(TextComponent.of("Binds a tool to the item in your hand"));
        command.condition(new SubCommandPermissionCondition.Generator(nonGlobalCommands).build());
    });
}
Also used : SubCommandPart(org.enginehub.piston.part.SubCommandPart) CommandParameters(org.enginehub.piston.CommandParameters) BlockDataCyler(com.sk89q.worldedit.command.tool.BlockDataCyler) Player(com.sk89q.worldedit.entity.Player) StackTool(com.sk89q.worldedit.command.tool.StackTool) Caption(com.fastasyncworldedit.core.configuration.Caption) Collections2(com.google.common.collect.Collections2) BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) FloodFillTool(com.sk89q.worldedit.command.tool.FloodFillTool) Arg(org.enginehub.piston.annotation.param.Arg) SubCommandPermissionCondition(com.sk89q.worldedit.command.util.SubCommandPermissionCondition) Component(com.sk89q.worldedit.util.formatting.text.Component) WorldEditException(com.sk89q.worldedit.WorldEditException) SelectionWand(com.sk89q.worldedit.command.tool.SelectionWand) CommandContainer(org.enginehub.piston.annotation.CommandContainer) TreeGenerator(com.sk89q.worldedit.util.TreeGenerator) TextColor(com.sk89q.worldedit.util.formatting.text.format.TextColor) InspectBrush(com.fastasyncworldedit.core.command.tool.brush.InspectBrush) ClickEvent(com.sk89q.worldedit.util.formatting.text.event.ClickEvent) NavigationWand(com.sk89q.worldedit.command.tool.NavigationWand) QueryTool(com.sk89q.worldedit.command.tool.QueryTool) WorldEdit(com.sk89q.worldedit.WorldEdit) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) FloatingTreeRemover(com.sk89q.worldedit.command.tool.FloatingTreeRemover) HandSide(com.sk89q.worldedit.util.HandSide) CommandManager(org.enginehub.piston.CommandManager) CommandMetadata(org.enginehub.piston.CommandMetadata) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) InvalidToolBindException(com.sk89q.worldedit.command.tool.InvalidToolBindException) BrushTool(com.sk89q.worldedit.command.tool.BrushTool) Set(java.util.Set) CommandUtil(com.sk89q.worldedit.internal.command.CommandUtil) BlockReplacer(com.sk89q.worldedit.command.tool.BlockReplacer) Collectors(java.util.stream.Collectors) Tool(com.sk89q.worldedit.command.tool.Tool) CommandManagerService(org.enginehub.piston.CommandManagerService) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) DistanceWand(com.sk89q.worldedit.command.tool.DistanceWand) Command(org.enginehub.piston.annotation.Command) CommandPermissionsConditionGenerator(com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator) TreePlanter(com.sk89q.worldedit.command.tool.TreePlanter) LongRangeBuildTool(com.sk89q.worldedit.command.tool.LongRangeBuildTool) Optional(java.util.Optional) LocalSession(com.sk89q.worldedit.LocalSession) Mask(com.sk89q.worldedit.function.mask.Mask) Pattern(com.sk89q.worldedit.function.pattern.Pattern) CommandRegistrationHandler(com.sk89q.worldedit.internal.command.CommandRegistrationHandler) CommandManager(org.enginehub.piston.CommandManager) Command(org.enginehub.piston.annotation.Command) TreeGenerator(com.sk89q.worldedit.util.TreeGenerator) CommandPermissionsConditionGenerator(com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator)

Aggregations

LocalSession (com.sk89q.worldedit.LocalSession)3 BrushTool (com.sk89q.worldedit.command.tool.BrushTool)3 Tool (com.sk89q.worldedit.command.tool.Tool)3 Player (com.sk89q.worldedit.entity.Player)3 BlockTool (com.sk89q.worldedit.command.tool.BlockTool)2 DoubleActionBlockTool (com.sk89q.worldedit.command.tool.DoubleActionBlockTool)2 DoubleActionTraceTool (com.sk89q.worldedit.command.tool.DoubleActionTraceTool)2 TraceTool (com.sk89q.worldedit.command.tool.TraceTool)2 Subscribe (com.sk89q.worldedit.util.eventbus.Subscribe)2 InspectBrush (com.fastasyncworldedit.core.command.tool.brush.InspectBrush)1 Caption (com.fastasyncworldedit.core.configuration.Caption)1 FaweException (com.fastasyncworldedit.core.internal.exception.FaweException)1 Collections2 (com.google.common.collect.Collections2)1 LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)1 WorldEdit (com.sk89q.worldedit.WorldEdit)1 WorldEditException (com.sk89q.worldedit.WorldEditException)1 BaseItemStack (com.sk89q.worldedit.blocks.BaseItemStack)1 BlockDataCyler (com.sk89q.worldedit.command.tool.BlockDataCyler)1 BlockReplacer (com.sk89q.worldedit.command.tool.BlockReplacer)1 DistanceWand (com.sk89q.worldedit.command.tool.DistanceWand)1