Search in sources :

Example 1 with BlockBag

use of com.sk89q.worldedit.extent.inventory.BlockBag in project FastAsyncWorldEdit by IntellectualSites.

the class LongRangeBuildTool method actSecondary.

@Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
    Location pos = getTargetFace(player);
    if (pos == null) {
        return false;
    }
    BlockBag bag = session.getBlockBag(player);
    try (EditSession editSession = session.createEditSession(player, "LongRangeBuildTool")) {
        try {
            BlockVector3 blockPoint = pos.toVector().toBlockPoint();
            BaseBlock applied = secondary.applyBlock(blockPoint);
            if (applied.getBlockType().getMaterial().isAir()) {
                editSession.setBlock(blockPoint, secondary);
            } else {
                editSession.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), secondary);
            }
        } catch (MaxChangedBlocksException ignored) {
        } finally {
            session.remember(editSession);
        }
    } finally {
        if (bag != null) {
            bag.flushChanges();
        }
    }
    return true;
}
Also used : BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) EditSession(com.sk89q.worldedit.EditSession) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Location(com.sk89q.worldedit.util.Location) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 2 with BlockBag

use of com.sk89q.worldedit.extent.inventory.BlockBag in project FastAsyncWorldEdit by IntellectualSites.

the class LongRangeBuildTool method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
    Location pos = getTargetFace(player);
    if (pos == null) {
        return false;
    }
    BlockBag bag = session.getBlockBag(player);
    try (EditSession editSession = session.createEditSession(player, "LongRangeBuildTool")) {
        try {
            BlockVector3 blockPoint = pos.toVector().toBlockPoint();
            BaseBlock applied = primary.applyBlock(blockPoint);
            if (applied.getBlockType().getMaterial().isAir()) {
                editSession.setBlock(blockPoint, primary);
            } else {
                editSession.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), primary);
            }
        } catch (MaxChangedBlocksException ignored) {
        } finally {
            session.remember(editSession);
        }
    } finally {
        if (bag != null) {
            bag.flushChanges();
        }
    }
    return true;
}
Also used : BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) EditSession(com.sk89q.worldedit.EditSession) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Location(com.sk89q.worldedit.util.Location) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 3 with BlockBag

use of com.sk89q.worldedit.extent.inventory.BlockBag in project FastAsyncWorldEdit by IntellectualSites.

the class StackTool method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
    if (face == null) {
        return false;
    }
    BlockBag bag = session.getBlockBag(player);
    try (EditSession editSession = session.createEditSession(player)) {
        BlockStateHolder<?> block = editSession.getFullBlock(clicked.toVector().toBlockPoint());
        try {
            BlockVector3 position = clicked.toVector().toBlockPoint();
            for (int i = 0; i < range; i++) {
                position = position.add(face.toBlockVector());
                if (!mask.test(position)) {
                    break;
                }
                editSession.setBlock(position, block);
            }
        } catch (MaxChangedBlocksException ignored) {
        } finally {
            session.remember(editSession);
        }
    } finally {
        if (bag != null) {
            bag.flushChanges();
        }
    }
    return true;
}
Also used : BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) EditSession(com.sk89q.worldedit.EditSession) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 4 with BlockBag

use of com.sk89q.worldedit.extent.inventory.BlockBag in project FastAsyncWorldEdit by IntellectualSites.

the class BlockReplacer method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
    BlockBag bag = session.getBlockBag(player);
    try (EditSession editSession = session.createEditSession(player)) {
        try {
            BlockVector3 position = clicked.toVector().toBlockPoint();
            editSession.setBlock(position, pattern);
        } catch (MaxChangedBlocksException ignored) {
        } finally {
            session.remember(editSession);
        }
    } finally {
        if (bag != null) {
            bag.flushChanges();
        }
    }
    return true;
}
Also used : BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) EditSession(com.sk89q.worldedit.EditSession) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 5 with BlockBag

use of com.sk89q.worldedit.extent.inventory.BlockBag in project FastAsyncWorldEdit by IntellectualSites.

the class WorldEditPlugin method createEditSession.

/**
 * Gets the session for the player.
 *
 * @param player a player
 * @return a session
 */
public EditSession createEditSession(Player player) {
    com.sk89q.worldedit.entity.Player wePlayer = wrapPlayer(player);
    LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);
    BlockBag blockBag = session.getBlockBag(wePlayer);
    EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().locatableActor(wePlayer).maxBlocks(session.getBlockChangeLimit()).blockBag(blockBag).build();
    editSession.enableStandardMode();
    return editSession;
}
Also used : BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) LocalSession(com.sk89q.worldedit.LocalSession) EditSession(com.sk89q.worldedit.EditSession)

Aggregations

BlockBag (com.sk89q.worldedit.extent.inventory.BlockBag)11 EditSession (com.sk89q.worldedit.EditSession)8 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)5 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)5 LocalSession (com.sk89q.worldedit.LocalSession)3 Player (com.sk89q.worldedit.entity.Player)3 Location (com.sk89q.worldedit.util.Location)3 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)3 BlockType (com.sk89q.worldedit.world.block.BlockType)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 Command (org.enginehub.piston.annotation.Command)2 BrushSettings (com.fastasyncworldedit.core.command.tool.brush.BrushSettings)1 ResettableExtent (com.fastasyncworldedit.core.extent.ResettableExtent)1 SlottableBlockBag (com.fastasyncworldedit.core.extent.inventory.SlottableBlockBag)1 PatternTraverser (com.fastasyncworldedit.core.function.pattern.PatternTraverser)1 AbstractChangeSet (com.fastasyncworldedit.core.history.changeset.AbstractChangeSet)1 BlockBagChangeSet (com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet)1 NBTException (com.fastasyncworldedit.core.jnbt.NBTException)1