May 3, 20178 yr 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
May 3, 20178 yr 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; }
May 3, 20178 yr if you want it in one line I think this might work: getPlayers().filter(player -> area.contains(player)).size();
May 3, 20178 yr 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, 20178 yr by Khaleesi
May 3, 20178 yr Author 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
May 3, 20178 yr 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, 20178 yr by Explv
May 3, 20178 yr 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(); }
Create an account or sign in to comment