Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.ddns.misplease.copysignsheads;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.block.BlockState;
- import org.bukkit.block.Sign;
- import org.bukkit.util.BoundingBox;
- public class CopySignsHeadsWorker {
- final double[] blocks;
- final World origin;
- final World destination;
- public CopySignsHeadsWorker(double[] blocks, World origin, World destination) {
- this.blocks = blocks;
- this.origin = origin;
- this.destination = destination;
- }
- private Location getNewPosition(Location selectionStart, Location destinationStart, Location oldPosition, World world) {
- double offsetX = oldPosition.getX() - selectionStart.getX();
- double offsetY = oldPosition.getY() - selectionStart.getY();
- double offsetZ = oldPosition.getZ() - selectionStart.getZ();
- final double x = destinationStart.getX() + offsetX;
- final double y = destinationStart.getY() + offsetY;
- final double z = destinationStart.getZ() + offsetZ;
- return new Location(world, x, y, z, oldPosition.getYaw(), oldPosition.getPitch());
- }
- // we will return item frames that shouldn't be fixed
- void startCopy() {
- // create the cube to be copied
- BoundingBox box = new BoundingBox(blocks[0], blocks[1], blocks[2], blocks[3], blocks[4], blocks[5]);
- // starting positions
- Location startPos1 = new Location(origin, box.getMinX(), box.getMinY(), box.getMinZ());
- Location startPos2 = new Location(destination, blocks[6], blocks[7], blocks[8]);
- double total = Math.abs(box.getMinX() - box.getMaxX()) * Math.abs(box.getMinY() - box.getMaxY()) * Math.abs(box.getMinZ() - box.getMaxZ());
- Bukkit.getServer().getConsoleSender().sendMessage("starting copy (" + total + ")");
- for (double x = box.getMinX(); x <= box.getMaxX(); x++) {
- for (double z = box.getMinZ(); z <= box.getMaxZ(); z++) {
- for (double y = box.getMinY(); y <= box.getMaxY(); y++) { // we will mainly iterate over the Y axis so we reload chunks as little as possible
- // point to that block
- Location location = new Location(origin, x, y, z);
- // get the block at that location
- Block block = location.getBlock();
- // sign
- if (block.getState() instanceof Sign) {
- BlockState blockState = block.getState();
- // point to the destiny block
- Location newLocation = getNewPosition(startPos1, startPos2, location, destination);
- // get the block at the new location
- Block newBlock = newLocation.getBlock();
- // paste the text
- String[] lines = ((Sign)blockState).getLines();
- for (int i = 0; i < lines.length; i++) {
- Bukkit.getServer().getConsoleSender().sendMessage("printing line ("+ lines[i] +")");
- ((Sign)newBlock.getState()).setLine(i, lines[i]);
- }
- Bukkit.getServer().getConsoleSender().sendMessage("block at " + x + " " + y + " " + z + " is a sign (new pos: " + newLocation.getBlockX() + " " + newLocation.getBlockY() + " " + newLocation.getBlockZ() + ")");
- }
- else {
- Bukkit.getServer().getConsoleSender().sendMessage("block at " + x + " " + y + " " + z + " is not a sign");
- }
- // heads
- }
- }
- }
- }
- }
RAW Paste Data