[1.8] How to get amount of players per world

Discussion in 'Spigot Plugin Development' started by iTweakz, Jun 1, 2017.

Thread Status:
Not open for further replies.
  1. Yes so how to get amount of players per world ?
     
  2. Code (Text):
    Map<World, List<Player>> groupByWorld =
                Bukkit.getOnlinePlayers().stream().collect(Collectors.groupingBy(Player::getWorld));
    Code (Text):
    Map<World, Long> groupByWorld =
                Bukkit.getOnlinePlayers().stream().collect(Collectors.groupingBy(Player::getWorld,Collectors.counting()));
    Edit: Java 8 only
    https://www.mkyong.com/java8/java-8-collectors-groupingby-and-mapping-example/
     
    #2 ysl3000, Jun 1, 2017
    Last edited: Jun 1, 2017
    • Agree Agree x 1
  3. A better way
    Code (Text):

        for(World w : Bukkit.getWorlds())
         {
           Bukkit.broadcastMessage("World, " + w.getName() + ", has " + w.getPlayers().size() + " online.");
         }
     
     
    • Agree Agree x 3
    • Like Like x 1
Thread Status:
Not open for further replies.