Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BlockRegen extends JavaPlugin implements Listener {
- public void onEnable() {
- Bukkit.getServer().getPluginManager().registerEvents(this, this);
- }
- @EventHandler
- public void onEntityExplode(EntityExplodeEvent e) {
- if (!e.blockList().isEmpty()) {
- final List<BlockState> blocks = new ArrayList<BlockState>();
- for (Block b : e.blockList()) {
- if (b.getType() != Material.AIR) {
- if (!blocks.contains(b.getState())) {
- blocks.add(b.getState());
- b.setType(Material.AIR);
- }
- }
- }
- new BukkitRunnable() {
- int i = 17;
- public void run() {
- if (i>0){
- i--;
- }else{
- regen(blocks, false, 5);
- this.cancel();
- }
- }
- }.runTaskTimer(this, 3, 3);
- }
- }
- protected void regen(List<BlockState> blocks, boolean effect, int speed) {
- new BukkitRunnable() {
- int i = -1;
- @SuppressWarnings("deprecation")
- public void run() {
- if (i != blocks.size()-1) {
- i++;
- BlockState bs = blocks.get(i);
- bs.getBlock().setType(bs.getType());
- bs.getBlock().setData(bs.getData().getData());
- bs.getBlock().getWorld().playEffect(bs.getLocation(), Effect.STEP_SOUND, bs.getBlock().getType());
- bs.getBlock().getWorld().playEffect(bs.getLocation(), Effect.STEP_SOUND, bs.getBlock().getData());
- }
- }
- }.runTaskTimer(this, 0, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement