Juggles Posted May 3, 2017 Share Posted May 3, 2017 Right now I am using getPlayers().getAll().size(); But this only works for the whole loaded map. I scoured through the API but cannot find a method to return the number of players within a certain area. I am looking for a method that can do something similar to this: getPlayers().getAll(area).size(); Appreciate any help I can get Quote Link to comment Share on other sites More sharing options...
whipz Posted May 3, 2017 Share Posted May 3, 2017 public boolean checkforPlayers(Area area) { List<Player> playerss = players.getAll(); for (Player p : playerss) { if (area.contains(p) && !p.getName().equals(myPlayer().getName())) { return true; } } return false; } Quote Link to comment Share on other sites More sharing options...
TheWind Posted May 3, 2017 Share Posted May 3, 2017 if you want it in one line I think this might work: getPlayers().filter(player -> area.contains(player)).size(); 3 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted May 3, 2017 Share Posted May 3, 2017 (edited) 2 hours ago, TheWind said: if you want it in one line I think this might work: getPlayers().filter(player -> area.contains(player)).size(); this^ Remember that NPC and players only get loaded when they are in range. (+-16 tiles) This is different then gameobjects that get loaded together with the map chunks. Edited May 3, 2017 by Khaleesi 1 Quote Link to comment Share on other sites More sharing options...
Juggles Posted May 3, 2017 Author Share Posted May 3, 2017 8 hours ago, TheWind said: if you want it in one line I think this might work: getPlayers().filter(player -> area.contains(player)).size(); Thanks totally forgot about Lambda expression Quote Link to comment Share on other sites More sharing options...
Explv Posted May 3, 2017 Share Posted May 3, 2017 (edited) 9 hours ago, Juggles said: looking for a method that can do something similar to this: getPlayers().getAll(area).size(); 9 hours ago, TheWind said: if you want it in one line I think this might work: getPlayers().filter(player -> area.contains(player)).size(); I believe this would also work: getPlayers().filter(new AreaFilter(area)).size(); Edited May 3, 2017 by Explv 1 Quote Link to comment Share on other sites More sharing options...
liverare Posted May 3, 2017 Share Posted May 3, 2017 16 hours ago, TheWind said: if you want it in one line I think this might work: getPlayers().filter(player -> area.contains(player)).size(); If I'm going to do Lambda, I'll stay away from OSBot's filter and just use theirs: public final int countPlayers(Area area) { return (int) players.getAll().stream().filter(area::contains).count(); } Quote Link to comment Share on other sites More sharing options...