Trouble With Random Player Selector Variable

Discussion in 'Plugin Development' started by AaronL98, Jul 21, 2013.

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

    AaronL98

    I am trying to implement into my plugin where the plugin selects a random player when server is full and stores it in a variable so i can use the selected player's name in a broadcast, but when I broadcast the players name, instead of just saying their name, is says "CraftPlayer(name=AaronL98) ...rest of broadcast.
    Heres my random player selector code

    Code:java
    1.  
    2. if(Bukkit.getOnlinePlayers().length == Bukkit.getMaxPlayers()){
    3.  
    4. Player variable = Bukkit.getOnlinePlayers()[new Random().nextInt(Bukkit.getOnlinePlayers().length)];
    5. Bukkit.broadcastMessage(ChatColor.AQUA + "" + variable + " has been chosen bla bla bla!" );
    6. Bukkit.broadcastMessage(ChatColor.AQUA + "Game starting");
     
  2. Offline

    Shevchik

    Bukkit.broadcastMessage(ChatColor.AQUA + "" + variable.getName() + " has been chosen bla bla bla!" );
     
  3. Offline

    AaronL98

    Shevchik Thanks lol, never even noticed that ^.^

    Shevchik Oh, and also how could i add a scheduled loop which occurs every X seconds broadcasting a message?

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

    Shevchik

    Use bukkit schedulers.
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin,runnable,delayticks,repeatticks)
     
Thread Status:
Not open for further replies.

Share This Page