Example #1
0
  @Override
  public void onEntityDamage(EntityDamageEvent event) {
    if (event.isCancelled()) {
      return;
    }

    // Check if the event is about a player that is drowning
    if (event.getCause() == EntityDamageEvent.DamageCause.DROWNING
        && event.getEntity() instanceof CraftPlayer) {
      final CraftPlayer player = (CraftPlayer) event.getEntity();

      // Check if user got unlimited air node
      if (PermissionsHandler.hasPermission(player, Gills.getConfig().unlimitedAirNode)) {
        updatePlayerAirBubbles(player);
        event.setCancelled(true);
        return;
      }

      // Check if user access to gills
      if (!PermissionsHandler.hasPermission(player, Gills.getConfig().userNode)) {
        return;
      }

      int depth = getDepth(player);
      // Check itemsets
      for (GillsItemSet itemSet : Gills.getConfig().itemSets) {
        if (PermissionsHandler.hasPermission(player, itemSet.getNode())
            && itemSet.isTargetDepth(depth)
            && itemSet.isTargetAltitude(player.getLocation().getBlockY())
            && itemSet.isWorldAllowed(player.getLocation().getWorld().getName())
            && itemSet.gotRequiredItems(player)) {

          // Check is inside itemSet
          itemSet.consumeRequiredItems(player);

          updatePlayerAirBubbles(player);
          event.setCancelled(true);
          return;
        }
      }
    }
  }