Search in sources :

Example 6 with BrushSettings

use of com.fastasyncworldedit.core.command.tool.brush.BrushSettings in project FastAsyncWorldEdit by IntellectualSites.

the class BrushCommands method set.

public BrushSettings set(InjectedValueAccess context, Brush brush, String permission) throws InvalidToolBindException {
    Player player = context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"));
    LocalSession session = player.getSession();
    BrushSettings bs = new BrushSettings();
    BrushTool tool = session.getBrushTool(player, false);
    if (tool != null) {
        BrushSettings currentContext = tool.getContext();
        if (currentContext != null) {
            Brush currentBrush = currentContext.getBrush();
            if (currentBrush != null && currentBrush.getClass() == brush.getClass()) {
                bs = currentContext;
            }
        }
    }
    Arguments arguments = context.injectedValue(Key.of(Arguments.class)).orElse(null);
    if (arguments != null) {
        String args = arguments.get();
        bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1));
    }
    bs.addPermission(permission);
    bs.setBrush(brush);
    return process(player, arguments, bs);
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) Player(com.sk89q.worldedit.entity.Player) LocalSession(com.sk89q.worldedit.LocalSession) Arguments(com.sk89q.worldedit.command.argument.Arguments) BrushSettings(com.fastasyncworldedit.core.command.tool.brush.BrushSettings) HollowSphereBrush(com.sk89q.worldedit.command.tool.brush.HollowSphereBrush) HeightBrush(com.fastasyncworldedit.core.command.tool.brush.HeightBrush) SphereBrush(com.sk89q.worldedit.command.tool.brush.SphereBrush) ScatterBrush(com.fastasyncworldedit.core.command.tool.brush.ScatterBrush) CopyPastaBrush(com.fastasyncworldedit.core.command.tool.brush.CopyPastaBrush) RaiseBrush(com.fastasyncworldedit.core.command.tool.brush.RaiseBrush) SnowSmoothBrush(com.sk89q.worldedit.command.tool.brush.SnowSmoothBrush) ClipboardBrush(com.sk89q.worldedit.command.tool.brush.ClipboardBrush) GravityBrush(com.sk89q.worldedit.command.tool.brush.GravityBrush) FlattenBrush(com.fastasyncworldedit.core.command.tool.brush.FlattenBrush) BlobBrush(com.fastasyncworldedit.core.command.tool.brush.BlobBrush) SweepBrush(com.fastasyncworldedit.core.command.tool.sweep.SweepBrush) CircleBrush(com.fastasyncworldedit.core.command.tool.brush.CircleBrush) SplatterBrush(com.fastasyncworldedit.core.command.tool.brush.SplatterBrush) CatenaryBrush(com.fastasyncworldedit.core.command.tool.brush.CatenaryBrush) RecurseBrush(com.fastasyncworldedit.core.command.tool.brush.RecurseBrush) CylinderBrush(com.sk89q.worldedit.command.tool.brush.CylinderBrush) ScatterOverlayBrush(com.fastasyncworldedit.core.command.tool.brush.ScatterOverlayBrush) StencilBrush(com.fastasyncworldedit.core.command.tool.brush.StencilBrush) LineBrush(com.fastasyncworldedit.core.command.tool.brush.LineBrush) Brush(com.sk89q.worldedit.command.tool.brush.Brush) ButcherBrush(com.sk89q.worldedit.command.tool.brush.ButcherBrush) ErodeBrush(com.fastasyncworldedit.core.command.tool.brush.ErodeBrush) SurfaceSphereBrush(com.fastasyncworldedit.core.command.tool.brush.SurfaceSphereBrush) SplineBrush(com.fastasyncworldedit.core.command.tool.brush.SplineBrush) HollowCylinderBrush(com.sk89q.worldedit.command.tool.brush.HollowCylinderBrush) SmoothBrush(com.sk89q.worldedit.command.tool.brush.SmoothBrush) LayerBrush(com.fastasyncworldedit.core.command.tool.brush.LayerBrush) CommandBrush(com.fastasyncworldedit.core.command.tool.brush.CommandBrush) ImageBrush(com.fastasyncworldedit.core.command.tool.brush.ImageBrush) ShatterBrush(com.fastasyncworldedit.core.command.tool.brush.ShatterBrush) OperationFactoryBrush(com.sk89q.worldedit.command.tool.brush.OperationFactoryBrush)

Example 7 with BrushSettings

use of com.fastasyncworldedit.core.command.tool.brush.BrushSettings in project FastAsyncWorldEdit by IntellectualSites.

the class ToolUtilCommands method transform.

@Command(name = "transform", aliases = { "/transform" }, desc = "Set the brush transform")
@CommandPermissions({ "worldedit.brush.options.transform", "worldedit.transform.brush" })
public void transform(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The transform", def = "") ResettableExtent transform, @Switch(name = 'h', desc = "Whether the offhand should be considered or not") boolean offHand, Arguments arguments) throws WorldEditException {
    BrushTool tool = session.getBrushTool(player, false);
    if (tool == null) {
        player.print(Caption.of("fawe.worldedit.brush.brush.none"));
        return;
    }
    if (transform == null) {
        player.print(Caption.of("fawe.worldedit.brush.brush.transform.disabled"));
        tool.setTransform(null);
        return;
    }
    BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
    String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
    settings.addSetting(BrushSettings.SettingType.TRANSFORM, lastArg);
    settings.setTransform(transform);
    tool.update();
    player.print(Caption.of("fawe.worldedit.brush.brush.transform"));
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) BrushSettings(com.fastasyncworldedit.core.command.tool.brush.BrushSettings) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 8 with BrushSettings

use of com.fastasyncworldedit.core.command.tool.brush.BrushSettings in project FastAsyncWorldEdit by IntellectualSites.

the class ToolUtilCommands method mask.

// FAWE start - destination mask > mask
@Command(name = "mask", aliases = "/mask", desc = "Set the brush destination mask")
@CommandPermissions({ "worldedit.brush.options.mask", "worldedit.mask.brush" })
public void mask(Player player, LocalSession session, @Switch(name = 'h', desc = "Whether the offhand should be considered or not") boolean offHand, @Arg(desc = "The destination mask", def = "") Mask maskOpt, Arguments arguments) throws WorldEditException {
    BrushTool tool = session.getBrushTool(player, false);
    if (tool == null) {
        player.print(Caption.of("fawe.worldedit.brush.brush.none"));
        return;
    }
    if (maskOpt == null) {
        player.print(Caption.of("worldedit.tool.mask.disabled"));
        tool.setMask(null);
    } else {
        BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
        String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
        settings.addSetting(BrushSettings.SettingType.MASK, lastArg);
        settings.setMask(maskOpt);
        tool.update();
        player.print(Caption.of("worldedit.tool.mask.set"));
    }
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) BrushSettings(com.fastasyncworldedit.core.command.tool.brush.BrushSettings) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 9 with BrushSettings

use of com.fastasyncworldedit.core.command.tool.brush.BrushSettings in project FastAsyncWorldEdit by IntellectualSites.

the class BrushTool method setBrush.

// FAWE end
/**
 * Set the brush.
 *
 * @param brush      the brush
 * @param permission the permission
 */
public void setBrush(Brush brush, String permission) {
    // FAWE start - We use our own logic
    BrushSettings current = getContext();
    current.clearPerms();
    current.setBrush(brush);
    current.addPermission(permission);
    update();
// FAWE end
}
Also used : BrushSettings(com.fastasyncworldedit.core.command.tool.brush.BrushSettings)

Example 10 with BrushSettings

use of com.fastasyncworldedit.core.command.tool.brush.BrushSettings 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

BrushSettings (com.fastasyncworldedit.core.command.tool.brush.BrushSettings)10 BrushTool (com.sk89q.worldedit.command.tool.BrushTool)6 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)6 Command (org.enginehub.piston.annotation.Command)6 Scroll (com.fastasyncworldedit.core.command.tool.scroll.Scroll)2 Brush (com.sk89q.worldedit.command.tool.brush.Brush)2 CylinderBrush (com.sk89q.worldedit.command.tool.brush.CylinderBrush)2 HollowCylinderBrush (com.sk89q.worldedit.command.tool.brush.HollowCylinderBrush)2 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