Help with runnable broadcasting

Discussion in 'Plugin Development' started by ArthurMaker, Oct 8, 2013.

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

    ArthurMaker

    I'm making a broadcasting plugin with time, but it is not repeating, it just run one time! D:

    That is what I'm using this code in my Listener:

    Code:java
    1. public static Runnable broadcaster = new Runnable(){
    2. @Override
    3. public void run() {
    4.  
    5. YamlConfiguration config = new YamlConfiguration();
    6.  
    7. //=== [ LOAD CONFIG ] ===//
    8. File fileConfig = new File("plugins/Essenciais/broadcaster.yml");
    9. YamlConfiguration configPlayer = YamlConfiguration.loadConfiguration(fileConfig);
    10. config = configPlayer;
    11. //try {
    12. //config.save("plugins/Essenciais/broadcaster.yml");
    13. //} catch (IOException e) {
    14. // TODO Auto-generated catch block
    15. //e.printStackTrace();
    16. //}
    17. //======================================//
    18.  
    19. List<String> broadcasts = config.getStringList("Broadcasts.mensagens");
    20. Random msgs = new Random();
    21. int msg = msgs.nextInt(config.getInt("Broadcasts.maximo_msgs")-1);
    22. String prefix = config.getString("Broadcasts.prefix").replace("&", "§");
    23. String msgBroadcast = broadcasts.get(msg).replace("&", "§");
    24. if(msgBroadcast.contains("&newline")){
    25. String toBroadcast = prefix + ChatColor.RESET + " " + msgBroadcast.split("&newline");
    26. Bukkit.broadcastMessage(toBroadcast);
    27. }else{
    28. String toBroadcast = prefix + ChatColor.RESET + " " + msgBroadcast;
    29. Bukkit.broadcastMessage(toBroadcast);
    30. }
    31. broadcasts.clear();
    32. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(pl, HubListener.broadcaster, 0L, 20L);
    33. Bukkit.broadcastMessage("END");
    34. }
    35. };


    And I'm using this code in my "onEnable" in my Main to call the "broadcasting":
    Code:java
    1. this.getServer().getScheduler().scheduleSyncDelayedTask(this, HubListener.broadcaster, 20L);
     
  2. Offline

    Xerfox

    Could you format it so I can read it a bit better? Go into eclipse and do Control + Shift + F, and then post that code. Just a bit easier to read.
     
  3. Offline

    ArthurMaker

    Xerfox

    Code:java
    1. // ===================================================//
    2. public static Runnable broadcaster = new Runnable() {
    3. @Override
    4. public void run() {
    5.  
    6. YamlConfiguration config = new YamlConfiguration();
    7.  
    8. // === [ LOAD FILE ] ===//
    9. File fileConfig = new File("plugins/Essenciais/broadcaster.yml");
    10. YamlConfiguration configPlayer = YamlConfiguration
    11. .loadConfiguration(fileConfig);
    12. config = configPlayer;
    13. // ======================================//
    14.  
    15. List<String> broadcasts = config
    16. .getStringList("Broadcasts.mensagens");
    17. Random msgs = new Random();
    18. int msg = msgs.nextInt(config.getInt("Broadcasts.maximo_msgs") - 1);
    19. String prefixo = config.getString("Broadcasts.prefixo").replace(
    20. "&", "§");
    21. String msgBroadcast = broadcasts.get(msg).replace("&", "§");
    22. if (msgBroadcast.contains("&newline")) {
    23. String toBroadcast = prefixo + ChatColor.RESET + " "
    24. + msgBroadcast.split("&newline");
    25. Bukkit.broadcastMessage(toBroadcast);
    26. } else {
    27. String toBroadcast = prefixo + ChatColor.RESET + " "
    28. + msgBroadcast;
    29. Bukkit.broadcastMessage(toBroadcast);
    30. }
    31. broadcasts.clear();
    32. Bukkit.getServer()
    33. .getScheduler()
    34. .scheduleSyncRepeatingTask(pl, HubListener.broadcaster, 0L,
    35. 20L);
    36. }
    37. };
    38. // ===================================================//
     
Thread Status:
Not open for further replies.

Share This Page