@EventHandler(priority = EventPriority.NORMAL)
  public void onPluginDisable(PluginDisableEvent event) {
    ProtectionPlugins protectionPlugin;
    try {
      protectionPlugin = ProtectionPlugins.valueOf(event.getPlugin().getName());
    } catch (Exception e) {
      return;
    }

    this.instance.getLogger().info("Unloading protection plugin: " + event.getPlugin().getName());
    protectionPlugin.removeHandler();
  }
  @SuppressWarnings("deprecation")
  @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
  public void onBlockPlace(BlockPlaceEvent event) {
    final Player player = event.getPlayer();
    if (player.getName().startsWith("[")) {
      return;
    }

    ItemStack itemInHand = event.getItemInHand();

    // special aoe items list (needs to check a wide area...)
    ListedRangedItem item =
        this.instance.config.getAoEItem(
            itemInHand.getType(), itemInHand.getData().getData(), player.getWorld().getName());
    if (item != null) {
      Location blockLocation = event.getBlock().getLocation();
      for (ProtectionHandler protection : ProtectionPlugins.getHandlers()) {
        if (!protection.canUseAoE(player, blockLocation, item.range)) {
          event.setBuild(false);
          event.setCancelled(true);
          this.confiscateInventory(player);
          return;
        }
      }
    }
  }
  void pluginEnable(String pluginName) {
    ProtectionPlugins protectionPlugin;
    try {
      protectionPlugin = ProtectionPlugins.valueOf(pluginName);
    } catch (Exception e1) {
      return;
    }

    if (protectionPlugin.isEnabled()) {
      try {
        this.instance.getLogger().info("Loading protection plugin: " + pluginName);
        protectionPlugin.createHandler();
      } catch (InstantiationException | IllegalAccessException e) {
        e.printStackTrace();
      }
    }
  }
 private boolean projectileCheck(Projectile projectile, Location location) {
   final Player player = (Player) projectile.getShooter();
   for (ProtectionHandler protection : ProtectionPlugins.getHandlers()) {
     if (!protection.canProjectileHit(player, projectile.getLocation())) {
       projectile.remove();
       return true;
     }
   }
   return false;
 }
  @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    if (event.getDamager().getType() == EntityType.PLAYER) {
      final Player damager = (Player) event.getDamager();

      if (damager.getName().startsWith("[")) {
        return;
      }

      final Entity damaged = event.getEntity();

      for (ProtectionHandler protection : ProtectionPlugins.getHandlers()) {
        if (!protection.canAttack(damager, damaged)) {
          event.setCancelled(true);
          this.confiscateInventory(damager);
          return;
        }
      }
    }
  }
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.LOWEST)
  public void onPlayerInteract(PlayerInteractEvent event) {
    // ignore stepping onto or into a block
    if (event.getAction() == Action.PHYSICAL) {
      return;
    }

    final Player player = event.getPlayer();
    Block block = event.getClickedBlock();

    ItemStack item = event.getItem();
    if (item == null) {
      item = player.getItemInHand();
    }

    // ignore all vanilla items and edible items in vanilla blocks actions
    if (block != null
        && (item.getData().getItemType().isEdible() || isVanilla(item.getType()))
        && isVanilla(block.getType())) {
      return;
    }

    // whitelisted item check
    if (this.instance.config.matchWhitelistItem(
            item.getType(), item.getData().getData(), player.getWorld().getName())
        != null) {
      return;
    }

    // special aoe items list (needs to check a wide area...)
    ListedRangedItem rangeItem =
        this.instance.config.matchAoEItem(
            item.getType(), item.getData().getData(), player.getWorld().getName());
    if (rangeItem != null) {
      // check players location
      for (ProtectionHandler protection : ProtectionPlugins.getHandlers()) {
        if (!protection.canUseAoE(player, player.getLocation(), rangeItem.range)) {
          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          event.setCancelled(true);
          this.confiscateInventory(player);
          return;
        }
      }
      return;
    }

    if (block == null) {
      // check if the item in hand is a ranged item
      rangeItem =
          this.instance.config.matchRangedItem(
              item.getType(), item.getData().getData(), player.getWorld().getName());
      if (rangeItem != null) {
        block = getTargetBlock(player, rangeItem.range);
      }
    }

    Location targetLocation;
    if (block == null) {
      targetLocation = player.getLocation();
    } else {
      targetLocation = block.getLocation();
    }

    // check permissions on that location
    for (ProtectionHandler protection : ProtectionPlugins.getHandlers()) {
      if (!protection.canInteract(player, targetLocation)) {
        event.setUseInteractedBlock(Result.DENY);
        event.setUseItemInHand(Result.DENY);
        event.setCancelled(true);
        this.confiscateInventory(player);
        return;
      }
    }
  }