@EventHandler(priority = EventPriority.MONITOR)
 public void onBlockBreak(BlockBreakEvent event) {
   Block block = event.getBlock();
   if (block.getType() == Material.DISPENSER) {
     plugin.removeCannon(block);
   } else if (block.getType() == Material.WEB) {
     if (plugin.removeWeb(block)) {
       // event.setCancelled(true);
       block.setType(Material.AIR);
     }
   }
 }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onBlockDispense(BlockDispenseEvent event) {
    Block block = event.getBlock();
    if (block.getType() == Material.DISPENSER) {

      Cannon cannon = plugin.getCannon(block, false);
      if (cannon == null) {
        return;
      }

      Material material = event.getItem().getType();

      Grenade grenade = plugin.getArmageddonConfig().getGrenade(material);

      if (grenade.getType() == Type.DUD || !grenade.isCannonUse()) {
        return;
      }

      Dispenser dispenser = (Dispenser) block.getType().getNewData(block.getData());

      double vx = cannon.getVelocity() * Math.cos((double) (Math.PI * cannon.getAngle() / 180));
      double y = cannon.getVelocity() * Math.sin((double) (Math.PI * cannon.getAngle() / 180));

      double x = 0;
      double z = 0;

      int yaw = 0;

      switch (dispenser.getFacing()) {
        case NORTH:
          x = -vx;
          yaw = 90;
          break;

        case SOUTH:
          x = vx;
          yaw = 270;
          break;

        case WEST:
          z = vx;
          yaw = 0;
          break;

        case EAST:
          z = -vx;
          yaw = 180;
          break;
      }

      Vector initialVelocity = new Vector(x, y, z);
      Location location = block.getRelative(dispenser.getFacing()).getLocation().add(0.5, 0.5, 0.5);
      World world = block.getWorld();

      Entity entity = null;

      x = location.getX();
      y = location.getY();
      z = location.getZ();

      Location locClone = location.clone();

      switch (grenade.getType()) {
        case PIG:
          entity = world.spawn(location, Pig.class);
          break;

        case COW:
          entity = world.spawn(location, Cow.class);
          break;

        case SHEEP:
          entity = world.spawn(location, Sheep.class);
          break;

        case TNT:
          entity = world.spawn(location, TNTPrimed.class);
          ((TNTPrimed) entity).setFuseTicks(cannon.getFuse());
          break;

        case EXPLOSIVE:
        case NUCLEAR:
        case WATER_BALLOON:
        case SPIDER_WEB:
        case SNARE:
        case STUN:
          entity = world.spawn(location, Snowball.class);
          break;

        case MOLOTOV:
          locClone.setPitch(0);
          locClone.setYaw(yaw);
          entity = world.spawn(locClone, Fireball.class);
          LivingEntity owner = plugin.getServer().getPlayer(cannon.getOwner());
          if (owner == null) {
            // get the closest living entity
            double distance = Double.MAX_VALUE;
            for (LivingEntity e : world.getLivingEntities()) {
              if (e.getLocation().distance(locClone) < distance) {
                distance = e.getLocation().distance(locClone);
                owner = e;
              }
            }
          }
          ((Fireball) entity).setShooter(owner);
          break;

        default:
          return;
      }

      if (entity != null) {
        if (!(entity instanceof Fireball)) {
          entity.setVelocity(initialVelocity);
        }

        if (!(entity instanceof LivingEntity)) {
          plugin.registerGrenade(entity, grenade);
        }

        plugin.adjustInventoryAndUsage(
            ((org.bukkit.block.Dispenser) block.getState()).getInventory(),
            cannon,
            material,
            grenade.getUses());

        event.setCancelled(true);
        world.createExplosion(location, 0);
      }
    }
  }