public static double getPercentageSung(Jukebox jb) {
    for (ISound is : tracker) {
      if (jb.getLocation().equals(is.getBlock().getLocation())) {
        return is.getPercentageComplete();
      }
    }

    return 0;
  }
 public static void deleteISound(Jukebox jb) {
   ISound tobeGone = null;
   for (ISound is : tracker) {
     if (is.getBlock().getLocation().equals(jb.getLocation())) {
       is.destroy();
       tobeGone = is;
     }
   }
   if (tobeGone != null) {
     tracker.remove(tobeGone);
   }
 }
 @EventHandler(priority = EventPriority.NORMAL)
 public void onEntityExplode(EntityExplodeEvent event) {
   if (event.isCancelled() || event.getEntity() == null) return;
   Boolean cancel = false;
   EntityType entity = event.getEntityType();
   FlagPermissions perms = Residence.getPermsByLoc(event.getEntity().getLocation());
   if (entity == EntityType.CREEPER) {
     if (!perms.has("creeper", perms.has("explode", true))) {
       cancel = true;
     }
   }
   if (entity == EntityType.PRIMED_TNT) {
     if (!perms.has("tnt", perms.has("explode", true))) {
       cancel = true;
     }
   }
   if (entity == EntityType.FIREBALL) {
     if (!perms.has("fireball", perms.has("explode", true))) {
       event.setCancelled(true);
       event.getEntity().remove();
     }
   }
   if (cancel) {
     event.setCancelled(true);
     event.getEntity().remove();
   } else {
     for (Block block : event.blockList()) {
       FlagPermissions blockperms = Residence.getPermsByLoc(block.getLocation());
       if ((!blockperms.has("fireball", perms.has("explode", true))
               && entity == EntityType.FIREBALL)
           || (!blockperms.has("tnt", perms.has("explode", true))
               && entity == EntityType.PRIMED_TNT)
           || (!blockperms.has("creeper", perms.has("explode", true))
               && entity == EntityType.CREEPER)) {
         if (block != null) {
           ItemStack[] inventory = null;
           BlockState save = block.getState();
           if (block.getType() == Material.CHEST) {
             Chest chest = (Chest) save;
             inventory = chest.getInventory().getContents();
             chest.getInventory().clear();
           }
           if (block.getType() == Material.FURNACE
               || block.getType() == Material.BURNING_FURNACE) {
             Furnace furnace = (Furnace) save;
             inventory = furnace.getInventory().getContents();
             furnace.getInventory().clear();
           }
           if (block.getType() == Material.BREWING_STAND) {
             BrewingStand brew = (BrewingStand) save;
             inventory = brew.getInventory().getContents();
             brew.getInventory().clear();
           }
           if (block.getType() == Material.DISPENSER) {
             Dispenser dispenser = (Dispenser) save;
             inventory = dispenser.getInventory().getContents();
             dispenser.getInventory().clear();
           }
           if (block.getType() == Material.JUKEBOX) {
             Jukebox jukebox = (Jukebox) save;
             if (jukebox.isPlaying()) {
               inventory = new ItemStack[1];
               inventory[0] = new ItemStack(jukebox.getPlaying());
               jukebox.setPlaying(null);
             }
           }
           ExplodeRestore.put(save, inventory);
           block.setType(Material.AIR);
         }
       }
     }
     Residence.getServ()
         .getScheduler()
         .scheduleSyncDelayedTask(
             Residence.getServ().getPluginManager().getPlugin("Residence"),
             new Runnable() {
               public void run() {
                 for (BlockState block : ExplodeRestore.keySet().toArray(new BlockState[0])) {
                   ItemStack[] inventory = ExplodeRestore.get(block);
                   block.update(true);
                   if (inventory != null) {
                     if (block.getType() == Material.CHEST)
                       ((Chest) block.getLocation().getBlock().getState())
                           .getInventory()
                           .setContents(inventory);
                     if (block.getType() == Material.FURNACE
                         || block.getType() == Material.BURNING_FURNACE)
                       ((Furnace) block.getLocation().getBlock().getState())
                           .getInventory()
                           .setContents(inventory);
                     if (block.getType() == Material.BREWING_STAND)
                       ((BrewingStand) block.getLocation().getBlock().getState())
                           .getInventory()
                           .setContents(inventory);
                     if (block.getType() == Material.DISPENSER)
                       ((Dispenser) block.getLocation().getBlock().getState())
                           .getInventory()
                           .setContents(inventory);
                     if (block.getType() == Material.JUKEBOX)
                       ((Jukebox) block.getLocation().getBlock().getState())
                           .setPlaying(inventory[0].getType());
                   }
                 }
                 ExplodeRestore.clear();
               }
             },
             1L);
   }
 }
  public static void clear(final Location bottom, final Location top) {
    final AthionMaps pmi = getMap(bottom);

    final int bottomX = bottom.getBlockX();
    final int topX = top.getBlockX();
    final int bottomZ = bottom.getBlockZ();
    final int topZ = top.getBlockZ();

    final int minChunkX = (int) Math.floor((double) bottomX / 16);
    final int maxChunkX = (int) Math.floor((double) topX / 16);
    final int minChunkZ = (int) Math.floor((double) bottomZ / 16);
    final int maxChunkZ = (int) Math.floor((double) topZ / 16);

    final World w = bottom.getWorld();

    for (int cx = minChunkX; cx <= maxChunkX; cx++) {
      for (int cz = minChunkZ; cz <= maxChunkZ; cz++) {
        final Chunk chunk = w.getChunkAt(cx, cz);

        for (final Entity e : chunk.getEntities()) {
          final Location eloc = e.getLocation();

          if (!(e instanceof Player)
              && (eloc.getBlockX() >= bottom.getBlockX())
              && (eloc.getBlockX() <= top.getBlockX())
              && (eloc.getBlockZ() >= bottom.getBlockZ())
              && (eloc.getBlockZ() <= top.getBlockZ())) {
            e.remove();
          }
        }
      }
    }

    for (int x = bottomX; x <= topX; x++) {
      for (int z = bottomZ; z <= topZ; z++) {
        Block block = new Location(w, x, 0, z).getBlock();

        block.setBiome(Biome.PLAINS);

        for (int y = w.getMaxHeight(); y >= 0; y--) {
          block = new Location(w, x, y, z).getBlock();

          final BlockState state = block.getState();

          if (state instanceof InventoryHolder) {
            final InventoryHolder holder = (InventoryHolder) state;
            holder.getInventory().clear();
          }

          if (state instanceof Jukebox) {
            final Jukebox jukebox = (Jukebox) state;
            // Remove once they fix the NullPointerException
            try {
              jukebox.setPlaying(Material.AIR);
            } catch (final Exception e) {
            }
          }

          if (y == 0) {
            block.setTypeId(pmi.BottomBlockId);
          } else if (y == pmi.RoadHeight) {
            block.setTypeId(pmi.PlotFloorBlockId);
          } else if (y < pmi.RoadHeight) {
            block.setTypeId(pmi.PlotFillingBlockId);
          } else {
            if ((y == (pmi.RoadHeight))
                && ((x == (bottomX - 1))
                    || (x == (topX + 1))
                    || (z == (bottomZ - 1))
                    || (z == (topZ + 1)))) {
              // block.setTypeId(pmi.WallBlockId);
            } else {
              block.setTypeIdAndData(0, (byte) 0, false); // .setType(Material.AIR);
            }
          }
        }
      }
    }

    adjustWall(bottom);
  }
 public static void addISound(Player p, Material record, Jukebox jb) {
   deleteISound(jb);
   tracker.add(new ISound(p, record, jb.getBlock()));
 }