October 11, 20169 yr public boolean checkforPlayers(int area) { java.util.List<Player> playerss = players.getAll(); for (Player p : playerss) { if (myPlayer().getArea(area).contains(p) && !p.getName().equals(myPlayer().getName())) { return true; } } return false; } Returns true if there's players around your area. (excluding yourself) I use this generally like this: if(checkforPlayers(7) && random(0,25) == 0){ /* do world hop*/ }
October 11, 20169 yr Nitpicking, but performance-wise you could do this: EDIT: Do not use this, is 10x slower return (getPlayers().filter(n -> myPlayer().getArea(area).contains(n)).size() > 1); Edited October 11, 20169 yr by Abuse
October 11, 20169 yr Nitpicking, but performance-wise you could do this: return (getPlayers().filter(n -> myPlayer().getArea(area).contains(n)).size() > 1); Performance wise that's probably exact the same. It just looks more neat ^^
October 11, 20169 yr Performance wise that's probably exact the same. It just looks more neat ^^ It's no longer comparing strings nor reserving memory for the entire list, thats a slight performance benefit Edited October 11, 20169 yr by Abuse
October 11, 20169 yr It's no longer comparing strings nor reserving memory for the entire list, thats a slight performance benefit It gets converted to the exact same java byte code when its compiled. The only benefit is that it looks more neat ^^
October 11, 20169 yr It gets converted to the exact same java byte code when its compiled. The only benefit is that it looks more neat ^^ Nevermind, I take my suggestion back. After some testing it appears that filters are highly inefficient (300 ms vs 3000ms for 10000 loops)
October 11, 20169 yr Nevermind, I take my suggestion back. After some testing it appears that filters are highly inefficient (300 ms vs 3000ms for 10000 loops) Do remember though, at most there can be 2000 players on and therefore can at most be 2000 loops for it. And worst case probably like ~600 anyway. It looks neat asf so worth.
Create an account or sign in to comment