Looping Through all the players and checking them

Discussion in 'Spigot Plugin Development' started by ZevoGaems, May 2, 2017.

  1. I am making a custom ban plugin. I need to loop through all of the online players so it can check all of the people and check them for the permission so when they get kicked it notifies them about the action. I need it to loop through all of the players but I need a variable so I can do if(variable.hasPermission("minegrid.notify")) how could I do this?
     
  2. Code (Java):

    Collection<Object> collection;

    for (Object object : collection) {
     if (object.methodA()) {
       object.methodB();
     }
    }
     
     
  3. You can only bump every 24 hours.
     
  4. Oh ok I didn't know that
     
  5. Even though I don't like to spoon feed people, I feel like you don't know basic java and basic Bukkit/Spigot API.

    Code (Text):
    For (Player player : Bukkit.getServer().getOnlinePlayers()) {
        if (!player.hasPermission("bland.permission") {
            //Do Desired Stuff
        }
    }
     
  6. Code (Java):

    Bukkit.getOnlinePlayers().stream().filter(player -> player.hasPermission("example.permissions")).forEach(player -> player.sendMessage("Hi"));
     
    java 8 stream api.

    filters the collection, if the player object has permission "example.permission", for each of those objects having met that criteria, it'll send them a message saying "Hi"
     
    • Like Like x 1
  7. Code (Java):

    Bukkit.broadcast("example.permission", "Hi");
     
     
    • Optimistic Optimistic x 1
  8. not necessarily aimed towards that function itself, but to show how to utilize the stream api to accomplish such a task like the OP intends.
     
    • Like Like x 1
    • Creative Creative x 1