public Monster getMostAggroInPanel(Point p) { Monster monster = null; Monster mostAggroMonster = null; double mostAggro = 0; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (!monster.getName().equals("Pig") && !monster.getName().equals("BlueThorn") && !monster.getName().equals("VineThorn")) { if (monster.getIsInPanel()) { double distance = p.distance(monster.getCenterPoint()); if (monster.getPlayerDamage() > mostAggro) { mostAggroMonster = monster; mostAggro = monster.getPlayerDamage(); } } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } return mostAggroMonster; }
public Monster getClosestWithinMax(Point p, int r) { Monster monster = null; Monster closestMonster = null; double closestDistance = 0; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (!monster.getName().equals("Pig") && !monster.getName().equals("BlueThorn") && !monster.getName().equals("VineThorn")) { if (monster.getIsInPanel()) { double distance = p.distance(monster.getCenterPoint()); if ((distance < closestDistance || closestDistance == 0) && distance <= r) { closestMonster = monster; closestDistance = distance; } } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } return closestMonster; }