Advertisement
Guest User

Baksovic

a guest
Jun 10th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1. public class ZDBlocks extends JavaPlugin implements Listener{
  2.     List<Block> BlocksList = new ArrayList<Block>();
  3.     HashMap<Material, Integer> BlockDurabilityList = new HashMap<Material, Integer>();
  4.    
  5.     public void onEnable() {
  6.         getServer().getPluginManager().registerEvents(this, this);
  7.         BlockDurabilityList.put(Material.DIRT, 200);
  8.         BlockDurabilityList.put(Material.GRASS, 200);
  9.         BlockDurabilityList.put(Material.GLASS, 120);
  10.         BlockDurabilityList.put(Material.WOOD, 50);
  11.         BlockDurabilityList.put(Material.LOG, 30);
  12.         BlockDurabilityList.put(Material.WOODEN_DOOR, 20);
  13.         BlockDurabilityList.put(Material.IRON_DOOR, 10);
  14.         BlockDurabilityList.put(Material.OBSIDIAN, 10);
  15.         new BukkitRunnable() {
  16.            
  17.             @Override
  18.             public void run() {
  19.                 Collection<? extends Player> PlayerList = getServer().getOnlinePlayers();
  20.                 Collection<Entity> EntityList;
  21.                 for (Player player : PlayerList){
  22.                     if (player.getGameMode() == GameMode.CREATIVE)
  23.                         return;
  24.                     EntityList = player.getNearbyEntities(16.0D, 16.0D, 16.0D);
  25.                     for (Entity entity : EntityList){
  26.                        
  27.                         if (entity.isDead())
  28.                             return;
  29.                        
  30.                         if (entity.getType() == EntityType.ZOMBIE && ((LivingEntity) entity).getTargetBlock((Set<Material>) null, 2).getType() != Material.AIR)
  31.                             BlocksList.add(((LivingEntity) entity).getTargetBlock((Set<Material>) null, 2));
  32.                     }
  33.                 }
  34.             }}.runTaskTimer(this, 0, 20);
  35.        
  36.         new BukkitRunnable() {
  37.             @Override
  38.             public void run(){
  39.                 for (Block block : BlocksList)
  40.                     BreakBlock(block);
  41.                 BlocksList.removeAll(BlocksList);
  42.             }}.runTaskTimer(this, 0, (long) (Math.random() * 30) + 15);
  43.     }
  44.    
  45.     protected void BreakBlock(Block block){
  46.        
  47.         Location loc = block.getLocation();
  48.         Material material = block.getType();
  49.         int RandomValue = 1000;
  50.         int BlockDurability = 20;
  51.        
  52.         List<Material> BlockList = new ArrayList<Material>();
  53.         BlockList.add(Material.AIR);
  54.         BlockList.add(Material.BEDROCK);
  55.        
  56.         if (BlockDurabilityList.containsKey(material))
  57.             BlockDurability = BlockDurabilityList.get(material);
  58.        
  59.         if (BlockList.contains(material))
  60.             return;
  61.            
  62.         if (Math.random() * RandomValue <= BlockDurability){
  63.             loc.getWorld().playEffect(loc, Effect.ZOMBIE_DESTROY_DOOR, 0);
  64.             block.breakNaturally();
  65.         }
  66.         else
  67.             loc.getWorld().playSound(loc, Sound.ZOMBIE_WOOD, 1.0F, 1.0F);
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement