Advertisement
Guest User

Untitled

a guest
Apr 10th, 2022
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. public void registerYamlFile() {
  2. if (yamlConfiguration == null) {
  3. reloadYamlFile();
  4. }
  5. }
  6.  
  7. public void reloadYamlFile() {
  8. File dir = new File(directory);
  9. if (!dir.exists()) dir.mkdirs();
  10. file = new File(directory, name + ".yml");
  11. if (!file.exists()) {
  12. try {
  13. if (file.createNewFile()) {
  14. if (javaPlugin != null) {
  15. String localDirectory = "";
  16. if (!directory.equals(javaPlugin.getDataFolder().getPath())) {
  17. localDirectory = StringUtils.remove(directory, javaPlugin.getDataFolder().getPath());
  18. localDirectory = StringUtils.replace(localDirectory, File.separator, "/");
  19. localDirectory = StringUtils.removeStart(localDirectory, "/");
  20. localDirectory = localDirectory + "/";
  21. }
  22. if (javaPlugin.getResource( localDirectory + name + ".yml") != null) javaPlugin.saveResource(localDirectory + name + ".yml", true);
  23. }
  24. }
  25. } catch (IOException | IllegalArgumentException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29.  
  30. yamlConfiguration = new YamlConfiguration();
  31. try{
  32. yamlConfiguration.load(file);
  33. }catch(Exception e){
  34. e.printStackTrace();
  35. }
  36. // load global replacements
  37. if (contains("replacements.global") && yamlConfiguration.isConfigurationSection("replacements.global")) {
  38. for (String key:getConfigurationSection("replacements.global").getKeys(false)) {
  39. SimpleYaml.globalReplacements.put(key, getString("replacements.global." + key));
  40. }
  41. }
  42. // load local replacements
  43. if (contains("replacements.local") && yamlConfiguration.isConfigurationSection("replacements.local")) {
  44. for (String key:getConfigurationSection("replacements.local").getKeys(false)) {
  45. replacements.put(key, getString("replacements.local." + key));
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement