PageRenderTime 58ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/com/Geekpower14/Quake/Utils/InvSerialization/SerializationConfig.java

https://gitlab.com/Bl4ckSkull666/Quake
Java | 85 lines | 73 code | 12 blank | 0 comment | 3 complexity | 767b14c2f0ba6c5750434e7ad09d3c59 MD5 | raw file
  1. package com.Geekpower14.Quake.Utils.InvSerialization;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.logging.Level;
  5. import java.util.logging.Logger;
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.configuration.file.YamlConfiguration;
  8. public class SerializationConfig {
  9. private static YamlConfiguration config;
  10. protected SerializationConfig() {
  11. }
  12. public static File getDataFolder() {
  13. File pluginFolder = Bukkit.getServer().getPluginManager().getPlugins()[0].getDataFolder();
  14. return new File(pluginFolder.getParentFile() + "/TacoSerialization/");
  15. }
  16. public static File getConfigFile() {
  17. return new File(SerializationConfig.getDataFolder() + "/config.yml");
  18. }
  19. public static void reload() {
  20. config = YamlConfiguration.loadConfiguration((File)SerializationConfig.getConfigFile());
  21. SerializationConfig.setDefaults();
  22. SerializationConfig.save();
  23. Logger.getLogger("Minecraft").log(Level.INFO, "[TacoSerialization] Config reloaded");
  24. }
  25. public static void save() {
  26. try {
  27. config.save(SerializationConfig.getConfigFile());
  28. }
  29. catch (IOException e) {
  30. e.printStackTrace();
  31. }
  32. }
  33. private static void setDefaults() {
  34. SerializationConfig.addDefault("horse.color", true);
  35. SerializationConfig.addDefault("horse.inventory", true);
  36. SerializationConfig.addDefault("horse.jump-stength", true);
  37. SerializationConfig.addDefault("horse.style", true);
  38. SerializationConfig.addDefault("horse.variant", true);
  39. SerializationConfig.addDefault("living-entity.age", true);
  40. SerializationConfig.addDefault("living-entity.health", true);
  41. SerializationConfig.addDefault("living-entity.name", true);
  42. SerializationConfig.addDefault("living-entity.potion-effects", true);
  43. SerializationConfig.addDefault("ocelot.type", true);
  44. SerializationConfig.addDefault("player.ender-chest", true);
  45. SerializationConfig.addDefault("player.inventory", true);
  46. SerializationConfig.addDefault("player.stats", true);
  47. SerializationConfig.addDefault("player-stats.can-fly", true);
  48. SerializationConfig.addDefault("player-stats.display-name", true);
  49. SerializationConfig.addDefault("player-stats.exhaustion", true);
  50. SerializationConfig.addDefault("player-stats.exp", true);
  51. SerializationConfig.addDefault("player-stats.food", true);
  52. SerializationConfig.addDefault("player-stats.flying", true);
  53. SerializationConfig.addDefault("player-stats.health", true);
  54. SerializationConfig.addDefault("player-stats.level", true);
  55. SerializationConfig.addDefault("player-stats.potion-effects", true);
  56. SerializationConfig.addDefault("player-stats.saturation", true);
  57. SerializationConfig.addDefault("wolf.collar-color", true);
  58. }
  59. public static void addDefault(String path, Object value) {
  60. if (!SerializationConfig.getConfig().contains(path)) {
  61. SerializationConfig.getConfig().set(path, value);
  62. }
  63. }
  64. private static YamlConfiguration getConfig() {
  65. if (config == null) {
  66. SerializationConfig.reload();
  67. }
  68. return config;
  69. }
  70. public static boolean getShouldSerialize(String path) {
  71. return SerializationConfig.getConfig().getBoolean(path);
  72. }
  73. }