Java Code Examples for com.sk89q.worldedit.LocalSession#getBrushTool()

The following examples show how to use com.sk89q.worldedit.LocalSession#getBrushTool() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrushOptionsCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"primary"},
        usage = "[brush-arguments]",
        desc = "Set the right click brush",
        help = "Set the right click brush",
        min = 1
)
public void primary(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    BaseBlock item = player.getBlockInHand();
    BrushTool tool = session.getBrushTool(player, false);
    session.setTool(item, null, player);
    String cmd = "brush " + args.getJoinedStrings(0);
    CommandEvent event = new CommandEvent(player, cmd);
    CommandManager.getInstance().handleCommandOnCurrentThread(event);
    BrushTool newTool = session.getBrushTool(item, player, false);
    if (newTool != null && tool != null) {
        newTool.setSecondary(tool.getSecondary());
    }
}
 
Example 2
Source File: BrushOptionsCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"secondary"},
        usage = "[brush-arguments]",
        desc = "Set the left click brush",
        help = "Set the left click brush",
        min = 1
)
public void secondary(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    BaseBlock item = player.getBlockInHand();
    BrushTool tool = session.getBrushTool(player, false);
    session.setTool(item, null, player);
    String cmd = "brush " + args.getJoinedStrings(0);
    CommandEvent event = new CommandEvent(player, cmd);
    CommandManager.getInstance().handleCommandOnCurrentThread(event);
    BrushTool newTool = session.getBrushTool(item, player, false);
    if (newTool != null && tool != null) {
        newTool.setPrimary(tool.getPrimary());
    }
}
 
Example 3
Source File: BrushOptionsCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"visualize", "visual", "vis"},
        usage = "[mode=0]",
        desc = "Toggle between different visualization modes",
        help = "Toggle between different visualization modes\n" +
                "0 = No visualization\n" +
                "1 = Single block at target position\n" +
                "2 = Glass showing what blocks will be changed",
        min = 0,
        max = 1
)
public void visual(Player player, LocalSession session, @Range(min = 0, max = 2)int mode) throws WorldEditException {
    BrushTool tool = session.getBrushTool(player, false);
    if (tool == null) {
        BBC.BRUSH_NONE.send(player);
        return;
    }
    VisualMode[] modes = VisualMode.values();
    VisualMode newMode = modes[MathMan.wrap(mode, 0, modes.length - 1)];
    tool.setVisualMode(player, newMode);
    BBC.BRUSH_VISUAL_MODE_SET.send(player, newMode);
}
 
Example 4
Source File: BrushOptionsCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"target", "tar"},
        usage = "[mode]",
        desc = "Toggle between different target modes",
        min = 0,
        max = 1
)
public void target(Player player, LocalSession session, @Optional("0") int mode) throws WorldEditException {
    BrushTool tool = session.getBrushTool(player, false);
    if (tool == null) {
        BBC.BRUSH_NONE.send(player);
        return;
    }
    TargetMode[] modes = TargetMode.values();
    TargetMode newMode = modes[MathMan.wrap(mode, 0, modes.length - 1)];
    tool.setTargetMode(newMode);
    BBC.BRUSH_TARGET_MODE_SET.send(player, newMode);
}
 
Example 5
Source File: BrushOptionsCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"targetmask", "tarmask", "tm"},
        usage = "[mask]",
        desc = "Set the targeting mask",
        min = 1,
        max = -1
)
public void targetMask(Player player, EditSession editSession, LocalSession session, CommandContext context) throws WorldEditException {
    BrushTool tool = session.getBrushTool(player, false);
    if (tool == null) {
        BBC.BRUSH_NONE.send(player);
        return;
    }
    ParserContext parserContext = new ParserContext();
    parserContext.setActor(player);
    parserContext.setWorld(player.getWorld());
    parserContext.setSession(session);
    parserContext.setExtent(editSession);
    Mask mask = worldEdit.getMaskFactory().parseFromInput(context.getJoinedStrings(0), parserContext);
    tool.setTargetMask(mask);
    BBC.BRUSH_TARGET_MASK_SET.send(player, context.getJoinedStrings(0));
}
 
Example 6
Source File: BrushOptionsCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"targetoffset", "to"},
        usage = "[mask]",
        desc = "Set the targeting mask",
        min = 1,
        max = -1
)
public void targetOffset(Player player, EditSession editSession, LocalSession session, int offset) throws WorldEditException {
    BrushTool tool = session.getBrushTool(player, false);
    if (tool == null) {
        BBC.BRUSH_NONE.send(player);
        return;
    }
    tool.setTargetOffset(offset);
    BBC.BRUSH_TARGET_OFFSET_SET.send(player, offset);
}
 
Example 7
Source File: BrushOptionsCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"scroll"},
        usage = "[none|clipboard|mask|pattern|range|size|visual|target|targetoffset]",
        desc = "Toggle between different target modes",
        min = 1,
        max = -1
)
public void scroll(Player player, EditSession editSession, LocalSession session, @Optional @Switch('h') boolean offHand, CommandContext args) throws WorldEditException {
    BrushTool bt = session.getBrushTool(player, false);
    if (bt == null) {
        BBC.BRUSH_NONE.send(player);
        return;
    }
    BrushSettings settings = offHand ? bt.getOffHand() : bt.getContext();
    ScrollAction action = ScrollAction.fromArguments(bt, player, session, args.getJoinedStrings(0), true);
    settings.setScrollAction(action);
    if (args.getString(0).equalsIgnoreCase("none")) {
        BBC.BRUSH_SCROLL_ACTION_UNSET.send(player);
    } else if (action != null) {
        String full = args.getJoinedStrings(0);
        settings.addSetting(BrushSettings.SettingType.SCROLL_ACTION, full);
        BBC.BRUSH_SCROLL_ACTION_SET.send(player, full);
    }
    bt.update();
}
 
Example 8
Source File: BrushOptionsCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"mat", "material"},
        usage = "[pattern]",
        desc = "Set the brush material",
        min = 1,
        max = 1
)
@CommandPermissions("worldedit.brush.options.material")
public void material(Player player, EditSession editSession, LocalSession session, Pattern pattern, @Switch('h') boolean offHand, CommandContext context) throws WorldEditException {
    BrushTool tool = session.getBrushTool(player, false);
    if (tool == null) {
        player.print(BBC.getPrefix() + BBC.BRUSH_NONE.f());
        return;
    }
    if (context.argsLength() == 0) {
        BBC.BRUSH_TRANSFORM_DISABLED.send(player);
        tool.setFill(null);
        return;
    }
    BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
    settings.setFill(pattern);
    settings.addSetting(BrushSettings.SettingType.FILL, context.getString(context.argsLength() - 1));
    tool.update();
    BBC.BRUSH_MATERIAL.send(player);
}
 
Example 9
Source File: BrushOptionsCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"size"},
        usage = "[pattern]",
        desc = "Set the brush size",
        min = 1,
        max = 1
)
@CommandPermissions("worldedit.brush.options.size")
public void size(Player player, LocalSession session, Expression radius, @Switch('h') boolean offHand) throws WorldEditException {
    BrushCommands.checkMaxBrushRadius(radius);
    BrushTool tool = session.getBrushTool(player, false);
    if (tool == null) {
        player.print(BBC.getPrefix() + BBC.BRUSH_NONE.f());
        return;
    }
    BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
    settings.setSize(radius);
    tool.update();
    BBC.BRUSH_SIZE.send(player);
}
 
Example 10
Source File: BrushProcessor.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public BrushSettings set(LocalSession session, CommandContext context, Brush brush) throws InvalidToolBindException {
    CommandLocals locals = context.getLocals();
    Actor actor = locals.get(Actor.class);
    BrushSettings bs = new BrushSettings();

    BrushTool tool = session.getBrushTool((Player) actor, false);
    if (tool != null) {
        BrushSettings currentContext = tool.getContext();
        if (currentContext != null) {
            Brush currentBrush = currentContext.getBrush();
            if (currentBrush != null && currentBrush.getClass() == brush.getClass()) {
                bs = currentContext;
            }
        }
    }

    bs.addPermissions(getPermissions());

    if (locals != null) {
        String args = (String) locals.get("arguments");
        if (args != null) {
            bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1));
        }
    }
    return bs.setBrush(brush);
}
 
Example 11
Source File: BrushOptionsCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"smask", "/smask", "/sourcemask", "sourcemask"},
        usage = "[mask]",
        desc = "Set the brush source mask",
        help = "Set the brush source mask",
        min = 0,
        max = -1
)
@CommandPermissions({"worldedit.brush.options.mask", "worldedit.mask.brush"})
public void smask(Player player, LocalSession session, EditSession editSession, @Optional @Switch('h') boolean offHand, CommandContext context) throws WorldEditException {
    BrushTool tool = session.getBrushTool(player, false);
    if (tool == null) {
        player.print(BBC.getPrefix() + BBC.BRUSH_NONE.f());
        return;
    }
    if (context.argsLength() == 0) {
        BBC.BRUSH_SOURCE_MASK_DISABLED.send(player);
        tool.setSourceMask(null);
        return;
    }
    ParserContext parserContext = new ParserContext();
    parserContext.setActor(player);
    parserContext.setWorld(player.getWorld());
    parserContext.setSession(session);
    parserContext.setExtent(editSession);
    Mask mask = worldEdit.getMaskFactory().parseFromInput(context.getJoinedStrings(0), parserContext);
    BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
    settings.addSetting(BrushSettings.SettingType.SOURCE_MASK, context.getString(context.argsLength() - 1));
    settings.setSourceMask(mask);
    tool.update();
    BBC.BRUSH_SOURCE_MASK.send(player);
}
 
Example 12
Source File: BrushProcessor.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BrushSettings process(CommandLocals locals, BrushSettings settings) throws WorldEditException {
    Actor actor = locals.get(Actor.class);
    LocalSession session = worldEdit.getSessionManager().get(actor);
    session.setTool(null, (Player) actor);
    BrushTool tool = session.getBrushTool((Player) actor);
    if (tool != null) {
        tool.setPrimary(settings);
        tool.setSecondary(settings);
        BBC.BRUSH_EQUIPPED.send(actor, ((String) locals.get("arguments")).split(" ")[1]);
    }
    return null;
}