Solved Random Player ?

Discussion in 'Plugin Development' started by Coopah, Apr 16, 2014.

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

    Coopah

    Hey, so I'm working on a arena plugin and I would like to get a random player.
    So I've set up a method that gets all the online players on the server, now how would I randomly select one of those players and teleport him to a different location. I know how to teleport I just want to get the random player.
    - Thanks in advance :)
     
  2. Offline

    werter318

    Are the players stored in a list? If so you can just get a random player like this: Player randomPlayer = players.get(random.nextInt(player.size());
     
  3. Offline

    Garris0n

  4. Offline

    Coopah

    werter318
    I'm using this method, for (Player playersALL : Bukkit.getServer().getOnlinePlayers()) {
    So I want the random the (playersALL).

    Bump

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

    GeorgeeeHD

    Coopah Coded in google chrome so small errors might be here:

    Code:java
    1. Random random = new Random();
    2. Player randomPlayer = Bukkit.getOnlinePlayers()[random.nextInt(Bukkit.getOnlinePlayers().length())];


    Not 100% sure if it works but im guessing it does xD
     
  6. Offline

    Coopah

    GeorgeeeHD
    Just figured out the error, but thanks anyways! :)
     
Thread Status:
Not open for further replies.

Share This Page