Example #1
0
  public static void checkCrowns(L2Player activeChar) {
    if (activeChar == null) return;

    int crownId = -1;
    boolean isLeader = false;

    final L2Clan clan = activeChar.getClan();

    if (clan != null) {
      final Castle castle = CastleManager.getInstance().getCastleByOwner(clan);

      if (castle != null) crownId = CrownTable.getCrownId(castle.getCastleId());

      if (clan.getLeaderId() == activeChar.getObjectId()) isLeader = true;
    }

    boolean alreadyFoundCirclet = false;
    boolean alreadyFoundCrown = false;

    for (L2ItemInstance item : activeChar.getInventory().getItems()) {
      if (ArrayUtils.contains(CrownTable.getCrownIds(), item.getItemId())) {
        if (crownId > 0) {
          if (item.getItemId() == crownId) {
            if (!alreadyFoundCirclet) {
              alreadyFoundCirclet = true;
              continue;
            }
          } else if (item.getItemId() == 6841 && isLeader) {
            if (!alreadyFoundCrown) {
              alreadyFoundCrown = true;
              continue;
            }
          }
        }

        // WRONG! The crown is not sellable/tradeable/dropable
        // And the circlets are sellable!!!, but not tradeable or dropable
        // Unequip is what happens
        if (item.getItemId() == 6841 || Config.ALT_REMOVE_CASTLE_CIRCLETS)
          activeChar.destroyItem("Removing Crown", item, activeChar, true);
        else if (item.isEquipped())
          activeChar.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_HAIR2);

        // No need to update every item in the inventory
        // activeChar.getInventory().updateDatabase();
      }
    }
  }