Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.thebmanswan541;
- import java.io.File;
- import java.io.IOException;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.PluginDescriptionFile;
- public class SettingsManager {
- private SettingsManager() { }
- static SettingsManager instance = new SettingsManager();
- public static SettingsManager getInstance() {
- return instance;
- }
- Plugin p;
- FileConfiguration config;
- File cfile;
- FileConfiguration admin;
- File admins;
- FileConfiguration mod;
- File mods;
- FileConfiguration helper;
- File helpers;
- FileConfiguration mute;
- File muted;
- FileConfiguration ban;
- File banned;
- public void setup(Plugin p) {
- cfile = new File(p.getDataFolder(), "config.yml");
- config = p.getConfig();
- config.options().copyDefaults(true);
- saveConfig();
- admins = new File(p.getDataFolder(), "admins.yml");
- mods = new File(p.getDataFolder(), "mods.yml");
- helpers = new File(p.getDataFolder(), "helpers.yml");
- muted = new File(p.getDataFolder(), "muted.yml");
- banned = new File(p.getDataFolder(), "banned.yml");
- if (!admins.exists()) {
- try {
- admins.createNewFile();
- }
- catch (IOException e) {
- Bukkit.getServer().getLogger().severe("Could not create admins.yml!");
- }
- }
- if (!mods.exists()) {
- try {
- mods.createNewFile();
- }
- catch (IOException e) {
- Bukkit.getServer().getLogger().severe("Could not create mods.yml!");
- }
- }
- if (!helpers.exists()) {
- try {
- helpers.createNewFile();
- }
- catch (IOException e) {
- Bukkit.getServer().getLogger().severe("Could not create helpers.yml!");
- }
- }
- if (!muted.exists()) {
- try {
- muted.createNewFile();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (!banned.exists()) {
- try{
- banned.createNewFile();
- }
- catch(IOException e) {
- e.printStackTrace();
- }
- }
- admin = YamlConfiguration.loadConfiguration(admins);
- mod = YamlConfiguration.loadConfiguration(mods);
- helper = YamlConfiguration.loadConfiguration(helpers);
- mute = YamlConfiguration.loadConfiguration(muted);
- ban = YamlConfiguration.loadConfiguration(banned);
- }
- public FileConfiguration getAdmins() {
- return admin;
- }
- public FileConfiguration getMods() {
- return mod;
- }
- public FileConfiguration getHelpers() {
- return helper;
- }
- public FileConfiguration getMuted() {
- return mute;
- }
- public FileConfiguration getBanned() {
- return ban;
- }
- public void saveAdmins() {
- try {
- admin.save(admins);
- }
- catch (IOException e) {
- Bukkit.getServer().getLogger().severe("Could not save admins.yml!");
- }
- }
- public void saveMods() {
- try {
- mod.save(mods);
- }
- catch (IOException e) {
- Bukkit.getServer().getLogger().severe("Could not save mods.yml!");
- }
- }
- public void saveHelpers() {
- try {
- helper.save(helpers);
- }
- catch (IOException e) {
- Bukkit.getServer().getLogger().severe("Could not save helpers.yml!");
- }
- }
- public void saveMuted() {
- try {
- mute.save(muted);
- }
- catch(IOException e) {
- e.printStackTrace();
- }
- }
- public void saveBanned() {
- try {
- ban.save(banned);
- }
- catch(IOException e) {
- e.printStackTrace();
- }
- }
- public void reloadAdmins() {
- admin = YamlConfiguration.loadConfiguration(admins);
- }
- public void reloadMods() {
- mod = YamlConfiguration.loadConfiguration(mods);
- }
- public void reloadHelpers() {
- helper = YamlConfiguration.loadConfiguration(helpers);
- }
- public void reloadMuted() {
- mute = YamlConfiguration.loadConfiguration(muted);
- }
- public void reloadBanned() {
- ban = YamlConfiguration.loadConfiguration(banned);
- }
- public FileConfiguration getConfig() {
- return config;
- }
- public void saveConfig() {
- try {
- config.save(cfile);
- }
- catch (IOException e) {
- Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save config.yml!");
- }
- }
- public void reloadConfig() {
- config = YamlConfiguration.loadConfiguration(cfile);
- }
- public PluginDescriptionFile getDesc() {
- return p.getDescription();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment