I need help please! Random Player Teleporter

Discussion in 'Spigot Plugin Development' started by ZevoGaems, May 4, 2017.

  1. I would like to have a feature where staff could enable a staff mode and get special features. I would like to make it so staff can click the rod and randomly teleport to a player. How would I make it so it teleport them to a completely random player?
     
  2. You create a Random object, which contains a nextInt(x, y) method. It gives you a random number between x (inclusive) and y (exclusive). x would always be 0, y would be the amount of players online.

    Say you have 10 players online, the method call would be random.nextInt(0, 10) which would return a number 0-9. 0 = player 1, 9 = player 10.
     
  3. Code (Java):
    Random rand = new Random();
    int index = rand.nextInt(Bukkit.getOnlinePlayers().size());
    Player p = Bukkit.getOnlinePlayers().get(index);
     
  4. Or you could just spoon feed. That's cool too.
     
  5. Thank you both so much I understand now :D