Advertisement
Guest User

Untitled

a guest
Jul 1st, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.gmail.morha0;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.configuration.file.FileConfiguration;
  9. import org.bukkit.configuration.file.YamlConfiguration;
  10. import org.bukkit.plugin.Plugin;
  11. import org.bukkit.plugin.PluginDescriptionFile;
  12.  
  13. public class SettingsManager {
  14.  
  15.         private SettingsManager() { }
  16.        
  17.         static SettingsManager instance = new SettingsManager();
  18.        
  19.         public static SettingsManager getInstance() {
  20.                 return instance;
  21.         }
  22.        
  23.         Plugin p;
  24.        
  25.         FileConfiguration config;
  26.         File cfile;
  27.        
  28.         FileConfiguration data;
  29.         File dfile;
  30.        
  31.         public void setup(Plugin p) {
  32.                 cfile = new File(p.getDataFolder(), "config.yml");
  33.                 config = p.getConfig();
  34.                 //config.options().copyDefaults(true);
  35.                 //saveConfig();
  36.                
  37.                 if (!p.getDataFolder().exists()) {
  38.                         p.getDataFolder().mkdir();
  39.                 }
  40.                
  41.                 dfile = new File(p.getDataFolder(), "data.yml");
  42.                
  43.                 if (!dfile.exists()) {
  44.                         try {
  45.                                 dfile.createNewFile();
  46.                         }
  47.                         catch (IOException e) {
  48.                                 Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create data.yml!");
  49.                         }
  50.                 }
  51.                
  52.                 data = YamlConfiguration.loadConfiguration(dfile);
  53.         }
  54.        
  55.         public FileConfiguration getData() {
  56.                 return data;
  57.         }
  58.        
  59. //-----------------
  60. // add this for the set
  61.     public void set(String arg0, Object arg1) {
  62.         p.getConfig().set(arg0, arg1);
  63.     }
  64.  
  65. //--------------------
  66.         public void saveData() {
  67.                 try {
  68.                         data.save(dfile);
  69.                 }
  70.                 catch (IOException e) {
  71.                         Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save data.yml!");
  72.                 }
  73.         }
  74.        
  75.         public void reloadData() {
  76.                 data = YamlConfiguration.loadConfiguration(dfile);
  77.         }
  78.        
  79.         public FileConfiguration getConfig() {
  80.                 return config;
  81.         }
  82.        
  83.         public void saveConfig() {
  84.                 try {
  85.                         config.save(cfile);
  86.                 }
  87.                 catch (IOException e) {
  88.                         Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save config.yml!");
  89.                 }
  90.         }
  91.        
  92.         public void reloadConfig() {
  93.                 config = YamlConfiguration.loadConfiguration(cfile);
  94.         }
  95.        
  96.         public PluginDescriptionFile getDesc() {
  97.                 return p.getDescription();
  98.         }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement