private static String getNeighborChestLoc(ShopChest lc) { Chest neighbor = lc.getNeighborChest(); String lockey = null; if (neighbor != null) { lockey = KeyUtil.getStringLoc(neighbor); } return lockey; }
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; }
/** @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); } } } }