ConfigValidated.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.gmail.nossr50.config;
  2. import com.gmail.nossr50.mcMMO;
  3. import java.io.File;
  4. import java.util.List;
  5. /**
  6. * This class is used for config files that validate their entries
  7. */
  8. public abstract class ConfigValidated extends Config implements DefaultKeys {
  9. /**
  10. * @param parentFolderPath Path to the "parent" folder on disk
  11. * @param relativePath Path to the config relative to the "parent" folder, this should mirror internal structure of resource files
  12. * @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load
  13. * @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path
  14. */
  15. public ConfigValidated(String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys)
  16. {
  17. super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults, removeOldKeys);
  18. validateEntries();
  19. }
  20. /**
  21. * @param parentFolderFile File for the "parent" folder on disk
  22. * @param relativePath Path to the config relative to the "parent" folder, this should mirror internal structure of resource files
  23. * @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load
  24. * @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path
  25. */
  26. public ConfigValidated(File parentFolderFile, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys)
  27. {
  28. super(parentFolderFile, relativePath, mergeNewKeys, copyDefaults, removeOldKeys);
  29. validateEntries();
  30. }
  31. /**
  32. * Prints all errors found when validating the config
  33. */
  34. private void validateEntries()
  35. {
  36. /*
  37. * Print Errors about Keys
  38. */
  39. List<String> validKeyErrors = validateKeys(); // Validate Keys
  40. if(validKeyErrors != null && validKeyErrors.size() > 0)
  41. {
  42. for(String error : validKeyErrors)
  43. {
  44. mcMMO.p.getLogger().severe(error);
  45. }
  46. }
  47. }
  48. }