Advertisement
Guest User

Untitled

a guest
Jun 4th, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. package com.fraithor.phantomac.Util.File;
  2.  
  3. import com.fraithor.phantomac.PhantomAC;
  4. import org.bukkit.configuration.ConfigurationSection;
  5. import org.bukkit.configuration.file.YamlConfiguration;
  6.  
  7. import java.io.File;
  8. import java.io.InputStream;
  9. import java.io.InputStreamReader;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import java.util.Map;
  13.  
  14. public class FileBasics {
  15.  
  16. List<FILETYPE> types = new ArrayList<>();
  17.  
  18. public void load() {
  19. types.clear();
  20. for (FILETYPE type : FILETYPE.values()) {
  21. type.load();
  22. types.add(type);
  23. }
  24. }
  25.  
  26. public enum FILETYPE {
  27. CONFIG("config"),BANWAVE("banwave"),REPORTQUEUE("reportQueue");
  28.  
  29. private final String fileName;
  30. private final YamlConfiguration config = new YamlConfiguration();
  31. private final File file;
  32.  
  33. FILETYPE(String str) {
  34. this.fileName = str + ".yml";
  35. this.file = new File(PhantomAC.getInstance().getDataFolder(), fileName);
  36. }
  37.  
  38. //PUBLIC
  39. public String getString(String path) {
  40. if (config.isString(path))
  41. return config.getString(path);
  42. return "SOMETHING WENT WRONG";
  43. }
  44.  
  45. public boolean getBoolean(String path) {
  46. return config.getBoolean(path);
  47. }
  48.  
  49. public int getInt(String path) {
  50. return config.getInt(path);
  51. }
  52.  
  53. public List<String> getStringList(String path) {
  54. if (config.isList(path))
  55. return config.getStringList(path);
  56. return new ArrayList<>();
  57. }
  58.  
  59. public ConfigurationSection getConfigurationSection(String path) {
  60. return config.getConfigurationSection(path);
  61. }
  62.  
  63. public boolean isString(String path) {
  64. return config.isString(path);
  65. }
  66.  
  67. public boolean isList(String path) {
  68. return config.isList(path);
  69. }
  70.  
  71. public List<Map<?, ?>> getMapList(String path) {
  72. return config.getMapList(path);
  73. }
  74.  
  75. public YamlConfiguration getConfig() {
  76. return config;
  77. }
  78.  
  79. public File getFile() {
  80. return file;
  81. }
  82.  
  83. public void setValue(String path, Object value) {
  84. config.set(path, value);
  85. }
  86.  
  87. //PROCCESSING
  88. public void load() {
  89. if (!file.exists()) {
  90. PhantomAC.getInstance().saveResource(fileName, false);
  91. try {
  92. config.load(file);
  93. } catch (Exception e) {
  94. e.printStackTrace();
  95. }
  96. } else {
  97. try {
  98. config.load(file);
  99. final InputStream in = PhantomAC.getInstance().getResource(fileName);
  100. if (in != null) {
  101. config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(in)));
  102. config.options().copyDefaults(true);
  103. in.close();
  104. }
  105. config.save(file);
  106. } catch (Exception e) {
  107. e.printStackTrace();
  108. }
  109. }
  110. }
  111. }
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement