ConfigLoader.java 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.gmail.nossr50.config;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import org.bukkit.configuration.file.FileConfiguration;
  5. import com.gmail.nossr50.mcMMO;
  6. public abstract class ConfigLoader {
  7. protected static File configFile;
  8. protected static File dataFolder;
  9. protected final mcMMO plugin;
  10. protected static FileConfiguration config;
  11. public ConfigLoader(mcMMO plugin, String fileName){
  12. this.plugin = plugin;
  13. dataFolder = plugin.getDataFolder();
  14. configFile = new File(dataFolder, File.separator + fileName);
  15. }
  16. /**
  17. * Load this config file.
  18. */
  19. protected abstract void load();
  20. /**
  21. * Save this config file.
  22. */
  23. private static void saveConfig() {
  24. try {
  25. config.save(configFile);
  26. }
  27. catch (IOException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31. /**
  32. * Add the defaults to this config file.
  33. */
  34. protected void addDefaults() {
  35. // Load from included config.yml
  36. config.options().copyDefaults(true);
  37. saveConfig();
  38. }
  39. /**
  40. * Load the keys from this config file.
  41. */
  42. protected abstract void loadKeys();
  43. }