public void addSign(StatSign sign) { switch (sign.getSignType()) { case TOP: topSigns.put(sign.getLocationString(), sign); break; case PERSONAL: personalSigns.put(sign.getLocationString(), sign); } }
/** * For all of the signs of this type * * @param ti TrackerInterface * @param statsigns List<StatSign> */ private void doTopSigns(TrackerInterface ti, List<StatSign> statsigns) { if (statsigns == null || statsigns.isEmpty()) return; /// Sort based on stattype Collections.sort( statsigns, new Comparator<StatSign>() { @Override public int compare(StatSign arg0, StatSign arg1) { if (arg0.getStatType() == null && arg1.getStatType() == null) return 0; else if (arg1.getStatType() == null) return -1; else if (arg0.getStatType() == null) return 1; return arg0.getStatType().compareTo(arg1.getStatType()); } }); /// Get the max length we need to query in the database for each stattype /// Once we have found the max, do an async update for the statsigns StatType st = statsigns.get(0).getStatType(); List<Stat> stats = new ArrayList<Stat>(); List<StatSign> update = new ArrayList<StatSign>(); int max = 0; int offset = 0; for (StatSign ss : statsigns) { if (ss.getStatType() != st) { /// Update signs if (st != null) updateSigns(ti, update, max, st, offset++); /// Reset variables st = ss.getStatType(); stats.clear(); update = new ArrayList<StatSign>(); max = 0; } update.add(ss); /// If size != prevsize, they have added or removed signs, coutn as a change int size = this.getUpDownCount(ss); Integer prevSize = prevSignCount.get(ss.getLocationString()); if (prevSize == null || prevSize != size) { prevSignCount.put(ss.getLocationString(), size); } if (max < size) { max = size; } } if (!update.isEmpty() && st != null) { updateSigns(ti, update, max, st, offset++); } }
public static boolean stillSign(StatSign o) { String l = o.getLocationString(); if (l == null) return false; try { Location loc = SerializerUtil.getLocation(l); if (loc == null) return false; Material mat = loc.getWorld().getBlockAt(loc).getType(); if (mat != Material.SIGN && mat != Material.SIGN_POST && mat != Material.WALL_SIGN) return false; } catch (Exception e) { return false; } return true; }
public void removeSignAt(Location location) { String l = StatSign.getLocationString(location); topSigns.remove(l); personalSigns.remove(l); }
public StatSign getStatSign(Location location) { String key = StatSign.getLocationString(location); if (personalSigns.containsKey(key)) return personalSigns.get(key); else return topSigns.get(key); }