Exemplo n.º 1
0
  /**
   * Weak equality is needed when we need only some informations about the equality, example: adding
   * items to players inventory does not need amount equality.
   *
   * @param item item to compare against
   * @return true if equal
   */
  public final boolean equalsWeak(StockItem item) {
    boolean equals;
    // check id
    equals = item.item.getTypeId() == this.item.getTypeId();
    // if equals check data, if not durability
    equals =
        equals && !ItemUtils.itemHasDurability(item.item)
            ? item.item.getDurability() == this.item.getDurability()
            : equals;

    // checking attribute missmatching
    equals = equals ? !attributeMissmatch(item) : equals;

    dB.low("After ID and data check: ", equals);

    // now a if block to not make thousands of not needed checks
    if (equals) {
      // for each attribute in this item
      for (ItemAttr tAttr : attr.values()) {
        // if only once is false then return false
        if (!equals) break;

        // temporary false
        equals = tAttr.getInfo().standalone();

        // debug low
        dB.low("Before ", tAttr.getInfo().name(), " check: ", equals, ", with: ", tAttr.onSave());

        // check each item in the second item, if the attribute is found and strong equal continue
        for (ItemAttr iAttr : item.attr.values()) {
          // debug low
          dB.info("Checking ", iAttr.getInfo().name(), " with: ", iAttr.onSave());

          // same attributes
          if (tAttr.getClass().equals(iAttr.getClass())) equals = tAttr.equalsWeak(iAttr);
        }

        // debug low
        dB.low("After ", tAttr.getInfo().name(), " check: ", equals);
      }

      // for each attribute in this item
      for (ItemFlag tFlag : flags.values()) {
        // if only once is false then return false
        if (!equals) tFlag.getInfo().standalone();

        // temporary false
        equals = tFlag.getInfo().standalone();

        // check each item in the second item, if the attribute is found and strong equal continue
        for (ItemFlag iFlag : item.flags.values())
          // same attributes
          if (tFlag.getClass().equals(iFlag.getClass())) equals = tFlag.equalsWeak(iFlag);
      }
    }
    return equals;
  }
Exemplo n.º 2
0
 private boolean standaloneFlagCheck(StockItem item) {
   boolean containsAll = true;
   for (ItemFlag key : item.flags.values())
     containsAll =
         containsAll && !key.getInfo().standalone()
             ? this.flags.containsKey(key.getClass())
             : containsAll;
   for (ItemFlag key : this.flags.values())
     containsAll =
         containsAll && !key.getInfo().standalone()
             ? item.flags.containsKey(key.getClass())
             : containsAll;
   return containsAll;
 }
Exemplo n.º 3
0
  /** @return a Item Stack item with all attributes and flag data assigned to it. */
  public ItemStack getItem() {
    // clone the "clean" item
    ItemStack clone = this.item.clone();

    // assign attribute data to it
    for (ItemAttr itemAttr : this.attr.values()) {
      try {
        // try assign the attribute
        itemAttr.onAssign(clone);
      } catch (InvalidItemException e) {
        debugMsgItem(itemAttr.getInfo());
      }
    }

    for (ItemFlag flag : flags.values()) {
      try {
        // try assign the flag
        flag.onAssign(clone);
      } catch (InvalidItemException e) {
        debugMsgItem(flag.getInfo());
      }
    }
    // returns the valid item
    return clone;
  }
Exemplo n.º 4
0
  /**
   * Returns a list of temporary lore strings that should be applied depending on the traders
   * status.
   *
   * @param status Status that is checked
   * @param target The a copy of item that gets the lore assigned
   * @return List of lore strings
   */
  public List<String> getTempLore(tNpcStatus status, ItemStack target) {
    // create a new list
    List<String> lore = new ArrayList<String>();

    // check and add if there is already lore attached
    if (this.hasFlag(Lore.class)) lore.addAll(this.getLore());

    // for each attribute
    for (ItemAttr itemAttr : this.attr.values())
      for (tNpcStatus attrStatus : itemAttr.getInfo().status())
        if (attrStatus.equals(status)) itemAttr.onStatusLoreRequest(status, target, lore);

    // for each flag
    for (ItemFlag flag : flags.values())
      for (tNpcStatus attrStatus : flag.getInfo().status())
        if (attrStatus.equals(status)) flag.onStatusLoreRequest(status, lore);

    // return the lore
    return lore;
  }
Exemplo n.º 5
0
  /**
   * Tries to factorize the given item getting all possible data out of it. The factorizing methods
   * will create flags and attributes for the item.
   *
   * @param item item to factorize
   */
  public void factorize(ItemStack item) {
    // debug low
    dB.low("Factorizing item: ", item.getType().name().toLowerCase());

    for (ItemAttr iAttr : ItemAttr.getAllAttributes()) {
      try {
        iAttr.onFactorize(item);
        attr.put(iAttr.getClass(), iAttr);
      } catch (AttributeValueNotFoundException e) {
        this.debugMsgValue(iAttr.getInfo(), "factorized");
      }
    }

    // factorize flags
    for (ItemFlag iFlag : ItemFlag.getAllFlags()) {
      try {
        iFlag.onFactorize(item);
        flags.put(iFlag.getClass(), iFlag);
      } catch (AttributeValueNotFoundException e) {
        this.debugMsgValue(iFlag.getInfo(), "factorized");
      }
    }

    // if the lore was already managed don't load it anymore
    if (loreManaged) return;

    Lore lore = null;
    try {
      lore = (Lore) ItemFlag.initFlag(this, ".lore");
      lore.onFactorize(item);
      flags.put(lore.getClass(), lore);
    } catch (AttributeValueNotFoundException e) {
      this.debugMsgValue(lore != null ? lore.getInfo() : null, "factorized");
    } catch (AttributeInvalidClassException e) {
      this.debugMsgClass(".lore");
    }
  }