Search in sources :

Example 1 with DoubleActionTraceTool

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

Aggregations

FaweException (com.fastasyncworldedit.core.internal.exception.FaweException)1 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 Subscribe (com.sk89q.worldedit.util.eventbus.Subscribe)1