Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new BukkitRunnable() {
- private int remainingSeconds = 25;
- private final Map<Location, Material> oldBlocks = new HashMap<>();
- @Override
- public void run() {
- remainingSeconds--;
- for (final Block block : getBlocksInRadius(location, 4)) {
- if (block.getType() != Material.ICE) {
- oldBlocks.put(block.getLocation(), block.getType());
- block.setType(Material.ICE); // TODO ignore grass and stuff
- }
- }
- Common.runLater(10, () -> {
- for (final Map.Entry<Location, Material> entry : oldBlocks.entrySet()) {
- if (entry.getKey().getBlock().getType() != entry.getValue())
- entry.getKey().getBlock().setType(entry.getValue());
- }
- });
- if (remainingSeconds == 0) {
- this.cancel();
- //for (final Map.Entry<Location, Material> entry : oldBlocks.entrySet()) {
- // entry.getKey().getBlock().setType(entry.getValue());
- /*final List<Map.Entry<Location, Material>> entries = new ArrayList<>(oldBlocks.entrySet());
- Collections.shuffle(entries);
- for (final Map.Entry<Location, Material> entry : entries) {
- entry.getKey().getBlock().setType(entry.getValue());
- //}
- }*/
- }
- }
- }.runTaskTimer(SimplePlugin.getInstance(), 0, 6);
- public Set<Block> getBlocksInRadius(final Location center, final int radius) {
- final Set<Block> blocks = new HashSet<>();
- final World world = center.getWorld();
- final int X = center.getBlockX();
- final int Y = center.getBlockY();
- final int Z = center.getBlockZ();
- final int radiusSquared = radius * radius;
- for (int x = X - radius; x <= X + radius; x++) {
- for (int y = Y - radius; y <= Y + radius; y++) {
- for (int z = Z - radius; z <= Z + radius; z++) {
- if ((X - x) * (X - x) + (Y - y) * (Y - y) + (Z - z) * (Z - z) <= radiusSquared) {
- final Location location = new Location(world, x, y, z);
- if (location.getBlock().getType() != Material.AIR)
- blocks.add(location.getBlock());
- }
- }
- }
- }
- return blocks;
- }
Add Comment
Please, Sign In to add comment