Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.bukkit.pandemic.AutoBroadcast;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import org.bukkit.Server;
- import org.bukkit.event.Event;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.PluginLoader;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- public class AutoBroadcast extends JavaPlugin {
- public final ABPlayerListener playerMove = new ABPlayerListener(this);
- public File folder;
- public ArrayList<Integer> delays = new ArrayList<Integer>();
- public ArrayList<String> broadcasts = new ArrayList<String>();
- public AutoBroadcast(PluginLoader pluginLoader, Server instance,
- PluginDescriptionFile desc, File _folder, File plugin,
- ClassLoader cLoader) {
- super(pluginLoader, instance, desc, _folder, plugin, cLoader);
- folder = _folder;
- }
- @Override
- public void onDisable() {
- }
- @Override
- public void onEnable() {
- PluginManager pm = getServer().getPluginManager();
- pm.registerEvent(Event.Type.PLAYER_MOVE, playerMove, Event.Priority.Normal, this);
- if(!folder.exists()) {
- System.out.println("AutoBroadcast: Configuration folder doesn't exist. Creating...");
- folder.mkdir();
- System.out.println("AutoBroadcast: Complete.");
- }
- File config = new File(folder.getAbsolutePath() + File.separator + "broadcasts.txt");
- if (!config.exists())
- {
- System.out.print("AutoBroadcast: Broadcasts file doesn't exist. Creating...");
- try {
- config.createNewFile();
- System.out.println("AutoBroadcast: Completed.");
- } catch (IOException ex)
- {
- System.out.println("AutoBroadcast: Failed to create file.");
- }
- }
- if (loadBroadcasts()) {
- System.out.println("AutoBroadcast: Loaded broadcasts!");
- } else {
- System.out.println("AutoBroadcast: Failed to load broadcasts!");
- }
- }
- public boolean loadBroadcasts() {
- try {
- BufferedReader reader = new BufferedReader(new FileReader(folder.getAbsolutePath() + File.separator + "broadcasts.txt"));
- String line = reader.readLine();
- while (line != null) {
- String[] info = line.split(";");
- if (info.length == 3) {
- int delay = Integer.parseInt(info[0]);
- String color = info[1];
- String message = info[2];
- delays.add(delay);
- broadcasts.add("§"+color+message);
- }
- line = reader.readLine();
- }
- return true;
- }
- catch (Exception localException) {
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement