Exemplo n.º 1
0
 private static String getNeighborChestLoc(ShopChest lc) {
   Chest neighbor = lc.getNeighborChest();
   String lockey = null;
   if (neighbor != null) {
     lockey = KeyUtil.getStringLoc(neighbor);
   }
   return lockey;
 }
Exemplo n.º 2
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);
     }
   }
 }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
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;
  }
Exemplo n.º 5
0
  /** @param chest */
  public void removeDoubleChestFromShop(ShopChest chest) {

    String lockey = KeyUtil.getStringLoc(chest);
    String lockey2 = getNeighborChestLoc(chest);
    if (Defaults.DEBUG_LINKING)
      System.out.println("Shop::removeDoubleChest  " + chest + "    " + lockey + ":" + lockey2);
    chests_by_loc.remove(lockey);
    if (lockey2 != null) chests_by_loc.remove(lockey2);

    Set<Integer> itemids = chest.getItemIds();

    /// Otherwise remove all these item ids from shop
    for (Integer itemid : itemids) {
      Map<String, ShopChest> map = chests_by_itemid.get(itemid);
      if (map != null) {
        map.remove(lockey);
        if (lockey2 != null) map.remove(lockey2);
        if (map.size() <= 0) {
          chests_by_itemid.remove(itemid);
        }
      }
    }
  }