Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2017
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. public class ConfigManager {
  2.  
  3.     private ConfigManager() {}
  4.     private static ConfigManager manager = new ConfigManager();
  5.     public static ConfigManager getManager() {return manager;}
  6.  
  7.     private Main plugin = Main.getPlugin(Main.class);
  8.  
  9.     public FileConfiguration config;
  10.  
  11.     public File configfile;
  12.  
  13.     public void setupFiles() {
  14.         configfile = new File(plugin.getDataFolder(), "config.yml");
  15.  
  16.         if (!this.configfile.exists()) {
  17.             this.configfile.getParentFile().mkdirs();
  18.             plugin.saveResource("config.yml", false);
  19.         }
  20.  
  21.         this.config = new YamlConfiguration();
  22.  
  23.         try {
  24.             this.config.load(this.configfile);
  25.         } catch (IOException | InvalidConfigurationException e) {
  26.             e.printStackTrace();
  27.         }
  28.     }
  29.  
  30.     public FileConfiguration getConfig() {
  31.         return config;
  32.     }
  33.  
  34.  
  35.     public void saveConfig() {
  36.         try {
  37.             this.config.save(this.configfile);
  38.             Bukkit.getServer().getConsoleSender().sendMessage("Config.yml has been saved");
  39.         } catch (IOException e) {
  40.             Bukkit.getServer().getConsoleSender().sendMessage("Config.yml could not be saved");
  41.         }
  42.     }
  43.  
  44.     public void reloadConfig() {
  45.         this.config = YamlConfiguration.loadConfiguration(this.configfile);
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement