コード例 #1
0
ファイル: StockItem.java プロジェクト: JRsz/dtlTraders
  /** @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;
  }
コード例 #2
0
ファイル: StockItem.java プロジェクト: JRsz/dtlTraders
 /**
  * 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);
   }
 }
コード例 #3
0
ファイル: StockItem.java プロジェクト: JRsz/dtlTraders
  /**
   * 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;
  }
コード例 #4
0
ファイル: StockItem.java プロジェクト: JRsz/dtlTraders
  /**
   * 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;
  }
コード例 #5
0
ファイル: StockItem.java プロジェクト: JRsz/dtlTraders
  /**
   * 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;
  }
コード例 #6
0
ファイル: StockItem.java プロジェクト: JRsz/dtlTraders
 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;
 }
コード例 #7
0
ファイル: StockItem.java プロジェクト: JRsz/dtlTraders
  /**
   * 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");
    }
  }