Solved WhiteListing all players online

Discussion in 'Plugin Development' started by Ty Cleere, Apr 7, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Ty Cleere

    Ok i feel like i know this but i cant remember what it is :p What do i type to white list all of the current players on the server no matter what world they are in and save their names into the whitelist?

    Also how would i remove a player from the whitelist upon death and reload the whitelist?

    Thanks!
     
  2. Offline

    Glumpz

    To whitelist all online players:
    Code:java
    1. for(Player p : Bukkit.getOnlinePlayers())
    2. {
    3. p.setWhitelisted(true);
    4. }

    On death do:
    Code:java
    1. p.setWhitelisted(false);
     
    Ty Cleere and Konkz like this.
  3. Offline

    MordorKing78

  4. Offline

    Ty Cleere

    When i do this it whitelists all of the players that have ever logged on.. How do i fix that. There isnt an error or anything it just whitelists all of the players including me that have logged onto that world. I want only the current players online..



    When i do this it whitelists all of the players that have ever logged on.. How do i fix that. There isnt an error or anything it just whitelists all of the players including me that have logged onto that world. I want only the current players online..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    xMrPoi

    Maybe all the people that have ever joined are on at that time :O. You also have to turn whitelist on (just incase you hadn't already)
     
    Ty Cleere likes this.
  6. Offline

    Ty Cleere

    xMrPoi Nah haha i know they arent. and in my code i have it set so that it does that.
     
  7. Offline

    xMrPoi

    hmmm the Bukkit.getOnlinePlayers() returns an array of all online players. Not sure why this is happening.
     
  8. Offline

    Ty Cleere

    xMrPoi Thats why i am confuzed... here is the code im using..

    Code:java
    1. if (commandLabel.equalsIgnoreCase("wl-all")) {
    2. Bukkit.setWhitelist(true); // outside of the loop
    3. player.sendMessage(ChatColor.RED
    4. + "You have whitelisted all online players!");
    5. for (Player online : Bukkit.getOnlinePlayers()) {
    6. Bukkit.setWhitelist(true);
    7. online.setWhitelisted(true);
    8. // What is the code to add all players to the whitelist
    9. }
    10.  
    11.  
    12. }
     
  9. Offline

    xMrPoi

    take out the
    Code:java
    1. Bukkit.setWhitelist(true);
    out of the for loop
     
  10. Offline

    Ty Cleere

    xMrPoi I did have it outside the loop and i put it inside the loop to try it. ill change it and try again but i still had the problem when it was outside the loop.
     
  11. Offline

    xMrPoi

    Ty Cleere Did you forget to take the people off the whitelist? :p
     
  12. Offline

    Ty Cleere

    xMrPoi LOL you would think but no i cleared the whitelist and made sure it was empty and it still did it :(
     
  13. Offline

    xMrPoi

    Try getting rid of the Bukkit.setWhitelist(true);. Try enabling it through the default /whitelist command.
     
  14. Offline

    Ty Cleere

    xMrPoi I think i fixed it. I tried to clear the file and i just saved it like normal but i trie deleting the file and apatently it liked that. so ill see if that keeps working. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page