Search in sources :

Example 6 with BukkitWorld

use of com.sk89q.worldedit.bukkit.BukkitWorld in project modules-extra by CubeEngine.

the class LogEditSession method rawSetBlock.

@Override
public boolean rawSetBlock(Vector pt, BaseBlock block) {
    if (this.player instanceof BukkitPlayer && this.player.getWorld() instanceof BukkitWorld) {
        World world = ((BukkitWorld) this.player.getWorld()).getWorld();
        BlockState oldState = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getState();
        boolean success = super.rawSetBlock(pt, block);
        if (success) {
            ActionWorldEdit action = this.listener.newAction(ActionWorldEdit.class, world);
            if (action != null) {
                BlockState newState = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getState();
                action.setOldBlock(oldState);
                action.setNewBlock(newState);
                action.setPlayer(((BukkitPlayer) this.player).getPlayer());
                action.setLocation(newState.getLocation());
                this.listener.logAction(action);
            }
        }
        return success;
    }
    return super.rawSetBlock(pt, block);
}
Also used : BlockState(org.bukkit.block.BlockState) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) World(org.bukkit.World) LocalWorld(com.sk89q.worldedit.LocalWorld) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) BukkitPlayer(com.sk89q.worldedit.bukkit.BukkitPlayer)

Example 7 with BukkitWorld

use of com.sk89q.worldedit.bukkit.BukkitWorld in project FunnyGuilds by FunnyGuilds.

the class SchematicHelper method pasteSchematic.

public static boolean pasteSchematic(File schematicFile, Location location, boolean withAir) {
    try {
        Vector pasteLocation = new Vector(location.getX(), location.getY(), location.getZ());
        World pasteWorld = new BukkitWorld(location.getWorld());
        WorldData pasteWorldData = pasteWorld.getWorldData();
        Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(new FileInputStream(schematicFile)).read(pasteWorldData);
        Region pasteRegion = clipboard.getRegion();
        Extent pasteExtent = WorldEdit.getInstance().getEditSessionFactory().getEditSession(pasteWorld, -1);
        AffineTransform transform = new AffineTransform();
        ForwardExtentCopy copy = new ForwardExtentCopy(pasteExtent, pasteRegion, clipboard.getOrigin(), pasteExtent, pasteLocation);
        if (!transform.isIdentity()) {
            copy.setTransform(transform);
        }
        if (!withAir) {
            copy.setSourceMask(new ExistingBlockMask(clipboard));
        }
        Operations.completeLegacy(copy);
        return true;
    } catch (IOException | MaxChangedBlocksException e) {
        FunnyLogger.exception(e);
        return false;
    }
}
Also used : Extent(com.sk89q.worldedit.extent.Extent) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) WorldData(com.sk89q.worldedit.world.registry.WorldData) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) FileInputStream(java.io.FileInputStream) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) Region(com.sk89q.worldedit.regions.Region) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) Vector(com.sk89q.worldedit.Vector)

Aggregations

BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)7 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)6 IOException (java.io.IOException)6 EditSession (com.sk89q.worldedit.EditSession)5 Vector (com.sk89q.worldedit.Vector)4 CuboidClipboard (com.sk89q.worldedit.CuboidClipboard)3 ForwardExtentCopy (com.sk89q.worldedit.function.operation.ForwardExtentCopy)3 DataException (com.sk89q.worldedit.data.DataException)2 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)2 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)2 Closer (com.sk89q.worldedit.util.io.Closer)2 WorldData (com.sk89q.worldedit.world.registry.WorldData)2 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)2 FileInputStream (java.io.FileInputStream)2 World (org.bukkit.World)2 LocalSession (com.sk89q.worldedit.LocalSession)1 LocalWorld (com.sk89q.worldedit.LocalWorld)1 BukkitPlayer (com.sk89q.worldedit.bukkit.BukkitPlayer)1 Extent (com.sk89q.worldedit.extent.Extent)1 ClipboardReader (com.sk89q.worldedit.extent.clipboard.io.ClipboardReader)1