Advertisement
Exception_Prototype

Untitled

Jul 2nd, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1.     private static final Random random = new Random();
  2.     private static final Map<String, Structure> structures = Maps.newHashMap(); //put("test", new Structure(..., 3))
  3.     private final JavaPlugin source;
  4.  
  5.     public void restructuring() { // /<command>
  6.         for (Map.Entry<String, Structure> entry : structures.entrySet()) {
  7.             final Location location = entry.getValue().pasteLocation;
  8.             final String schematic = String.format("%s_%d.schematic", entry.getKey(), random.nextInt(entry.getValue().maxRandom));
  9.             final File file = new File(source.getDataFolder(), schematic);
  10.             Logging.info("file exists: " + file.exists()); //always true
  11.             paste(file, location.getWorld(), new org.bukkit.util.Vector(location.getBlockX(), location.getBlockY(), location.getBlockX()));
  12.         }
  13.     }
  14.  
  15.     public static void paste(File file, org.bukkit.World bworld, org.bukkit.util.Vector vector) {
  16.         try {
  17.             Vector position = new Vector(vector.getX(), vector.getY(), vector.getZ());
  18.             World world = FaweAPI.getWorld(bworld.getName());
  19.             ClipboardFormat.SCHEMATIC.load(file).paste(world, position, true, false, (Transform) null);
  20.         } catch (IOException e) {
  21.             Logging.severe("Could not paste " + file.getName(), e);
  22.         }
  23.     }
  24.  
  25.     private static class Structure {
  26.         private final Location pasteLocation;
  27.         private final int maxRandom;
  28.  
  29.         Structure(Location pasteLocation, int maxRandom) {
  30.             this.pasteLocation = pasteLocation;
  31.             this.maxRandom = maxRandom;
  32.         }
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement