Search in sources :

Example 6 with BrushTool

use of com.sk89q.worldedit.command.tool.BrushTool 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 7 with BrushTool

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

the class BrushCommands method setOperationBasedBrush.

// FAWE end
static void setOperationBasedBrush(Player player, LocalSession session, double radius, Contextual<? extends Operation> factory, RegionFactory shape, String permission) throws WorldEditException {
    WorldEdit.getInstance().checkMaxBrushRadius(radius);
    BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
    tool.setSize(radius);
    tool.setFill(null);
    tool.setBrush(new OperationFactoryBrush(factory, shape, session), permission);
    player.print(Caption.of("worldedit.brush.operation.equip", TextComponent.of(factory.toString())));
    ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) OperationFactoryBrush(com.sk89q.worldedit.command.tool.brush.OperationFactoryBrush)

Example 8 with BrushTool

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

the class BrushCommands method setOperationBasedBrush.

// FAWE end
static void setOperationBasedBrush(Player player, LocalSession session, // FAWE start - Expression > double
Expression radius, // FAWE end
Contextual<? extends Operation> factory, RegionFactory shape, String permission) throws WorldEditException {
    WorldEdit.getInstance().checkMaxBrushRadius(radius);
    BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
    tool.setSize(radius);
    tool.setFill(null);
    tool.setBrush(new OperationFactoryBrush(factory, shape, session), permission);
    player.print(Caption.of("worldedit.brush.operation.equip", TextComponent.of(factory.toString())));
    ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) OperationFactoryBrush(com.sk89q.worldedit.command.tool.brush.OperationFactoryBrush)

Example 9 with BrushTool

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

the class ScrollTargetOffset method increment.

@Override
public boolean increment(Player player, int amount) {
    BrushTool tool = getTool();
    tool.setTargetOffset(tool.getTargetOffset() + amount);
    return true;
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool)

Example 10 with BrushTool

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

the class BrushCommands method process.

// FAWE start
public BrushSettings process(Player player, Arguments arguments, BrushSettings settings) throws WorldEditException {
    LocalSession session = worldEdit.getSessionManager().get(player);
    session.setTool(player, null);
    BrushTool tool = session.getBrushTool(player);
    if (tool != null) {
        tool.setPrimary(settings);
        tool.setSecondary(settings);
        player.print(Caption.of("fawe.worldedit.brush.brush.equipped", arguments.get().split(" ")[1]));
        ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
    }
    return settings;
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) LocalSession(com.sk89q.worldedit.LocalSession)

Aggregations

BrushTool (com.sk89q.worldedit.command.tool.BrushTool)17 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)10 Command (org.enginehub.piston.annotation.Command)10 BrushSettings (com.fastasyncworldedit.core.command.tool.brush.BrushSettings)6 LocalSession (com.sk89q.worldedit.LocalSession)3 OperationFactoryBrush (com.sk89q.worldedit.command.tool.brush.OperationFactoryBrush)3 BaseItem (com.sk89q.worldedit.blocks.BaseItem)2 TargetMode (com.fastasyncworldedit.core.command.tool.TargetMode)1 BlobBrush (com.fastasyncworldedit.core.command.tool.brush.BlobBrush)1 CatenaryBrush (com.fastasyncworldedit.core.command.tool.brush.CatenaryBrush)1 CircleBrush (com.fastasyncworldedit.core.command.tool.brush.CircleBrush)1 CommandBrush (com.fastasyncworldedit.core.command.tool.brush.CommandBrush)1 CopyPastaBrush (com.fastasyncworldedit.core.command.tool.brush.CopyPastaBrush)1 ErodeBrush (com.fastasyncworldedit.core.command.tool.brush.ErodeBrush)1 FlattenBrush (com.fastasyncworldedit.core.command.tool.brush.FlattenBrush)1 HeightBrush (com.fastasyncworldedit.core.command.tool.brush.HeightBrush)1 ImageBrush (com.fastasyncworldedit.core.command.tool.brush.ImageBrush)1 LayerBrush (com.fastasyncworldedit.core.command.tool.brush.LayerBrush)1 LineBrush (com.fastasyncworldedit.core.command.tool.brush.LineBrush)1 RaiseBrush (com.fastasyncworldedit.core.command.tool.brush.RaiseBrush)1