Esempio n. 1
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;
  }
Esempio n. 2
0
 /**
  * Looks for the flag declaration that has the specified <b>key</b>. If found it will add it
  * automatically to the items structure.
  *
  * @param key the unique flag key
  */
 public void addFlag(String key) {
   try {
     ItemFlag flag = ItemFlag.initFlag(this, key);
     flags.put(flag.getClass(), flag);
   } catch (Exception e) {
     debugMsgClass(key);
   }
 }
Esempio n. 3
0
  /**
   * Strong equality is needed when we need precise information if an item is equal, example: Stock
   * placement
   *
   * @param item item to compare against
   * @return true if equal
   */
  public final boolean equalsStrong(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.equalsStrong(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) break;

        // temporary false
        equals = false;

        // 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.equalsStrong(iFlag);
      }
    }
    return equals;
  }
Esempio n. 4
0
  /**
   * Creates a string representation of the item, used for saving. Only lores are saved in another
   * way.
   *
   * @return prepared save string
   */
  public String save() {
    // result string
    String result = "";

    // add id and data information
    result += item.getTypeId();
    if (!ItemUtils.itemHasDurability(item) && item.getData().getData() != 0)
      result += ":" + item.getData().getData();

    // save each attribute
    for (ItemAttr entry : attr.values()) result += " " + entry.toString();

    // save each flag
    for (ItemFlag flag : flags.values()) result += " " + flag.getKey();

    // return the result
    return result;
  }
Esempio n. 5
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;
  }
Esempio n. 6
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;
 }
Esempio n. 7
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");
    }
  }