Modify this code

Discussion in 'Plugin Development' started by EvilGooD, Aug 18, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    EvilGooD

    How I can modify this code to do this:
    when the blocks are regenerating it shows the particles of the blocks that are regenerating as if they were breaking.
    Code:
    Code:
            
    @EventHandler
        public void onExplode(EntityExplodeEvent e) {
            final HashMap<Location, Material> blocks = new HashMap<>();
            final Entity entity = e.getEntity();
            for (Block b : e.blockList()) {
                blocks.put(b.getLocation(), b.getType());
            }
            Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
                @Override
                public void run() {
                    for (Entity ent : entity.getWorld().getNearbyEntities(entity.getLocation(), 10, 10, 10)) {
                        if (ent instanceof Item) {
                            ent.remove();
                        }
                    }
                }
            }, 1);
            Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
                @Override
                public void run() {
                    blockRegen(blocks);
                }
            }, 40);
        }
        public void blockRegen(final HashMap<Location, Material> blocks) {
            Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
                @Override
                public void run() {
                    if (!blocks.isEmpty()) {
                        HashMap<Double, Location> hashList = new HashMap<>();
                        for (Location loc : blocks.keySet()) {
                            hashList.put(loc.getY(), loc);
                        }
                        List<Double> doubles = new ArrayList<>();
                        for (double d : hashList.keySet()) {
                            doubles.add(d);
                        }
                        Location loc = hashList.get(doubles.get(minIndex(doubles)));
                        Material b = blocks.get(loc);
                        loc.getWorld().getBlockAt(loc).setType(b);
                        for (Entity ent : loc.getWorld().getNearbyEntities(loc, 15D, 15D, 15D)) {
                            if (ent instanceof Player) {
                                ((Player)ent).playSound(loc, Sound.CLICK, 1F, 1F);
                            }
                        }
                        blocks.remove(loc);
                        blockRegen(blocks);
                    }
                }
            }, 3);
        }
        public static int minIndex(List<Double> list) {
            return list.indexOf(Collections.min(list));
        }
    }
     
  2. Offline

    Synapz

    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page