Advertisement
Guest User

constructor

a guest
Aug 30th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. private FileConfiguration config;
  2. private File file;
  3. private TeamSkywars main;
  4.  
  5. public SettingsController(TeamSkywars main, String resourceName){
  6. this.main = main;
  7. this.file = new File(this.main.getDataFolder(), resourceName+".yml");
  8. this.config = new YamlConfiguration().loadConfiguration(this.file);
  9. InputStream readConfig = this.main.getResource(resourceName+".yml");
  10. YamlConfiguration setDefaults = new YamlConfiguration().loadConfiguration(readConfig);
  11. try {
  12.  
  13. if(!this.file.exists()){
  14.  
  15. this.config.addDefaults(setDefaults);
  16. this.config.options().copyDefaults(true);
  17. this.config.save(this.file);
  18. }else {
  19. this.config.load(this.file);
  20. }
  21.  
  22. } catch (Exception e) {
  23.  
  24. }
  25. }
  26.  
  27. public void sDefault(String path, String value){
  28. if(!config.contains(path)){
  29. config.set(path, value);
  30. save();
  31. }
  32. }
  33.  
  34. public void save(){
  35. try{
  36. this.config.save(this.file);
  37. }catch(Exception e){
  38.  
  39. }
  40. }
  41.  
  42. public FileConfiguration getConfig(){
  43. return config;
  44. }
  45.  
  46. public File getFile(){
  47. return file;
  48. }
  49.  
  50. public String get(String path){
  51. return org.bukkit.ChatColor.translateAlternateColorCodes('&', config.getString(path));
  52. }
  53. public int getint(String path){
  54. return config.getInt(path);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement