misdocumeno

Untitled

Dec 22nd, 2020
927
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.ddns.misplease.copysignsheads;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.World;
  6. import org.bukkit.block.Block;
  7. import org.bukkit.block.BlockState;
  8. import org.bukkit.block.Sign;
  9. import org.bukkit.util.BoundingBox;
  10.  
  11. public class CopySignsHeadsWorker {
  12.  
  13.     final double[] blocks;
  14.     final World origin;
  15.     final World destination;
  16.  
  17.     public CopySignsHeadsWorker(double[] blocks, World origin, World destination) {
  18.         this.blocks = blocks;
  19.         this.origin = origin;
  20.         this.destination = destination;
  21.     }
  22.  
  23.     private Location getNewPosition(Location selectionStart, Location destinationStart, Location oldPosition, World world) {
  24.         double offsetX = oldPosition.getX() - selectionStart.getX();
  25.         double offsetY = oldPosition.getY() - selectionStart.getY();
  26.         double offsetZ = oldPosition.getZ() - selectionStart.getZ();
  27.         final double x = destinationStart.getX() + offsetX;
  28.         final double y = destinationStart.getY() + offsetY;
  29.         final double z = destinationStart.getZ() + offsetZ;
  30.         return new Location(world, x, y, z, oldPosition.getYaw(), oldPosition.getPitch());
  31.     }
  32.  
  33.     // we will return item frames that shouldn't be fixed
  34.     void startCopy() {
  35.  
  36.         // create the cube to be copied
  37.         BoundingBox box = new BoundingBox(blocks[0], blocks[1], blocks[2], blocks[3], blocks[4], blocks[5]);
  38.  
  39.         // starting positions
  40.         Location startPos1 = new Location(origin, box.getMinX(), box.getMinY(), box.getMinZ());
  41.         Location startPos2 = new Location(destination, blocks[6], blocks[7], blocks[8]);
  42.  
  43.         double total = Math.abs(box.getMinX() - box.getMaxX()) * Math.abs(box.getMinY() - box.getMaxY()) * Math.abs(box.getMinZ() - box.getMaxZ());
  44.  
  45.         Bukkit.getServer().getConsoleSender().sendMessage("starting copy (" + total + ")");
  46.  
  47.         for (double x = box.getMinX(); x <= box.getMaxX(); x++) {
  48.             for (double z = box.getMinZ(); z <= box.getMaxZ(); z++) {
  49.                 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
  50.  
  51.                     // point to that block
  52.                     Location location = new Location(origin, x, y, z);
  53.  
  54.                     // get the block at that location
  55.                     Block block = location.getBlock();
  56.  
  57.                     // sign
  58.                     if (block.getState() instanceof Sign) {
  59.  
  60.                         BlockState blockState = block.getState();
  61.                         // point to the destiny block
  62.                         Location newLocation = getNewPosition(startPos1, startPos2, location, destination);
  63.  
  64.                         // get the block at the new location
  65.                         Block newBlock = newLocation.getBlock();
  66.  
  67.                         // paste the text
  68.                         String[] lines = ((Sign)blockState).getLines();
  69.  
  70.                         for (int i = 0; i < lines.length; i++) {
  71.                             Bukkit.getServer().getConsoleSender().sendMessage("printing line ("+ lines[i] +")");
  72.                             ((Sign)newBlock.getState()).setLine(i, lines[i]);
  73.                         }
  74.  
  75.                         Bukkit.getServer().getConsoleSender().sendMessage("block at " + x + " " + y + " " + z + " is a sign (new pos: " + newLocation.getBlockX() + " " + newLocation.getBlockY() + " " + newLocation.getBlockZ() + ")");
  76.                     }
  77.                     else {
  78.                         Bukkit.getServer().getConsoleSender().sendMessage("block at " + x + " " + y + " " + z + " is not a sign");
  79.                     }
  80.                     // heads
  81.                 }
  82.             }
  83.         }
  84.     }
  85. }
  86.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×