public class ZDBlocks extends JavaPlugin implements Listener{
List<Block> BlocksList = new ArrayList<Block>();
HashMap<Material, Integer> BlockDurabilityList = new HashMap<Material, Integer>();
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
BlockDurabilityList.put(Material.DIRT, 200);
BlockDurabilityList.put(Material.GRASS, 200);
BlockDurabilityList.put(Material.GLASS, 120);
BlockDurabilityList.put(Material.WOOD, 50);
BlockDurabilityList.put(Material.LOG, 30);
BlockDurabilityList.put(Material.WOODEN_DOOR, 20);
BlockDurabilityList.put(Material.IRON_DOOR, 10);
BlockDurabilityList.put(Material.OBSIDIAN, 10);
new BukkitRunnable() {
@Override
public void run() {
Collection<? extends Player> PlayerList = getServer().getOnlinePlayers();
Collection<Entity> EntityList;
for (Player player : PlayerList){
if (player.getGameMode() == GameMode.CREATIVE)
return;
EntityList = player.getNearbyEntities(16.0D, 16.0D, 16.0D);
for (Entity entity : EntityList){
if (entity.isDead())
return;
if (entity.getType() == EntityType.ZOMBIE && ((LivingEntity) entity).getTargetBlock((Set<Material>) null, 2).getType() != Material.AIR)
BlocksList.add(((LivingEntity) entity).getTargetBlock((Set<Material>) null, 2));
}
}
}}.runTaskTimer(this, 0, 20);
new BukkitRunnable() {
@Override
public void run(){
for (Block block : BlocksList)
BreakBlock(block);
BlocksList.removeAll(BlocksList);
}}.runTaskTimer(this, 0, (long) (Math.random() * 30) + 15);
}
protected void BreakBlock(Block block){
Location loc = block.getLocation();
Material material = block.getType();
int RandomValue = 1000;
int BlockDurability = 20;
List<Material> BlockList = new ArrayList<Material>();
BlockList.add(Material.AIR);
BlockList.add(Material.BEDROCK);
if (BlockDurabilityList.containsKey(material))
BlockDurability = BlockDurabilityList.get(material);
if (BlockList.contains(material))
return;
if (Math.random() * RandomValue <= BlockDurability){
loc.getWorld().playEffect(loc, Effect.ZOMBIE_DESTROY_DOOR, 0);
block.breakNaturally();
}
else
loc.getWorld().playSound(loc, Sound.ZOMBIE_WOOD, 1.0F, 1.0F);
}
}