Search in sources :

Example 11 with ResettableExtent

use of com.fastasyncworldedit.core.extent.ResettableExtent in project FastAsyncWorldEdit by IntellectualSites.

the class BrushTool method act.

public boolean act(BrushAction action, Player player, LocalSession session) {
    switch(action) {
        case PRIMARY:
            setContext(primary);
            break;
        case SECONDARY:
            setContext(secondary);
            break;
        default:
            throw new IllegalStateException("Unexpected value: " + action);
    }
    BrushSettings current = getContext();
    Brush brush = current.getBrush();
    if (brush == null) {
        return false;
    }
    if (!current.canUse(player)) {
        player.print(Caption.of("fawe.error.no-perm", StringMan.join(current.getPermissions(), ",")));
        return false;
    }
    try (EditSession editSession = session.createEditSession(player, current.toString())) {
        Location target = player.getBlockTrace(getRange(), true, traceMask);
        if (target == null) {
            editSession.cancel();
            player.print(Caption.of("worldedit.tool.no-block"));
            return true;
        }
        BlockBag bag = session.getBlockBag(player);
        Request.request().setEditSession(editSession);
        Mask mask = current.getMask();
        if (mask != null) {
            Mask existingMask = editSession.getMask();
            if (existingMask == null) {
                editSession.setMask(mask);
            } else if (existingMask instanceof MaskIntersection) {
                ((MaskIntersection) existingMask).add(mask);
            } else {
                MaskIntersection newMask = new MaskIntersection(existingMask);
                newMask.add(mask);
                editSession.setMask(newMask);
            }
        }
        Mask sourceMask = current.getSourceMask();
        if (sourceMask != null) {
            editSession.addSourceMask(sourceMask);
        }
        ResettableExtent transform = current.getTransform();
        if (transform != null) {
            editSession.addTransform(transform);
        }
        try {
            new PatternTraverser(current).reset(editSession);
            double size = current.getSize();
            WorldEdit.getInstance().checkMaxBrushRadius(size);
            brush.build(editSession, target.toBlockPoint(), current.getMaterial(), size);
        } catch (MaxChangedBlocksException e) {
            player.print(Caption.of("worldedit.tool.max-block-changes"));
        } finally {
            session.remember(editSession);
            if (bag != null) {
                bag.flushChanges();
            }
        }
    } finally {
        Request.reset();
    }
    return true;
}
Also used : MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) SolidBlockMask(com.sk89q.worldedit.function.mask.SolidBlockMask) Mask(com.sk89q.worldedit.function.mask.Mask) PatternTraverser(com.fastasyncworldedit.core.function.pattern.PatternTraverser) EditSession(com.sk89q.worldedit.EditSession) BrushSettings(com.fastasyncworldedit.core.command.tool.brush.BrushSettings) Brush(com.sk89q.worldedit.command.tool.brush.Brush) ResettableExtent(com.fastasyncworldedit.core.extent.ResettableExtent) Location(com.sk89q.worldedit.util.Location) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Aggregations

ResettableExtent (com.fastasyncworldedit.core.extent.ResettableExtent)11 Extent (com.sk89q.worldedit.extent.Extent)5 RandomTransform (com.fastasyncworldedit.core.extent.transform.RandomTransform)2 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)2 NoMatchException (com.sk89q.worldedit.extension.input.NoMatchException)2 ArrayList (java.util.ArrayList)2 SuggestInputParseException (com.fastasyncworldedit.core.command.SuggestInputParseException)1 BrushSettings (com.fastasyncworldedit.core.command.tool.brush.BrushSettings)1 MultiTransform (com.fastasyncworldedit.core.extent.transform.MultiTransform)1 OffsetTransform (com.fastasyncworldedit.core.extent.transform.OffsetTransform)1 PatternTransform (com.fastasyncworldedit.core.extent.transform.PatternTransform)1 RandomOffsetTransform (com.fastasyncworldedit.core.extent.transform.RandomOffsetTransform)1 ScaleTransform (com.fastasyncworldedit.core.extent.transform.ScaleTransform)1 PatternTraverser (com.fastasyncworldedit.core.function.pattern.PatternTraverser)1 TrueRandom (com.fastasyncworldedit.core.math.random.TrueRandom)1 CommandLocals (com.sk89q.minecraft.util.commands.CommandLocals)1 EditSession (com.sk89q.worldedit.EditSession)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 Brush (com.sk89q.worldedit.command.tool.brush.Brush)1 Actor (com.sk89q.worldedit.extension.platform.Actor)1