Bukkit getting 2 online players.

Discussion in 'Plugin Development' started by mrgreen33gamer, Feb 20, 2015.

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

    mrgreen33gamer

    Hi there,

    I need some help. I am trying to figure out how I can get only 2 online and forget the rest. Taking those 2 players and sending them into an Array. Does anyone know how I can do that? Just fetching 2 players out of all the other online players.
     
  2. Offline

    teej107

    What have you tried?
     
  3. Offline

    Monkey_Swag

    Player random = Bukkit.getOnlinePlayers()[new Random().nextInt(Bukkit.getOnlinePlayers().lenght)]
    You should be able to figure out the rest
     
  4. Offline

    mrgreen33gamer

    @Monkey_Swag What if it gets the same player?

    @teej107 Yeah I looked up a couple of topics, tried my own but there is nothing related to and is kinda hard to me.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 20, 2018
  5. Offline

    Monkey_Swag

    It's a simple extra conditional statement
     
  6. Offline

    TheEntropy

    @mrgreen33gamer Just check to see if you already have that player selected. If you get the same one again, just try again.
     
  7. Offline

    teej107

    That is only if he is using a version where it returns an array.
     
  8. Offline

    Monkey_Swag

    True, forgot CB 1.7.10 changed it to a collection. I personally use 1.7.9
     
  9. Offline

    teej107

    If it was up to me, I would just iterate through the online players and increment an integer for each iteration up until the integer is equal to the random number. Adding the online players to a collection may throw an error if you are using the wrong version and same with
    It might not be the most efficient but it'll work with 1.7.9 and 1.7.10
     
Thread Status:
Not open for further replies.

Share This Page