Search in sources :

Example 16 with WorldEditException

use of com.sk89q.worldedit.WorldEditException in project BetonQuest by BetonQuest.

the class PasteSchematicEvent method execute.

@Override
protected Void execute(final String playerID) throws QuestRuntimeException {
    try {
        final ClipboardFormat format = ClipboardFormats.findByFile(file);
        if (format == null) {
            throw new IOException("Unknown Schematic Format");
        }
        final Clipboard clipboard;
        try (ClipboardReader reader = format.getReader(Files.newInputStream(file.toPath()))) {
            clipboard = reader.read();
        }
        final Location location = loc.getLocation(playerID);
        try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(location.getWorld()), -1)) {
            final Operation operation = new ClipboardHolder(clipboard).createPaste(editSession).to(BukkitAdapter.asBlockVector(location)).ignoreAirBlocks(noAir).build();
            Operations.complete(operation);
        }
    } catch (IOException | WorldEditException e) {
        LOG.warn(instruction.getPackage(), "Error while pasting a schematic: " + e.getMessage(), e);
    }
    return null;
}
Also used : ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) IOException(java.io.IOException) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) EditSession(com.sk89q.worldedit.EditSession) Operation(com.sk89q.worldedit.function.operation.Operation) ClipboardReader(com.sk89q.worldedit.extent.clipboard.io.ClipboardReader) WorldEditException(com.sk89q.worldedit.WorldEditException) ClipboardFormat(com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat) CompoundLocation(org.betonquest.betonquest.utils.location.CompoundLocation) Location(org.bukkit.Location)

Example 17 with WorldEditException

use of com.sk89q.worldedit.WorldEditException in project buildinggame by stefvanschie.

the class WorldEditBoundaryAssertion method onEditSession.

/**
 * Cancels any edits being made for blocks outside the plot the actor is (possibly) on.
 *
 * @param event the event fired when a session is being edited
 * @since 5.8.0
 */
@Subscribe
public void onEditSession(EditSessionEvent event) {
    if (event.getActor() == null || !event.getActor().isPlayer())
        return;
    var player = Bukkit.getPlayer(event.getActor().getUniqueId());
    var arena = ArenaManager.getInstance().getArena(player);
    // don't do anything if the player isn't in an arena
    if (arena == null)
        return;
    event.setExtent(new AbstractDelegateExtent(event.getExtent()) {

        @Override
        public boolean setBlock(BlockVector3 vector, BlockStateHolder block) throws WorldEditException {
            var world = Bukkit.getWorld(event.getWorld().getName());
            var loc = new Location(world, vector.getX(), vector.getY(), vector.getZ());
            if (!arena.getPlot(player).getBoundary().isInside(loc)) {
                return false;
            }
            return super.setBlock(vector, block);
        }
    });
}
Also used : AbstractDelegateExtent(com.sk89q.worldedit.extent.AbstractDelegateExtent) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) BlockVector3(com.sk89q.worldedit.math.BlockVector3) WorldEditException(com.sk89q.worldedit.WorldEditException) Location(org.bukkit.Location) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 18 with WorldEditException

use of com.sk89q.worldedit.WorldEditException in project WorldGuard by EngineHub.

the class SpongeUtil method clearSpongeWater.

/**
 * Remove water around a sponge.
 *
 * @param world The world the sponge is in
 * @param ox The x coordinate of the 'sponge' block
 * @param oy The y coordinate of the 'sponge' block
 * @param oz The z coordinate of the 'sponge' block
 */
public static void clearSpongeWater(World world, int ox, int oy, int oz) {
    WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
    for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
        for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
            for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
                BlockVector3 vector = BlockVector3.at(ox + cx, oy + cy, oz + cz);
                BaseBlock block = world.getFullBlock(vector);
                BlockType blockType = block.getBlockType();
                if (isReplacable(blockType)) {
                    try {
                        world.setBlock(vector, BlockTypes.AIR.getDefaultState());
                    } catch (WorldEditException e) {
                        e.printStackTrace();
                    }
                } else {
                    @SuppressWarnings("unchecked") Property<Object> waterloggedProp = waterloggable.computeIfAbsent(blockType, (bt -> (Property<Object>) bt.getPropertyMap().get("waterlogged")));
                    if (waterloggedProp != null) {
                        try {
                            world.setBlock(vector, block.with(waterloggedProp, false));
                        } catch (WorldEditException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
Also used : Property(com.sk89q.worldedit.registry.state.Property) WorldEditException(com.sk89q.worldedit.WorldEditException) BlockTypes(com.sk89q.worldedit.world.block.BlockTypes) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockType(com.sk89q.worldedit.world.block.BlockType) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) WorldGuard(com.sk89q.worldguard.WorldGuard) Map(java.util.Map) World(com.sk89q.worldedit.world.World) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Maps(com.google.common.collect.Maps) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BlockType(com.sk89q.worldedit.world.block.BlockType) BlockVector3(com.sk89q.worldedit.math.BlockVector3) WorldEditException(com.sk89q.worldedit.WorldEditException) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Property(com.sk89q.worldedit.registry.state.Property)

Aggregations

WorldEditException (com.sk89q.worldedit.WorldEditException)18 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)10 EditSession (com.sk89q.worldedit.EditSession)8 Operation (com.sk89q.worldedit.function.operation.Operation)8 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)8 IOException (java.io.IOException)8 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)7 Region (com.sk89q.worldedit.regions.Region)5 World (com.sk89q.worldedit.world.World)5 ClipboardReader (com.sk89q.worldedit.extent.clipboard.io.ClipboardReader)4 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)3 Actor (com.sk89q.worldedit.extension.platform.Actor)3 ClipboardFormat (com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat)3 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)3 FileInputStream (java.io.FileInputStream)3 Location (org.bukkit.Location)3 Caption (com.fastasyncworldedit.core.configuration.Caption)2 ByteArrayTag (com.sk89q.jnbt.ByteArrayTag)2 CompoundTag (com.sk89q.jnbt.CompoundTag)2 IntTag (com.sk89q.jnbt.IntTag)2