Search in sources :

Example 1 with EditSession

use of com.sk89q.worldedit.EditSession in project Skree by Skelril.

the class SkyWarsInstance method showStartingPlatform.

private void showStartingPlatform(boolean present) {
    Location<World> platformLocation = startingLocation.add(0, -1, 0);
    EditSession editor = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new WorldResolver(getRegion().getExtent()).getWorldEditWorld(), -1);
    com.sk89q.worldedit.Vector origin = new com.sk89q.worldedit.Vector(platformLocation.getX(), platformLocation.getY(), platformLocation.getZ());
    BaseBlock targetBlock;
    if (present) {
        targetBlock = WorldEdit.getInstance().getBaseBlockFactory().getBaseBlock(BlockID.STAINED_GLASS, 15);
    } else {
        targetBlock = WorldEdit.getInstance().getBaseBlockFactory().getBaseBlock(BlockID.AIR);
    }
    try {
        editor.makeCylinder(origin, new SingleBlockPattern(targetBlock), 12, 1, true);
    } catch (MaxChangedBlocksException e) {
        e.printStackTrace();
    }
}
Also used : EditSession(com.sk89q.worldedit.EditSession) World(org.spongepowered.api.world.World) BaseBlock(com.sk89q.worldedit.blocks.BaseBlock) SingleBlockPattern(com.sk89q.worldedit.patterns.SingleBlockPattern) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 2 with EditSession

use of com.sk89q.worldedit.EditSession in project PixelsSkyblock by dudullle.

the class WEManager method count_entities.

public static List<? extends Entity> count_entities(World world, Location loc1, Location loc2) {
    EditSession es = new EditSessionBuilder(FaweAPI.getWorld("world")).fastmode(true).build();
    CuboidSelection cbs = new CuboidSelection(world, loc1, loc2);
    Region r = null;
    try {
        r = cbs.getRegionSelector().getRegion();
    } catch (IncompleteRegionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return es.getEntities(r);
}
Also used : CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) EditSessionBuilder(com.boydti.fawe.util.EditSessionBuilder) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession)

Example 3 with EditSession

use of com.sk89q.worldedit.EditSession in project PixelsSkyblock by dudullle.

the class WEManager method count.

public static List<Countable<Integer>> count(World world, Location loc1, Location loc2) {
    EditSession es = new EditSessionBuilder(FaweAPI.getWorld("world")).fastmode(true).build();
    CuboidSelection cbs = new CuboidSelection(world, loc1, loc2);
    Region r = null;
    try {
        r = cbs.getRegionSelector().getRegion();
    } catch (IncompleteRegionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return es.getBlockDistribution(r);
}
Also used : CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) EditSessionBuilder(com.boydti.fawe.util.EditSessionBuilder) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession)

Example 4 with EditSession

use of com.sk89q.worldedit.EditSession in project PixelsSkyblock by dudullle.

the class WEManager method pasteSchematics.

public static boolean pasteSchematics(World world, File file, Location origin) throws DataException, IOException, MaxChangedBlocksException {
    EditSession es = new EditSessionBuilder(FaweAPI.getWorld("world")).fastmode(true).build();
    MCEditSchematicFormat.getFormat(file).load(file).paste(es, new Vector(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ()), false);
    return true;
}
Also used : EditSessionBuilder(com.boydti.fawe.util.EditSessionBuilder) EditSession(com.sk89q.worldedit.EditSession) Vector(com.sk89q.worldedit.Vector)

Example 5 with EditSession

use of com.sk89q.worldedit.EditSession in project Skree by Skelril.

the class WEDecorator method pasteAt.

public <T> ZoneWorldBoundingBox pasteAt(WorldResolver world, Vector3i origin, String resourceName, Function<ZoneWorldBoundingBox, T> initMapper, Consumer<T> callback) {
    EditSession transaction = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world.getWorldEditWorld(), -1);
    transaction.setFastMode(true);
    transaction.getChangeSet().setRecordChanges(false);
    hashRefMap.computeIfAbsent(resourceName, (a) -> {
        HashRef ref = new HashRef();
        try {
            ref.holder = getHolder(resourceName, world.getWorldEditWorld().getWorldData());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ref;
    });
    HashRef ref = hashRefMap.get(resourceName);
    if (ref == null) {
        callback.accept(null);
        return null;
    }
    ++ref.refCount;
    Clipboard clipboard = ref.holder.getClipboard();
    Region clipReg = clipboard.getRegion();
    clipboard.setOrigin(clipReg.getMinimumPoint());
    Operation operation = ref.holder.createPaste(transaction, transaction.getWorld().getWorldData()).to(new Vector(origin.getX(), origin.getY(), origin.getZ())).build();
    Vector dimensions = clipboard.getDimensions();
    ZoneWorldBoundingBox region = new ZoneWorldBoundingBox(world.getSpongeWorld(), origin, new Vector3i(dimensions.getX(), dimensions.getY(), dimensions.getZ()));
    T returnVal = initMapper.apply(region);
    RunManager.runOperation(operation, () -> {
        RunManager.runOperation(transaction.commit(), () -> {
            region.getChunks().forEach(chunk -> {
                tf(chunk).resetRelightChecks();
                tf(chunk).generateSkylightMap();
                tf(chunk).checkLight();
            });
            callback.accept(returnVal);
            if (--ref.refCount == 0) {
                hashRefMap.remove(resourceName);
                System.gc();
            }
        });
    });
    return region;
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession) IOException(java.io.IOException) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) Operation(com.sk89q.worldedit.function.operation.Operation) Vector(com.sk89q.worldedit.Vector) ZoneWorldBoundingBox(com.skelril.skree.service.internal.zone.ZoneWorldBoundingBox)

Aggregations

EditSession (com.sk89q.worldedit.EditSession)14 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)7 Vector (com.sk89q.worldedit.Vector)7 Region (com.sk89q.worldedit.regions.Region)6 IOException (java.io.IOException)6 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)5 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)4 CuboidSelection (com.sk89q.worldedit.bukkit.selections.CuboidSelection)4 EditSessionBuilder (com.boydti.fawe.util.EditSessionBuilder)3 CuboidClipboard (com.sk89q.worldedit.CuboidClipboard)3 Vector3i (com.flowpowered.math.vector.Vector3i)2 DataException (com.sk89q.worldedit.data.DataException)2 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)2 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)2 ForwardExtentCopy (com.sk89q.worldedit.function.operation.ForwardExtentCopy)2 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 Closer (com.sk89q.worldedit.util.io.Closer)2 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 EditSessionFactory (com.sk89q.worldedit.EditSessionFactory)1