Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. package spigot.headhunting.files;
  2.  
  3. /*
  4. * Spigot HeadHunting created by MisterFantasy on 23-7-2017
  5. */
  6.  
  7. import org.bukkit.configuration.file.YamlConfiguration;
  8. import spigot.headhunting.Main;
  9. import spigot.headhunting.utils.Util;
  10.  
  11. import java.io.File;
  12. import java.io.IOException;
  13.  
  14. public class FileHandler {
  15.  
  16. private Main plugin;
  17. private Util util;
  18.  
  19. private File langFile, levelFile, playerFile;
  20. private YamlConfiguration langConfiguration, levelConfiguration, playerConfiguration;
  21.  
  22. public FileHandler(Main plugin)
  23. {
  24. this.plugin = plugin;
  25. this.util = new Util(this.getPlugin());
  26.  
  27. this.langFile = new File(this.getPlugin().getDataFolder(), "lang.yml");
  28. this.langConfiguration = YamlConfiguration.loadConfiguration(this.langFile);
  29.  
  30. this.levelFile = new File(this.getPlugin().getDataFolder(), "levels.yml");
  31. this.levelConfiguration = YamlConfiguration.loadConfiguration(this.levelFile);
  32.  
  33. this.playerFile = new File(this.getPlugin().getDataFolder(), "playerdata.yml");
  34. this.playerConfiguration = YamlConfiguration.loadConfiguration(this.playerFile);
  35.  
  36. }
  37.  
  38. public void createFile()
  39. {
  40. File[] files = {this.getLangFile(), this.getLevelFile(), this.getPlayerFile()};
  41.  
  42. try {
  43. if (!this.getPlugin().getDataFolder().exists()) {
  44. this.getPlugin().getDataFolder().mkdirs();
  45. }
  46.  
  47. for (File file : files)
  48. {
  49. if (!file.exists()) {
  50. this.getUtil().log("The file " + file.getName() + " could not be found, creating!");
  51. this.saveDefaultConfig(file);
  52. }
  53. }
  54.  
  55. } catch (Exception e) {
  56. e.printStackTrace();
  57. }
  58. }
  59.  
  60. public void saveFile(File file, YamlConfiguration yamlConfiguration)
  61. {
  62. try {
  63. yamlConfiguration.save(file);
  64. this.getUtil().log("The file " + file.getName() + " has been saved!");
  65. } catch (IOException e) {
  66. this.getUtil().warn("File " + file.getName() + " could not be saved, printing stacktrace!");
  67. e.printStackTrace();
  68. }
  69. }
  70.  
  71. public void saveDefaultConfig(File file)
  72. {
  73. this.getPlugin().saveResource(file.getName(), false);
  74. }
  75.  
  76. public YamlConfiguration getLangConfiguration() {
  77. return langConfiguration;
  78. }
  79.  
  80. public File getLangFile() {
  81. return langFile;
  82. }
  83.  
  84. public YamlConfiguration getLevelConfiguration() {
  85. return levelConfiguration;
  86. }
  87.  
  88. public File getLevelFile() {
  89. return levelFile;
  90. }
  91.  
  92. public YamlConfiguration getPlayerConfiguration() {
  93. return playerConfiguration;
  94. }
  95.  
  96. public File getPlayerFile() {
  97. return playerFile;
  98. }
  99.  
  100. public Main getPlugin() {
  101. return plugin;
  102. }
  103.  
  104. public Util getUtil() {
  105. return util;
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement