Example #1
0
  private void updateSigns(int itemid) {
    Map<String, ShopSign> signs = signs_by_itemid.get(itemid);
    if (signs == null || signs.size() == 0) return;

    Map<String, ShopChest> chests = new HashMap<String, ShopChest>();
    if (chests_by_itemid.containsKey(itemid)) chests.putAll(chests_by_itemid.get(itemid));
    if (chests_by_itemid.containsKey(Defaults.EVERYTHING_ID))
      chests.putAll(chests_by_itemid.get(Defaults.EVERYTHING_ID));

    if (chests == null || chests.size() == 0) {
      for (ShopSign sign : signs.values()) {
        sign.setUnlinked();
      }
    } else {
      ChestSet chestset = new ChestSet(itemid, chests.values());

      ItemStack is = ShopSign.getItemStackByShopID(itemid);
      int amount = chestset.amount(is);
      int free = chestset.amountFreeSpace(is);
      //			System.out.println("chests=" + is + "   amount=" + amount + "  free= " + free);
      for (ShopSign sign : signs.values()) {
        sign.setSignAmount(amount, free);
      }
    }
  }
Example #2
0
 public int getNumChestsAttachedToSign(ShopSign sign) {
   int itemid = sign.getItemId();
   int count = 0;
   count += chests_by_itemid.containsKey(itemid) ? chests_by_itemid.get(itemid).size() : 0;
   count +=
       chests_by_itemid.containsKey(Defaults.EVERYTHING_ID)
           ? chests_by_itemid.get(Defaults.EVERYTHING_ID).size()
           : 0;
   return count;
 }
Example #3
0
 public void removeSign(ShopSign ss) {
   String lockey = KeyUtil.getStringLoc(ss);
   signs_by_loc.remove(lockey);
   int itemid = ss.getItemId();
   Map<String, ShopSign> map = signs_by_itemid.get(itemid);
   if (map != null) {
     map.remove(lockey);
     if (map.size() <= 0) {
       signs_by_itemid.remove(itemid);
     }
   }
 }
Example #4
0
  public int addShopSign(ShopSign sign) {
    String key = KeyUtil.getStringLoc(sign);
    signs_by_loc.put(key, sign);
    int itemid = sign.getItemId();

    if (!signs_by_itemid.containsKey(itemid)) {
      signs_by_itemid.put(itemid, new HashMap<String, ShopSign>());
    }
    Map<String, ShopSign> ss = signs_by_itemid.get(itemid);
    ss.put(key, sign);
    int count = 0;
    count += chests_by_itemid.containsKey(itemid) ? chests_by_itemid.get(itemid).size() : 0;
    count +=
        chests_by_itemid.containsKey(Defaults.EVERYTHING_ID)
            ? chests_by_itemid.get(Defaults.EVERYTHING_ID).size()
            : 0;
    return count;
  }
Example #5
0
  public HashMap<String, Integer> addChest(ShopChest chest) {
    Set<Integer> itemids = chest.getItemIds();
    /// Trying to activate a chest with nothing in it, abort, everything_id is something and would
    // show up here
    if (itemids == null || itemids.isEmpty()) {
      return null;
    }
    Location cl = chest.getLocation();
    /// Somehow occasionally,
    for (ShopChest sc : chests_by_loc.values()) {
      if (!sc.getWorld().getName().equals(cl.getWorld().getName())) continue;
      int distance =
          (cl.getY() == sc.getY())
              ? (int) (Math.abs(cl.getX() - sc.getX()) + Math.abs(cl.getZ() - sc.getZ()))
              : Integer.MAX_VALUE;
      if (distance <= 1) {
        return null;
      }
    }
    String key = KeyUtil.getStringLoc(chest);
    chests_by_loc.put(key, chest);
    HashMap<String, Integer> itemname_count = new HashMap<String, Integer>();

    List<Integer> ids_with_signs = new ArrayList<Integer>();
    for (Integer id : itemids) {
      if (!chests_by_itemid.containsKey(id)) {
        chests_by_itemid.put(id, new HashMap<String, ShopChest>());
      }
      Map<String, ShopChest> c = chests_by_itemid.get(id);
      c.put(key, chest);
      final String cn = ShopSign.getCommonName(id);
      if (cn.isEmpty()) { // / As of 1.0.0 sometimes this is empty for some reason, figure out why
        System.err.println("Commonname id=" + id + "  location=" + chest.getLocation());
        continue;
      }
      if (signs_by_itemid.containsKey(id)) {
        ids_with_signs.add(id);
        itemname_count.put(cn, signs_by_itemid.get(id).size());
      } else {
        itemname_count.put(cn, 0);
      }
    }
    return itemname_count;
  }