Plugin Help txt files

Discussion in 'Plugin Help/Development/Requests' started by Takedown, Oct 22, 2014.

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

    Takedown

    So i recently made my first plugin. Its an auto broadcaster. It stores all messages in a txt file that is supposed to generate in a folder called "Broadcast" when you install the plugin but I dont know how to make this automatic. When i create the folder myself the plugin works and its awesome but I want it to create automatically.. can anyone give me the code to do that or help? thanks :D if you need I can include all the source code.
    Code:java
    1. package me.takedown.Broadcast;
    2.  
    3. import java.io.BufferedReader;
    4. import java.io.File;
    5. import java.io.FileInputStream;
    6. import java.io.FileReader;
    7. import java.io.IOException;
    8. import java.io.InputStreamReader;
    9. import java.io.LineNumberReader;
    10. import java.util.logging.Logger;
    11.  
    12. import org.bukkit.Bukkit;
    13. import org.bukkit.ChatColor;
    14. import org.bukkit.command.Command;
    15. import org.bukkit.command.CommandSender;
    16. import org.bukkit.entity.Player;
    17. import org.bukkit.plugin.PluginDescriptionFile;
    18. import org.bukkit.plugin.java.JavaPlugin;
    19.  
    20. public class Broadcast extends JavaPlugin {
    21. public static Broadcast plugin;
    22. public final Logger logger = Logger.getLogger("Minecraft");
    23. public static int currentLine = 0; // Line number of count
    24. public static int tid = 0;
    25. public static int running = 1;
    26. public static long interval = 10;
    27.  
    28.  
    29. @Override
    30. public void onDisable() {
    31. PluginDescriptionFile pdfFile = this.getDescription();
    32. this.logger.info(pdfFile.getName() + " is now disabled.");
    33.  
    34. }
    35.  
    36. @Override
    37. public void onEnable() {
    38. PluginDescriptionFile pdfFile = this.getDescription();
    39. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + "is enabled.");
    40.  
    41. tid = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    42. public void run() {
    43. try {
    44. broadcastMessages("plugins/Broadcast/messages.txt");
    45. } catch (IOException e) {
    46. }
    47. }
    48. }, 0, interval * 120);
    49.  
    50. }
    51.  
    52.  
    53. public static void broadcastMessages(String fileName) throws IOException {
    54. fs = new FileInputStream(fileName);
    55. for(int i = 0; i < currentLine; ++i)
    56. br.readLine();
    57. String line =br.readLine();
    58. line = line.replaceAll("&f", ChatColor.WHITE + "");
    59. line = line.replaceAll("&e", ChatColor.YELLOW + "");
    60. line = line.replaceAll("&d", ChatColor.LIGHT_PURPLE + "");
    61. line = line.replaceAll("&a", ChatColor.GREEN + "");
    62. Bukkit.getServer().broadcastMessage(ChatColor.LIGHT_PURPLE + "[Broadcast]" + ChatColor.WHITE + line);
    63. LineNumberReader lnr = new LineNumberReader(new FileReader(new File(fileName)));
    64. lnr.skip(Long.MAX_VALUE);
    65. int lastLine = lnr.getLineNumber();
    66. if(currentLine + 1 == lastLine + 1) {
    67. currentLine = 0;
    68. } else {
    69. currentLine++;
    70. }
    71. }
    72.  
    73. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    74.  
    75.  
    76. if (commandLabel.equalsIgnoreCase("stobroadcast")) {
    77. if(running == 1) {
    78. Bukkit.getServer().getScheduler().cancelTask(tid);
    79. Player player = (Player) sender;
    80. player.sendMessage("Cancelled broadcasts");
    81. running = 0;
    82. } else {
    83. Player player = (Player) sender;
    84. player.sendMessage("They aren't running!");
    85. }
    86. }
    87. else if (commandLabel.equalsIgnoreCase("startbroadcast")); {
    88. if(running == 1) {
    89. Player player = (Player) sender;
    90. player.sendMessage("They are still running!");
    91. } else {
    92. tid = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runable());
    93. public void run(); {
    94. try {
    95. broadcastMessages("plugins/Broadcast/messages.txt");
    96. } catch (IOException e) {
    97.  
    98.  
    99. }
    100. }, 0, interval * 120);
    101. Player player = (Player) sender
    102. player.sendMessage("Started broadcasts.");
    103. running = 1;
    104. }
    105. }
    106.  
    107. return false;
    108.  
    109. }
    110.  
    111. private void run() {
    112. // TODO Auto-generated method stub
    113.  
    114. }
    115. }
    116.  
    117.  
     
  2. Offline

    Gamecube762

  3. Offline

    Takedown

Thread Status:
Not open for further replies.

Share This Page