Search in sources :

Example 1 with BlockTool

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

Aggregations

LocalSession (com.sk89q.worldedit.LocalSession)1 BlockTool (com.sk89q.worldedit.command.tool.BlockTool)1 BrushTool (com.sk89q.worldedit.command.tool.BrushTool)1 DoubleActionBlockTool (com.sk89q.worldedit.command.tool.DoubleActionBlockTool)1 DoubleActionTraceTool (com.sk89q.worldedit.command.tool.DoubleActionTraceTool)1 Tool (com.sk89q.worldedit.command.tool.Tool)1 TraceTool (com.sk89q.worldedit.command.tool.TraceTool)1 Player (com.sk89q.worldedit.entity.Player)1 Location (com.sk89q.worldedit.util.Location)1 Subscribe (com.sk89q.worldedit.util.eventbus.Subscribe)1