Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. package org.hcfpvp.base.util;
  2.  
  3. import org.bukkit.configuration.file.*;
  4. import org.bukkit.plugin.java.*;
  5. import java.io.*;
  6.  
  7. public class Config extends YamlConfiguration
  8. {
  9. private final String fileName;
  10. private final JavaPlugin plugin;
  11.  
  12. public Config(final JavaPlugin plugin, final String fileName) {
  13. this(plugin, fileName, ".yml");
  14. }
  15.  
  16. public Config(final JavaPlugin plugin, final String fileName, final String fileExtension) {
  17. this.plugin = plugin;
  18. this.fileName = String.valueOf(fileName) + (fileName.endsWith(fileExtension) ? "" : fileExtension);
  19. this.createFile();
  20. }
  21.  
  22. public String getFileName() {
  23. return this.fileName;
  24. }
  25.  
  26. public JavaPlugin getPlugin() {
  27. return this.plugin;
  28. }
  29.  
  30. private void createFile() {
  31. final File folder = this.plugin.getDataFolder();
  32. try {
  33. final File file = new File(folder, this.fileName);
  34. if (!file.exists()) {
  35. if (this.plugin.getResource(this.fileName) != null) {
  36. this.plugin.saveResource(this.fileName, false);
  37. }
  38. else {
  39. this.save(file);
  40. }
  41. this.load(file);
  42. }
  43. else {
  44. this.load(file);
  45. this.save(file);
  46. }
  47. }
  48. catch (Exception ex) {
  49. ex.printStackTrace();
  50. }
  51. }
  52.  
  53. public void save() {
  54. final File folder = this.plugin.getDataFolder();
  55. try {
  56. this.save(new File(folder, this.fileName));
  57. }
  58. catch (Exception ex) {
  59. ex.printStackTrace();
  60. }
  61. }
  62.  
  63. public boolean equals(final Object o) {
  64. if (this == o) {
  65. return true;
  66. }
  67. if (!(o instanceof Config)) {
  68. return false;
  69. }
  70. final Config config = (Config)o;
  71. Label_0057: {
  72. if (this.fileName != null) {
  73. if (this.fileName.equals(config.fileName)) {
  74. break Label_0057;
  75. }
  76. }
  77. else if (config.fileName == null) {
  78. break Label_0057;
  79. }
  80. return false;
  81. }
  82. if (this.plugin != null) {
  83. if (!this.plugin.equals((Object)config.plugin)) {
  84. return false;
  85. }
  86. }
  87. else if (config.plugin != null) {
  88. return false;
  89. }
  90. return true;
  91. }
  92.  
  93. public int hashCode() {
  94. int result = (this.fileName != null) ? this.fileName.hashCode() : 0;
  95. result = 31 * result + ((this.plugin != null) ? this.plugin.hashCode() : 0);
  96. return result;
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement