diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java index c775ce0..3ea6965 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java @@ -1,15 +1,16 @@ package de.steamwar.bausystem.world; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; -import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.transform.AffineTransform; -import com.sk89q.worldedit.session.ClipboardHolder; +import com.sk89q.worldedit.world.block.BaseBlock; +import net.minecraft.server.v1_15_R1.BlockPosition; +import net.minecraft.server.v1_15_R1.WorldServer; import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData; import java.io.File; import java.io.FileInputStream; @@ -30,18 +31,29 @@ public class Region_15 { BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 v = BlockVector3.at(x, y, z); BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - AffineTransform aT = new AffineTransform(); if(rotate){ - aT = aT.rotateY(180); v = v.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); }else{ v = v.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset); } - EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1); - ClipboardHolder ch = new ClipboardHolder(clipboard); - ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e).to(v).build()); - e.flushSession(); + WorldServer world = ((CraftWorld)Bukkit.getWorlds().get(0)).getHandle(); + v = v.add(offset); + + for(int X = v.getBlockX(); X < v.getBlockX() + dimensions.getBlockX(); X++){ + for(int Y = v.getBlockY(); Y < v.getBlockY() + dimensions.getBlockY(); Y++){ + for(int Z = v.getBlockZ(); Z < v.getBlockZ() + dimensions.getBlockZ(); Z++){ + BlockPosition blockPos = new BlockPosition(X, Y, Z); + BaseBlock fullBlock = clipboard.getFullBlock(BlockVector3.at(X, Y, Z).subtract(v).add(clipboard.getRegion().getMinimumPoint())); + Material replaceTo = BukkitAdapter.adapt(fullBlock.getBlockType()); + if(replaceTo == null) + world.setTypeAndData(blockPos, ((CraftBlockData)Material.AIR.createBlockData()).getState(), 1024); + else + world.setTypeAndData(new BlockPosition(X, Y, Z), ((CraftBlockData)replaceTo.createBlockData()).getState(), 1024); + world.getChunkProvider().flagDirty(blockPos); + //world.getChunkProvider().getLightEngine().a(blockPos); //TODO: Fix lightning issues without preventing shutdown + } + } + } } }