Get random online player

Discussion in 'Plugin Development' started by Sking3000, Dec 2, 2015.

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

    Sking3000

    hi all

    i am need to get random player from online players and the
    code is wrong someone can help me?

    (i am

    Code:
    package me.sking3000;
    
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
                                                   
    public class StartGame implements Runnable{
    
      
        public void run() {
          
          
              
              
                int i = new Random().nextInt(Bukkit.getServer().getOnlinePlayers().size());
                Player p = Bukkit.getServer().getOnlinePlayers().size()[i];
              
          
          
          
        }
    
    }


    thanx to all
    -sking3000
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Sking3000 In the second line use .get(i) instead of size
     
  3. Offline

    Sking3000

    i can put there only .getClass()
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Sking3000 You can turn it into a list first and use get on that.
     
  5. Offline

    Sking3000

    can u send me the code that i am need to use please?
     
  6. @Sking3000 No one will spoonfeed you. We will assist but not spoonfeed.
     
    Last edited: Dec 2, 2015
  7. Offline

    pokekart2014

    You have one extra "but". But yes, maybe not spoon-feed you, which means giving code directly, which you won't be learning anything from, but instead giving you hints and parts of code, which you can then search on this wonderful thing I am sure you have heard of. Google.
     
  8. Offline

    Scimiguy

    Dont need most of that

    Just do your getOnlinePlayers()
    Then on that use.get(new Random() etc....
     
  9. Offline

    TheNewTao

    Place the players online on a list, then use the Random class to get a random number, which would be the index, make sure the random number would be the same as the size of the getOnlinePlayers() size.
     
  10. Offline

    mcdorli

    Interesting, you noticed the the error. Most of the the people skip those. For example, please, read this post again slowly.
     
  11. Offline

    pokekart2014

    Yes... I see it. I am normally a person who doesn't like to have an error in their typing, and so, I naturally check other people's too... :)
     
  12. Offline

    Scimiguy

    Do you include grammatical errors in that?
     
Thread Status:
Not open for further replies.

Share This Page