Java Code Examples for com.sk89q.worldedit.WorldEditException

The following examples show how to use com.sk89q.worldedit.WorldEditException. These examples are extracted from open source projects. 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
@Command(
            aliases = {"/listbrush"},
            desc = "List saved brushes",
            usage = "[mine|<filter>] [page=1]",
            min = 0,
            max = -1,
            flags = "dnp",
            help = "List all brushes in the brush directory\n" +
                    " -p <page> prints the requested page\n"
    )
    @CommandPermissions("worldedit.brush.list")
    public void list(Actor actor, CommandContext args, @Switch('p') @Optional("1") int page) throws WorldEditException {
        String baseCmd = Commands.getAlias(BrushCommands.class, "brush") + " " + Commands.getAlias(BrushOptionsCommands.class, "loadbrush");
        File dir = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
        UtilityCommands.list(dir, actor, args, page, null, true, baseCmd);
//                new RunnableVal2<Message, String[]>() {
//            @Override
//            public void run(Message msg, String[] info) {
//
//            }
//        });
    }
 
Example 2
@Command(
        aliases = {"/hpos2"},
        usage = "",
        desc = "Set position 2 to targeted block",
        min = 0,
        max = 0
)
@CommandPermissions("worldedit.selection.hpos")
public void hpos2(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    Vector pos = player.getBlockTrace(300);

    if (pos != null) {
        if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos, ActorSelectorLimits.forActor(player))) {
            BBC.SELECTOR_ALREADY_SET.send(player);
            return;
        }

        session.getRegionSelector(player.getWorld())
                .explainSecondarySelection(player, session, pos);
    } else {
        player.printError("No block in sight!");
    }
}
 
Example 3
@Override
public void regenerate(Floor floor, EditSession session, RegenerationCause cause) {
	Clipboard clipboard = floor.getClipboard();
	
	Region region = clipboard.getRegion();
	World world = region.getWorld();
	WorldData data = world.getWorldData();
	
	ClipboardHolder holder = new ClipboardHolder(clipboard, data);
	
	Operation pasteOperation = holder.createPaste(session, data)
			.to(region.getMinimumPoint())
			.ignoreAirBlocks(true)
			.build();
	
	try {
		Operations.complete(pasteOperation);
	} catch (WorldEditException e) {
		throw new RuntimeException(e);
	}
}
 
Example 4
@Command(
        aliases = {"/hpos1"},
        usage = "",
        desc = "Set position 1 to targeted block",
        min = 0,
        max = 0
)
@CommandPermissions("worldedit.selection.hpos")
public void hpos1(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    Vector pos = player.getBlockTrace(300);

    if (pos != null) {
        if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos, ActorSelectorLimits.forActor(player))) {
            BBC.SELECTOR_ALREADY_SET.send(player);
            return;
        }

        session.getRegionSelector(player.getWorld())
                .explainPrimarySelection(player, session, pos);
    } else {
        player.printError("No block in sight!");
    }
}
 
Example 5
/**
 * Gets an {@link Pattern} from a {@link ArgumentStack}.
 *
 * @param context the context
 * @return a pattern
 * @throws ParameterException on error
 * @throws WorldEditException on error
 */
@BindingMatch(type = Pattern.class,
        behavior = BindingBehavior.CONSUMES,
        consumedCount = 1)
public Pattern getPattern(ArgumentStack context) throws ParameterException, WorldEditException {
    Actor actor = context.getContext().getLocals().get(Actor.class);
    ParserContext parserContext = new ParserContext();
    parserContext.setActor(context.getContext().getLocals().get(Actor.class));
    if (actor instanceof Entity) {
        Extent extent = ((Entity) actor).getExtent();
        if (extent instanceof World) {
            parserContext.setWorld((World) extent);
        }
    }
    parserContext.setSession(worldEdit.getSessionManager().get(actor));
    try {
        return worldEdit.getPatternFactory().parseFromInput(context.next(), parserContext);
    } catch (NoMatchException e) {
        throw new ParameterException(e.getMessage(), e);
    }
}
 
Example 6
@Command(
        aliases = {"threads"},
        usage = "",
        desc = "Print all thread stacks",
        min = 0,
        max = 0
)
@CommandPermissions("worldedit.threads")
public void threads(Actor actor) throws WorldEditException {
    Map<Thread, StackTraceElement[]> stacks = Thread.getAllStackTraces();
    for (Map.Entry<Thread, StackTraceElement[]> entry : stacks.entrySet()) {
        Thread thread = entry.getKey();
        actor.printDebug("--------------------------------------------------------------------------------------------");
        actor.printDebug("Thread: " + thread.getName() + " | Id: " + thread.getId() + " | Alive: " + thread.isAlive());
        for (StackTraceElement elem : entry.getValue()) {
            actor.printDebug(elem.toString());
        }
    }
}
 
Example 7
@Command(
        aliases = {"remap"},
        help = "Remap a clipboard between MCPE/PC values\n",
        desc = "Remap a clipboard between MCPE/PC values\n"
)
@Deprecated
@CommandPermissions({"worldedit.schematic.remap"})
public void remap(final Player player, final LocalSession session) throws WorldEditException {
    ClipboardRemapper remapper;
    if (Fawe.imp().getPlatform().equalsIgnoreCase("nukkit")) {
        remapper = new ClipboardRemapper(ClipboardRemapper.RemapPlatform.PC, ClipboardRemapper.RemapPlatform.PE);
    } else {
        remapper = new ClipboardRemapper(ClipboardRemapper.RemapPlatform.PE, ClipboardRemapper.RemapPlatform.PC);
    }

    for (Clipboard clip : session.getClipboard().getClipboards()) {
        remapper.apply(clip);
    }
    player.print(BBC.getPrefix() + "Remapped schematic");
}
 
Example 8
Source Project: FastAsyncWorldedit   Source File: MCAWorld.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean clearContainerBlockContents(Vector position) {
    BaseBlock block = extent.getLazyBlock(position);
    if (block.hasNbtData()) {
        Map<String, Tag> nbt = ReflectionUtils.getMap(block.getNbtData().getValue());
        if (nbt.containsKey("Items")) {
            nbt.put("Items", new ListTag(CompoundTag.class, new ArrayList<CompoundTag>()));
            try {
                extent.setBlock(position, block);
            } catch (WorldEditException e) {
                e.printStackTrace();
            }
        }
    }
    return true;
}
 
Example 9
@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 10
@Command(
        aliases = {"descend", "desc"},
        usage = "[# of floors]",
        desc = "Go down a floor",
        min = 0,
        max = 1
)
@CommandPermissions("worldedit.navigation.descend")
public void descend(Player player, @Optional("1") int levelsToDescend) throws WorldEditException {
    int descentLevels = 0;
    while (player.descendLevel()) {
        ++descentLevels;
        if (levelsToDescend == descentLevels) {
            break;
        }
    }
    if (descentLevels == 0) {
        BBC.DESCEND_FAIL.send(player);
    } else {
        if (descentLevels == 1) {
            BBC.DESCEND_SINGULAR.send(player);
        } else {
            BBC.DESCEND_PLURAL.send(player, descentLevels);
        }
    }
}
 
Example 11
@Command(
        aliases = {"up"},
        usage = "<number>",
        desc = "Go upwards some distance",
        flags = "fg",
        min = 1,
        max = 1
)
@CommandPermissions("worldedit.navigation.up")
@Logging(POSITION)
public void up(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    final int distance = args.getInteger(0);

    final boolean alwaysGlass = getAlwaysGlass(args);
    if (player.ascendUpwards(distance, alwaysGlass)) {
        BBC.WHOOSH.send(player);
    } else {
        BBC.UP_FAIL.send(player);
    }
}
 
Example 12
@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 13
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
    World world = (World) clicked.getExtent();

    int initialType = world.getBlockType(clicked.toVector());

    if (initialType == BlockID.AIR) {
        return true;
    }

    if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) {
        return true;
    }

    EditSession editSession = session.createEditSession(player);

    try {
        recurse(server, editSession, world, clicked.toVector().toBlockVector(),
                clicked.toVector(), range, initialType, new HashSet<BlockVector>());
    } catch (WorldEditException e) {
        throw new RuntimeException(e);
    }
    editSession.flushQueue();
    session.remember(editSession);
    return true;
}
 
Example 14
@Command(
        aliases = {"/gmask", "gmask", "globalmask", "/globalmask"},
        usage = "[mask]",
        help = "The global destination mask applies to all edits you do and masks based on the destination blocks (i.e. the blocks in the world).",
        desc = "Set the global mask",
        min = 0,
        max = -1
)
@CommandPermissions({"worldedit.global-mask", "worldedit.mask.global"})
public void gmask(Player player, LocalSession session, EditSession editSession, @Optional CommandContext context) throws WorldEditException {
    if (context == null || context.argsLength() == 0) {
        session.setMask((Mask) null);
        BBC.MASK_DISABLED.send(player);
    } else {
        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);
        session.setMask(mask);
        BBC.MASK.send(player);
    }
}
 
Example 15
@Command(
        aliases = {"toggleeditwand"},
        usage = "",
        desc = "Toggle functionality of the edit wand",
        min = 0,
        max = 0
)
@CommandPermissions("worldedit.wand.toggle")
public void toggleWand(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    session.setToolControl(!session.isToolControlEnabled());

    if (session.isToolControlEnabled()) {
        BBC.SELECTION_WAND_ENABLE.m().send(player);
    } else {
        BBC.SELECTION_WAND_DISABLE.send(player);
    }
}
 
Example 16
@Override
public boolean setBlock(final Vector location, final BaseBlock block) throws WorldEditException {
    if (super.setBlock(location, block)) {
        if (MemUtil.isMemoryLimited()) {
            if (this.player != null) {
                player.sendMessage(BBC.WORLDEDIT_CANCEL_REASON.format(BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY.s()));
                if (Perm.hasPermission(this.player, "worldedit.fast")) {
                    BBC.WORLDEDIT_OOM_ADMIN.send(this.player);
                }
            }
            WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY);
            return false;
        }
        return true;
    }
    return false;
}
 
Example 17
@Override
public boolean setBlock(int x, int y, int z, BaseBlock block) throws WorldEditException {
    CompoundTag nbt = block.getNbtData();
    if (nbt != null) {
        if (!limit.MAX_BLOCKSTATES()) {
            WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_TILES);
            return false;
        } else {
            if (!limit.MAX_CHANGES()) {
                WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES);
                return false;
            }
            return extent.setBlock(x, y, z, block);
        }
    }
    if (!limit.MAX_CHANGES()) {
        WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES);
        return false;
    } else {
        return extent.setBlock(x, y, z, block);
    }
}
 
Example 18
/**
 * Gets an {@link BaseBlock} from a {@link ArgumentStack}.
 *
 * @param context the context
 * @return a pattern
 * @throws ParameterException on error
 * @throws WorldEditException on error
 */
@BindingMatch(type = BaseBlock.class,
        behavior = BindingBehavior.CONSUMES,
        consumedCount = 1)
public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException {
    Actor actor = context.getContext().getLocals().get(Actor.class);
    ParserContext parserContext = new ParserContext();
    parserContext.setActor(context.getContext().getLocals().get(Actor.class));
    if (actor instanceof Entity) {
        Extent extent = ((Entity) actor).getExtent();
        if (extent instanceof World) {
            parserContext.setWorld((World) extent);
        }
    }
    parserContext.setSession(worldEdit.getSessionManager().get(actor));
    try {
        return worldEdit.getBlockFactory().parseFromInput(context.next(), parserContext);
    } catch (NoMatchException e) {
        throw new ParameterException(e.getMessage(), e);
    }
}
 
Example 19
@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 20
@Command(
        aliases = {"update"},
        usage = "",
        desc = "Update the plugin",
        min = 0,
        max = 0
)
public void update(FawePlayer fp) throws WorldEditException {
    if (Fawe.get().getUpdater().installUpdate(fp)) {
        TaskManager.IMP.sync(() -> {
            fp.executeCommand("restart");
            return null;
        });
        fp.sendMessage(BBC.getPrefix() + "Please restart to finish installing the update");
    } else {
        fp.sendMessage(BBC.getPrefix() + "No update is pending");
    }
}
 
Example 21
/**
 * Gets an {@link Mask} from a {@link ArgumentStack}.
 *
 * @param context the context
 * @return a pattern
 * @throws ParameterException on error
 * @throws WorldEditException on error
 */
@BindingMatch(type = Mask.class,
        behavior = BindingBehavior.CONSUMES,
        consumedCount = 1)
public Mask getMask(ArgumentStack context) throws ParameterException, WorldEditException {
    Actor actor = context.getContext().getLocals().get(Actor.class);
    ParserContext parserContext = new ParserContext();
    parserContext.setActor(context.getContext().getLocals().get(Actor.class));
    if (actor instanceof Entity) {
        Extent extent = ((Entity) actor).getExtent();
        if (extent instanceof World) {
            parserContext.setWorld((World) extent);
        }
    }
    parserContext.setSession(worldEdit.getSessionManager().get(actor));
    try {
        return worldEdit.getMaskFactory().parseFromInput(context.next(), parserContext);
    } catch (NoMatchException e) {
        throw new ParameterException(e.getMessage(), e);
    }
}
 
Example 22
@Override
public boolean setBlock(int x, int y, int z, BaseBlock block) throws WorldEditException {
    BaseBlock previous = super.getLazyBlock(x, y, z);
    int cx = x >> 4;
    int cz = z >> 4;
    long chunkPair = MathMan.pairInt(cx, cz);
    VisualChunk chunk = chunks.get(chunkPair);
    if (previous.equals(block)) {
        if (chunk != null) {
            chunk.unset(x, y, z);
        }
        return false;
    } else {
        if (chunk == null) {
            chunk = new VisualChunk(cx, cz);
            chunks.put(chunkPair, chunk);
        }
        chunk.setBlock(x, y, z, block.getId(), block.getData());
        return true;
    }
}
 
Example 23
Source Project: WorldGuardExtraFlagsPlugin   Source File: WorldEditFlagHandler.java    License: MIT License 5 votes vote down vote up
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException
{
	ApplicableRegionSet regions = WorldGuard.getInstance().getPlatform().getRegionContainer().get(this.weWorld).getApplicableRegions(location);

	State state = WorldGuardUtils.queryState(this.player, this.world, regions.getRegions(), Flags.WORLDEDIT);
	if (state != State.DENY)
	{
		return super.setBlock(location, block);
	}
	
	return false;
}
 
Example 24
@Command(
        aliases = {"farwand"},
        usage = "",
        desc = "Wand at a distance tool",
        min = 0,
        max = 0
)
@CommandPermissions("worldedit.tool.farwand")
public void farwand(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    session.setTool(new DistanceWand(), player);
    BBC.TOOL_FARWAND.send(player, ItemType.toHeldName(player.getItemInHand()));
}
 
Example 25
@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 26
@Override
public void perform(Block block) {
    mutable.setComponents(block.getX(), block.getY(), block.getZ());
    try {
        pattern.apply(extent, mutable, mutable);
    } catch (WorldEditException e) {
        throw new RuntimeException(e);
    }
}
 
Example 27
@Command(
        aliases = {"/tips", "tips"},
        desc = "Toggle FAWE tips"
)
public void tips(Player player, LocalSession session) throws WorldEditException {
    FawePlayer<Object> fp = FawePlayer.wrap(player);
    if (fp.toggle("fawe.tips")) {
        BBC.WORLDEDIT_TOGGLE_TIPS_ON.send(player);
    } else {
        BBC.WORLDEDIT_TOGGLE_TIPS_OFF.send(player);
    }
}
 
Example 28
@Command(
        aliases = {"reload"},
        usage = "",
        desc = "Reload configuration",
        min = 0,
        max = 0
)
@CommandPermissions("worldedit.reload")
public void reload(Actor actor) throws WorldEditException {
    we.getServer().reload();
    we.getEventBus().post(new ConfigurationLoadEvent(we.getPlatformManager().queryCapability(Capability.CONFIGURATION).getConfiguration()));
    Fawe.get().setupConfigs();
    actor.print(BBC.getPrefix() + "Reloaded WorldEdit " + we.getVersion() + " and FAWE (" + Fawe.get().getVersion() + ")");
}
 
Example 29
@Override
public boolean apply(Vector position, int depth) throws WorldEditException {
    if (depth == 0) {
        if (function.apply(position)) {
            affected++;
        }
    }
    return false;
}
 
Example 30
@Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
    BaseBlock block = extent.getBlock(getPosition);
    TextureUtil util = holder.getTextureUtil();
    int currentColor = util.getColor(block);
    if (currentColor == 0) return false;
    int newColor = util.averageColor(currentColor, color);
    BaseBlock newBlock = util.getNearestBlock(newColor);
    if (newBlock.equals(block)) return false;
    return extent.setBlock(setPosition, newBlock);
}