Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. package us.vexillum.managers;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.configuration.file.YamlConfiguration;
  8.  
  9. import us.vexillum.logic.BattleProtection;
  10.  
  11. public class ConfigManager {
  12.  
  13. private static final String CONFIG = "config.yml";
  14. public static final String PLUGIN_PREFIX = "pluginPrefix";
  15. public static final String LOGGER_PREFIX = "loggerPrefix";
  16. public static final String LANGUAGE = "language";
  17. public static final String ENABLE_MYSQL = "enableMySQL";
  18. public static final String HOSTNAME = "hostname";
  19. public static final String PORTNUMBER = "portnumber";
  20. public static final String USERNAME = "username";
  21. public static final String PASSWORD = "password";
  22. public static final String DATABASE = "database";
  23.  
  24. private static ConfigManager instance;
  25. private static YamlConfiguration configuration;
  26. private static File file;
  27.  
  28. private ConfigManager() {
  29. try {
  30. file = new File(BattleProtection.getPluginFile(), CONFIG);
  31. configuration = new YamlConfiguration();
  32. reloadConfig();
  33. }
  34. catch (Exception e) {
  35. LoggerManager.logError(e.getMessage());
  36. }
  37. }
  38.  
  39. private YamlConfiguration getConfig() {
  40. return configuration;
  41. }
  42.  
  43. private static ConfigManager getInstance() {
  44. if(instance == null) {
  45. instance = new ConfigManager();
  46. }
  47. return instance;
  48. }
  49.  
  50. private static YamlConfiguration getConfiguration() {
  51. return getInstance().getConfig();
  52. }
  53.  
  54. private static void reloadConfig() throws Exception {
  55. configuration.load(file);
  56. }
  57.  
  58. private static String format(String string) {
  59. return ChatColor.translateAlternateColorCodes('&', string);
  60. }
  61.  
  62. public static void setValue(String key, Object value) {
  63. try {
  64. getConfiguration().set(key, value);
  65. getConfiguration().save(file);
  66. }
  67. catch (IOException e) {
  68. LoggerManager.logError(e.getMessage());
  69. }
  70. }
  71.  
  72. public static String getPluginPrefix() {
  73. return format(getConfiguration().getString(PLUGIN_PREFIX));
  74. }
  75.  
  76. public static String getLoggerPrefix() {
  77. return format(getConfiguration().getString(LOGGER_PREFIX));
  78. }
  79.  
  80. public static String getLanguage() {
  81. return getConfiguration().getString(LANGUAGE);
  82. }
  83.  
  84. public static boolean isEnableMySQL() {
  85. return configuration.getBoolean(ENABLE_MYSQL);
  86. }
  87.  
  88. public static String getHostname() {
  89. return getConfiguration().getString(HOSTNAME);
  90. }
  91.  
  92. public static String getPortnumber() {
  93. return getConfiguration().getString(PORTNUMBER);
  94. }
  95.  
  96. public static String getUsername() {
  97. return getConfiguration().getString(USERNAME);
  98. }
  99.  
  100. public static String getPassword() {
  101. return getConfiguration().getString(PASSWORD);
  102. }
  103.  
  104. public static String getDatabase() {
  105. return getConfiguration().getString(DATABASE);
  106. }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement