JackOUT

Untitled

Mar 15th, 2022 (edited)
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1.         new BukkitRunnable() {
  2.  
  3.             private int remainingSeconds = 25;
  4.             private final Map<Location, Material> oldBlocks = new HashMap<>();
  5.  
  6.             @Override
  7.             public void run() {
  8.                 remainingSeconds--;
  9.  
  10.                 for (final Block block : getBlocksInRadius(location, 4)) {
  11.                     if (block.getType() != Material.ICE) {
  12.                         oldBlocks.put(block.getLocation(), block.getType());
  13.                         block.setType(Material.ICE); // TODO ignore grass and stuff
  14.                     }
  15.                 }
  16.  
  17.                 Common.runLater(10, () -> {
  18.                     for (final Map.Entry<Location, Material> entry : oldBlocks.entrySet()) {
  19.                         if (entry.getKey().getBlock().getType() != entry.getValue())
  20.                             entry.getKey().getBlock().setType(entry.getValue());
  21.                     }
  22.                 });
  23.  
  24.                 if (remainingSeconds == 0) {
  25.                     this.cancel();
  26.  
  27.                     //for (final Map.Entry<Location, Material> entry : oldBlocks.entrySet()) {
  28.                     // entry.getKey().getBlock().setType(entry.getValue());
  29.  
  30.                     /*final List<Map.Entry<Location, Material>> entries = new ArrayList<>(oldBlocks.entrySet());
  31.                     Collections.shuffle(entries);
  32.  
  33.                     for (final Map.Entry<Location, Material> entry : entries) {
  34.                         entry.getKey().getBlock().setType(entry.getValue());
  35.                         //}
  36.                     }*/
  37.                 }
  38.             }
  39.         }.runTaskTimer(SimplePlugin.getInstance(), 0, 6);
  40.  
  41.     public Set<Block> getBlocksInRadius(final Location center, final int radius) {
  42.         final Set<Block> blocks = new HashSet<>();
  43.         final World world = center.getWorld();
  44.         final int X = center.getBlockX();
  45.         final int Y = center.getBlockY();
  46.         final int Z = center.getBlockZ();
  47.         final int radiusSquared = radius * radius;
  48.  
  49.         for (int x = X - radius; x <= X + radius; x++) {
  50.             for (int y = Y - radius; y <= Y + radius; y++) {
  51.                 for (int z = Z - radius; z <= Z + radius; z++) {
  52.                     if ((X - x) * (X - x) + (Y - y) * (Y - y) + (Z - z) * (Z - z) <= radiusSquared) {
  53.                         final Location location = new Location(world, x, y, z);
  54.  
  55.                         if (location.getBlock().getType() != Material.AIR)
  56.                             blocks.add(location.getBlock());
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.         return blocks;
  62.  
  63.     }
Add Comment
Please, Sign In to add comment