public boolean canPlayerUseBlock(Player player, Block block) {

    if (Conf.adminBypassPlayers.contains(player.getName())) {
      return true;
    }

    Material material = block.getType();
    FLocation loc = new FLocation(block);
    Faction otherFaction = Board.getFactionAt(loc);

    // no door/chest/whatever protection in wilderness, war zones, or safe zones
    if (!otherFaction.isNormal()) {
      return true;
    }

    // We only care about some material types.
    if (otherFaction.hasPlayersOnline()) {
      if (!Conf.territoryProtectedMaterials.contains(material)) {
        return true;
      }
    } else {
      if (!Conf.territoryProtectedMaterialsWhenOffline.contains(material)) {
        return true;
      }
    }

    FPlayer me = FPlayer.get(player);
    Faction myFaction = me.getFaction();
    Relation rel = myFaction.getRelation(otherFaction);
    boolean ownershipFail =
        Conf.ownedAreasEnabled
            && Conf.ownedAreaProtectMaterials
            && !otherFaction.playerHasOwnershipRights(me, loc);

    // You may use any block unless it is another faction's territory...
    if (rel.isNeutral()
        || (rel.isEnemy() && Conf.territoryEnemyProtectMaterials)
        || (rel.isAlly() && Conf.territoryAllyProtectMaterials)) {
      me.sendMessage(
          "You can't use "
              + TextUtil.getMaterialName(material)
              + " in the territory of "
              + otherFaction.getTag(myFaction));
      return false;
    }
    // Also cancel if player doesn't have ownership rights for this claim
    else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) {
      me.sendMessage(
          "You can't use "
              + TextUtil.getMaterialName(material)
              + " in this territory, it is owned by: "
              + myFaction.getOwnerListString(loc));
      return false;
    }

    return true;
  }
  public boolean playerCanUseItemHere(Player player, Block block, Material material) {

    if (Conf.adminBypassPlayers.contains(player.getName())) {
      return true;
    }

    FLocation loc = new FLocation(block);
    Faction otherFaction = Board.getFactionAt(loc);

    if (otherFaction.hasPlayersOnline()) {
      if (!Conf.territoryDenyUseageMaterials.contains(material)) {
        return true; // Item isn't one we're preventing for online factions.
      }
    } else {
      if (!Conf.territoryDenyUseageMaterialsWhenOffline.contains(material)) {
        return true; // Item isn't one we're preventing for offline factions.
      }
    }

    FPlayer me = FPlayer.get(player);

    if (otherFaction.isNone()) {
      if (!Conf.wildernessDenyUseage
          || Factions.hasPermAdminBypass(player)
          || Conf.worldsNoWildernessProtection.contains(block.getWorld().getName())) {
        return true; // This is not faction territory. Use whatever you like here.
      }
      me.sendMessage("You can't use " + TextUtil.getMaterialName(material) + " in the wilderness.");
      return false;
    } else if (otherFaction.isSafeZone()) {
      if (!Conf.safeZoneDenyUseage || Factions.hasPermManageSafeZone(player)) {
        return true;
      }
      me.sendMessage("You can't use " + TextUtil.getMaterialName(material) + " in a safe zone.");
      return false;
    } else if (otherFaction.isWarZone()) {
      if (!Conf.warZoneDenyUseage || Factions.hasPermManageWarZone(player)) {
        return true;
      }
      me.sendMessage("You can't use " + TextUtil.getMaterialName(material) + " in a war zone.");
      return false;
    }

    Faction myFaction = me.getFaction();
    Relation rel = myFaction.getRelation(otherFaction);
    boolean ownershipFail =
        Conf.ownedAreasEnabled
            && Conf.ownedAreaDenyUseage
            && !otherFaction.playerHasOwnershipRights(me, loc);

    // Cancel if we are not in our own territory
    if (!rel.isMember() && rel.confDenyUseage()) {
      me.sendMessage(
          "You can't use "
              + TextUtil.getMaterialName(material)
              + " in the territory of "
              + otherFaction.getTag(myFaction));
      return false;
    }
    // Also cancel if player doesn't have ownership rights for this claim
    else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) {
      me.sendMessage(
          "You can't use "
              + TextUtil.getMaterialName(material)
              + " in this territory, it is owned by: "
              + myFaction.getOwnerListString(loc));
      return false;
    }

    return true;
  }