Help with auto broadcasting system.

Discussion in 'Plugin Development' started by drillzy, Apr 23, 2017.

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

    drillzy

    Hello i would like to ask how to get my auto broadcasting system to advertise when there is players on only. here is my code.

    Code:
    publicintbroadcastnumber = 0;
    
    
    
    
    
    publicstatic Plugin plugin;
    
    
    public void Broadcasts() {
    
    
    final int time = getConfig().getInt("Time");
    
    
    Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Alerts.plugin, new Runnable() {
    
    public void run() {
    
    
    if (broadcastnumber == 0) {
    
    int broadcasts = getConfig().getStringList("Broadcasts").size();
    
    broadcastnumber = broadcasts;
    
    }
    
    
    String header = ChatColor.translateAlternateColorCodes('&', getConfig().getString("Header"));
    
    Bukkit.getServer().broadcastMessage(header);
    
    
    String message = ChatColor.translateAlternateColorCodes('&', getConfig().getStringList("Broadcasts").get(broadcastnumber - 1));
    
    Bukkit.getServer().broadcastMessage(message);
    
    
    String footer = ChatColor.translateAlternateColorCodes('&', getConfig().getString("Footer"));
    
    Bukkit.getServer().broadcastMessage(footer);
    
    
    broadcastnumber = broadcastnumber - 1;
    
    
    
    
    
    }
    
    },0, 20 * time);
    
    
    }
    
     
  2. Offline

    Zombie_Striker

    @drillzy
    1. Inside the task
    2. If the online player count is not equal to 0 (Bukkit.getOnlinePlayers().size() != 0 )
    3. broadcast the message.
     
  3. Offline

    drillzy

    sorry but i didn't fully understand you on where that code belongs to inside the code.
     
  4. Offline

    MrPowWow

    Add a repeating task in onEnable
    Make a random chance
    if chance = 1 {
    bukkit.broadcastMessage("1");
    }
    if chance = 2 {
    bukkit.broadcastMessage("2");
    }
    etc..
     
  5. Offline

    LittleUrso

    @drillzy I think he said:

    Do not run the task if there are no players online.
    Broadcast the message with Bukkit.broadcastMessage("message");
    And of course you should start the task on your onEnable.
     
  6. Offline

    TheHadDad

    if (Bukkit.getOnlinePlayers() != 0) {
    theschedueltaskname(); (which in this case is Broadcasts)
    }


    I think that's what he meant but you can arrange it differently. I'm not 100% sure but try it out anyway :).

    Does anyone know how you can make an arraylist for a few different scheduelers?
     
Thread Status:
Not open for further replies.

Share This Page