Search in sources :

Example 16 with BrushTool

use of com.sk89q.worldedit.command.tool.BrushTool in project FastAsyncWorldEdit by IntellectualSites.

the class ToolUtilCommands method primary.

// FAWE start
@Command(name = "primary", aliases = { "/primary" }, desc = "Set the right click brush", descFooter = "Set the right click brush")
@CommandPermissions("worldedit.brush.primary")
public void primary(Player player, LocalSession session, @Arg(desc = "The brush command", variable = true) List<String> commandStr) throws WorldEditException {
    BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
    BrushTool tool = session.getBrushTool(player, false);
    session.setTool(item, null, player);
    String cmd = "brush " + StringMan.join(commandStr, " ");
    CommandEvent event = new CommandEvent(player, cmd);
    PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event);
    BrushTool newTool = session.getBrushTool(item, player, false);
    if (newTool != null && tool != null) {
        newTool.setSecondary(tool.getSecondary());
    }
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) CommandEvent(com.sk89q.worldedit.event.platform.CommandEvent) BaseItem(com.sk89q.worldedit.blocks.BaseItem) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 17 with BrushTool

use of com.sk89q.worldedit.command.tool.BrushTool in project FastAsyncWorldEdit by IntellectualSites.

the class BrushCache method getTool.

public static BrushTool getTool(Player player, LocalSession session, BaseItem item) {
    if (!item.hasNbtData()) {
        return null;
    }
    Object key = getKey(item);
    if (key == null) {
        return null;
    }
    BrushTool cached = brushCache.get(key);
    if (cached != null) {
        return cached;
    }
    CompoundTag nbt = item.getNbtData();
    if (nbt == null) {
        return null;
    }
    StringTag json = (StringTag) nbt.getValue().get("weBrushJson");
    /* if (json != null) {
            try {
                if (RECURSION.get() != null) return null;
                RECURSION.set(true);

                BrushTool tool = BrushTool.fromString(player, session, json.getValue());
                tool.setHolder(item);
                brushCache.put(key, tool);
                return tool;
            } catch (Exception throwable) {
                getLogger(BrushCache.class).debug("Invalid brush for " + player + " holding " + item.getType() + ": " + json.getValue(), throwable);
                item.setNbtData(null);
                brushCache.remove(key);
            } finally {
                RECURSION.remove();
            }
        }*/
    return null;
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) StringTag(com.sk89q.jnbt.StringTag) CompoundTag(com.sk89q.jnbt.CompoundTag)

Aggregations

BrushTool (com.sk89q.worldedit.command.tool.BrushTool)17 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)10 Command (org.enginehub.piston.annotation.Command)10 BrushSettings (com.fastasyncworldedit.core.command.tool.brush.BrushSettings)6 LocalSession (com.sk89q.worldedit.LocalSession)3 OperationFactoryBrush (com.sk89q.worldedit.command.tool.brush.OperationFactoryBrush)3 BaseItem (com.sk89q.worldedit.blocks.BaseItem)2 TargetMode (com.fastasyncworldedit.core.command.tool.TargetMode)1 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