Access Online Players not working

Discussion in 'Spigot Plugin Development' started by Retrooper, Jun 12, 2019.

  1. Usually in some of my plugins I would want to be able to contact staff, or players with a certain permission, like (I'm on my phome btw atm)

    Method 1:
    Code (Text):

    for(Player staff : Bukkit.getOnlinePlayers()) {
        if(staff.hasPermission("")) {
    Method 2:
    Code (Text):

           if(staff.hasPermission("")) {
    I have tried both, for some reason they never work!
    No errors, Idk in console but I tried on my localhost server and a hosted server.

    Common Questions Answered:
    Is it your Bukkit API?
    No, it cannot be since I tried it on CraftBukkit and in Spigot API, 1.8 version, in past used to work now no more, idk why maybe I forgot something.

    Please help me, this is my first time making such a help thread a fast response would be appreciated!

    Edit: It was probably something in the class stopping this idk, doesn't matter!
    #1 Retrooper, Jun 12, 2019
    Last edited: Jun 17, 2019
  2. Hello,

    Your Method 1 should work. Your method 2 should also work, but you'll send a message to everybody (even without permission).
    I think it's a permission problem: you didn't add "" permission correctly to players.

    Did you test the 2nd method (without permission) ? You don't recieve message at all?
  3. I am sure I did, btw I was op and got no message, op have all permissions
  4. BGHDDevelopment


    Can you show the whole class, that code should work but it could be something in the class that could cause a issue.
  5. Choco


    • Winner Winner x 1
  6. Have you defined the permission in plugin.yml? If not, that could be the cause.
  7. You don't need to register permissions
  8. I cannot atm but can explain what I did,
    I made a separate class to contact staff called the reportmanager for the plugin and it had just this void method that takes in a player and a reason(report plugin).
    Then you call the method from another class and it should contact staff!
    I had ONLY that method in the class and nothing else, no constructor and no errors, everything works fine just that.
    I tried again but sending message through console say command and worked perfectly!
    I also tried contacting staff outside the reporterclass(where I needed it) for testing purposes and still didn't work...
    I'm very confused and annoyed that it's not working maybe I am doing a real stupid mistake.
  9. It's no command, it is accessed in a method so I don't think your response applies.
  10. What do I do then?
  11. **COUUUUUGH**
    Yo, ofcourse I tried that and no worked :/
    Don't do that cough thing :/
    The message was not displayed AT all and also then I tried using console to execute thebsay command and worked fine but I need to use something to message the staff, I am quite experienced in the API, it can be me forgetting something simple.
  12. I assume you've tried the above methods? Those are not working - They look okay to me; What errors do you get? If any?
  13. none
  14. That's odd.

    Works for me on 1.13+
  15. Choco


    Then the code to broadcast a message to players is not being reached. It would be much, much faster to help if you were to provide us with all relevant code. We can't keep guessing. The API isn't broken.
    • Agree Agree x 1
  16. This should be in Plugin Development
  17. Yeah... you're suggesting you tried several ways of sending a message and none of them worked. I guarantee all those methods DO work, and in fact it is something else in your code causing that part to not be called.
  18. Post your code when you are able to. We can't help you until then. Also, please make sure you post it using [code][/code] brackets so that it's legible.

    Lastly, don't triple post (especially if it's just to bump your thread), please use the Edit button instead.

Share This Page