Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. package me.savvy.cb.other;
  2.  
  3. import me.savvy.cb.Core;
  4. import org.bukkit.configuration.file.FileConfiguration;
  5. import org.bukkit.configuration.file.YamlConfiguration;
  6.  
  7. import java.io.File;
  8. import java.io.IOException;
  9.  
  10. /**
  11. * Created by savit on 6/27/2017.
  12. */
  13. public class ConfigBuilder {
  14.  
  15. private String name;
  16. private File file;
  17. private FileConfiguration fc;
  18. public ConfigBuilder(String name, String path, String fileName) {
  19. this.name = name;
  20. try {
  21. file = new File(path + "/" + fileName);
  22. if (!(file.exists())) {
  23. file.getParentFile().mkdirs();
  24. file.createNewFile();
  25. }
  26. fc = YamlConfiguration.loadConfiguration(file);
  27. } catch(IOException ex) {
  28. Core.getInstance().getLogger().severe(String.format("Unable to generate configuration file '%s'", fileName));
  29. ex.printStackTrace();
  30. }
  31. }
  32.  
  33. public FileConfiguration getConfig() {
  34. return fc;
  35. }
  36.  
  37. public File getFile() {
  38. return file;
  39. }
  40.  
  41. public void saveConfig() {
  42. try {
  43. fc.save(file);
  44. Core.getInstance().getLogger().info(String.format("Successfully saved configuration file '%s'", file.getName()));
  45. } catch(IOException ex) {
  46. Core.getInstance().getLogger().severe(String.format("Unable to generate configuration file '%s'", file.getName()));
  47. ex.printStackTrace();
  48. }
  49. }
  50.  
  51. public void register() {
  52. if(!ConfigManager.hasConfig(name)) {
  53. ConfigManager.addConfig(name, this);
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement