lNockl

Config.java

Jul 9th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. package me.filipenock.sw.Utils;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import org.bukkit.configuration.file.YamlConfiguration;
  7.  
  8. import me.filipenock.sw.Main;
  9.  
  10. public class Config {
  11.    
  12.     private String path;
  13.     private File file;
  14.     private YamlConfiguration cfg;
  15.     private boolean savedefault;
  16.    
  17.     public Config(String path, boolean savedefault) {
  18.         this.path = path;
  19.         this.savedefault = savedefault;
  20.         this.file = new File(Main.main.getDataFolder()+"/"+path+".yml");
  21.         this.cfg = YamlConfiguration.loadConfiguration(this.file);
  22.         File folder = new File(Main.main.getDataFolder()+"/");
  23.         if (!folder.exists()) {
  24.             folder.mkdirs();
  25.         }
  26.         if (!this.file.exists()) {
  27.             if (this.savedefault) {
  28.                 Main.main.saveResource(path+".yml", true);
  29.             } else {
  30.                 try {
  31.                     this.file.createNewFile();
  32.                 } catch (IOException e) {
  33.                     e.printStackTrace();
  34.                 }
  35.             }
  36.         }
  37.         reload();
  38.     }
  39.     public void reload() {
  40.         this.file = new File(Main.main.getDataFolder()+"/"+path+".yml");
  41.         this.cfg = YamlConfiguration.loadConfiguration(this.file);
  42.     }
  43.    
  44.     public void save() {
  45.         try {
  46.             this.cfg.save(file);
  47.         } catch (IOException e) {
  48.             e.printStackTrace();
  49.         }
  50.         reload();
  51.     }
  52.    
  53.     public File getFile() {
  54.         return file;
  55.     }
  56.    
  57.     public void setFile(File file) {
  58.         this.file = file;
  59.     }
  60.  
  61.     public YamlConfiguration getCfg() {
  62.         return cfg;
  63.     }
  64.  
  65.     public void setCfg(YamlConfiguration cfg) {
  66.         this.cfg = cfg;
  67.     }
  68.  
  69. }
Add Comment
Please, Sign In to add comment