@EventHandler
  public void onPlayerInteractEvent(PlayerInteractEvent event) {
    if (!isEnabled()) return;
    try {
      if (event.hasBlock() && event.getClickedBlock().getType() == Material.SIGN) return;
      if (event.hasItem() && event.useItemInHand() != Event.Result.DENY) {
        ForgePermittor.log(
            "ItemType: " + getValidator().CheckItem(event.getItem()).toString(), true);
        if (!getProtectionManager()
            .CanUseItem(
                event.getPlayer(),
                event.getPlayer().getLocation(),
                getValidator().CheckItem(event.getItem()))) {
          event.setUseItemInHand(Event.Result.DENY);
          event.setUseInteractedBlock(Event.Result.DENY);

          return;
        }
      }
      if (event.hasBlock() && event.useInteractedBlock() != Event.Result.DENY) {
        ForgePermittor.log(
            "BlockType: " + getValidator().CheckBlock(event.getClickedBlock()).toString(), true);
        if (!getProtectionManager()
            .CanUseBlock(
                event.getPlayer(),
                event.getClickedBlock(),
                getValidator().CheckBlock(event.getClickedBlock()))) {
          event.setUseInteractedBlock(Event.Result.DENY);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @EventHandler
  public void onPlayerInteract(PlayerInteractEvent event) {
    final PlayerInteractEvent Event = event;

    // If not right clicking air, do nothing
    if (!event.getAction().equals(Action.RIGHT_CLICK_AIR)
        && !event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
      return;
    }
    // If the event doesn't involve an item
    if (!event.hasItem()) {
      return;
    }
    // If the item is null
    if (event.getItem() == null) {
      return;
    }
    // If the item isn't a potion
    if (event.getItem().getType() != Material.POTION) {
      return;
    }
    // Removes the potion effects
    plugin
        .getServer()
        .getScheduler()
        .scheduleSyncDelayedTask(
            plugin,
            new Runnable() {
              public void run() {
                // If the player currently has potion effects
                if (Event.getPlayer().getActivePotionEffects() == null) {
                  return;
                }
                // If the player has less than or eqaul to 0 potion effects
                if (Event.getPlayer().getActivePotionEffects().size() <= 0) {
                  return;
                }

                for (PotionEffect x : Event.getPlayer().getActivePotionEffects()) {
                  if (plugin.getConfig().getBoolean("Potions." + x.getType().getName())) {
                    Event.getPlayer().removePotionEffect(x.getType());
                  }
                }
              }
            },
            40);
  }
 @EventHandler
 public void onPlayerInteract(PlayerInteractEvent event) {
   // Open the backpack when the player clicks while holding it
   switch (event.getAction()) {
     case RIGHT_CLICK_AIR:
     case RIGHT_CLICK_BLOCK:
       // Verify that the item has lore
       if (event.hasItem()) {
         ItemStack hand = event.getItem();
         if (hand.hasItemMeta()) {
           ItemMeta meta = hand.getItemMeta();
           if (meta.hasLore()) {
             // Scan the lore for linked PhatLoots
             List<String> lore = meta.getLore();
             for (String line : lore) {
               if (line.startsWith(PhatLootsConfig.lootBagKey)) {
                 PhatLoot phatLoot =
                     PhatLoots.getPhatLoot(line.substring(PhatLootsConfig.lootBagKey.length()));
                 if (phatLoot != null) { // Valid PhatLoot
                   event.setCancelled(true);
                   // Remove the bag from the player's inventory
                   if (hand.getAmount() > 1) {
                     hand.setAmount(hand.getAmount() - 1);
                   } else {
                     event.getPlayer().setItemInHand(new ItemStack(0));
                   }
                   // Give loot to the player
                   phatLoot.rollForLoot(event.getPlayer());
                 }
               }
             }
           }
         }
       }
   }
 }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (!event.hasBlock()) return;

    Action action = event.getAction();
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();
    int type = block.getTypeId();
    BlockFace face = event.getBlockFace();

    if (action == Action.RIGHT_CLICK_BLOCK) {
      if (Lockette.protectTrapDoors)
        if (type == Material.TRAP_DOOR.getId()) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (Lockette.protectDoors)
        if ((type == Material.WOODEN_DOOR.getId())
            || (type == Material.IRON_DOOR_BLOCK.getId())
            || (type == materialFenceGate)) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (type == Material.WALL_SIGN.getId()) {
        interactSign(block, player);
        return;
      }

      if (type == Material.CHEST.getId()) {
        // Try at making a 1.7->1.8 chest fixer.
        Lockette.rotateChestOrientation(block, face);
      }

      if ((type == Material.CHEST.getId())
          || (type == Material.DISPENSER.getId())
          || (type == Material.FURNACE.getId())
          || (type == Material.BURNING_FURNACE.getId())
          || (type == Material.BREWING_STAND.getId())
          || Lockette.isInList(type, Lockette.customBlockList)) {

        // Trying something out....
        if (Lockette.directPlacement)
          if (event.hasItem())
            if ((face != BlockFace.UP) && (face != BlockFace.DOWN)) {
              ItemStack item = event.getItem();

              if (item.getTypeId() == Material.SIGN.getId()) {
                Block checkBlock = block.getRelative(face);

                type = checkBlock.getTypeId();

                if (type == Material.AIR.getId()) {
                  boolean place = false;

                  if (Lockette.isProtected(block)) {
                    // Add a users sign only if owner.
                    if (Lockette.isOwner(block, player.getName())) place = true;
                  } else place = true;
                  // if(Lockette.altPrivate == null){}//if(Lockette.altMoreUsers == null){}
                  if (place) {
                    // player.sendMessage(ChatColor.RED + "Lockette: Using a sign on a container");

                    event.setUseItemInHand(Result.ALLOW); // ? seems to work in 568
                    event.setUseInteractedBlock(Result.DENY);
                    return;
                  }
                }
              }
            }

        if (interactContainer(block, player)) return;

        event.setUseInteractedBlock(Result.DENY);
        event.setUseItemInHand(Result.DENY);
        return;
      }

      if (type == Material.DIRT.getId())
        if (event.hasItem()) {
          ItemStack item = event.getItem();

          type = item.getTypeId();

          if ((type == Material.DIAMOND_HOE.getId())
              || (type == Material.GOLD_HOE.getId())
              || (type == Material.IRON_HOE.getId())
              || (type == Material.STONE_HOE.getId())
              || (type == Material.WOOD_HOE.getId())) {
            Block checkBlock = block.getRelative(BlockFace.UP);

            type = checkBlock.getTypeId();

            if ((type == Material.WOODEN_DOOR.getId())
                || (type == Material.IRON_DOOR_BLOCK.getId())
                || (type == materialFenceGate)) {
              event.setUseInteractedBlock(Result.DENY);
              return;
            }
          }
        }
    } else if (action == Action.LEFT_CLICK_BLOCK) {
      if (Lockette.protectTrapDoors)
        if (type == Material.TRAP_DOOR.getId()) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (Lockette.protectDoors)
        if ((type == Material.WOODEN_DOOR.getId())
            || (type == Material.IRON_DOOR_BLOCK.getId())
            || (type == materialFenceGate)) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }
    }
  }