Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. package me.imelvin.bungeecore;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import net.md_5.bungee.api.ProxyServer;
  7. import net.md_5.bungee.api.plugin.Plugin;
  8. import net.md_5.bungee.config.Configuration;
  9. import net.md_5.bungee.config.ConfigurationProvider;
  10. import net.md_5.bungee.config.YamlConfiguration;
  11.  
  12. public class ConfigManager {
  13. boolean isSetup = false;
  14. static ConfigManager instance = new ConfigManager();
  15. File cfile;
  16. Configuration config;
  17. YamlConfiguration prov = (YamlConfiguration) ConfigurationProvider.getProvider(YamlConfiguration.class);
  18.  
  19. public static ConfigManager getInstance() {
  20. return instance;
  21. }
  22.  
  23. public void setup(Plugin p) {
  24. if (!p.getDataFolder().exists()) {
  25. p.getDataFolder().mkdirs();
  26. }
  27.  
  28. cfile = new File(p.getDataFolder(), "config.yml");
  29. if (!cfile.exists()) {
  30. try {
  31. cfile.createNewFile();
  32. } catch (IOException e) {
  33. ProxyServer.getInstance().getLogger().info("Trilar Core >> Could not create config.yml");
  34. }
  35. }
  36. try {
  37. config = prov.load(new File(p.getDataFolder(), "config.yml"));
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. if (this.config.get("settings.talkInStaffChat") == null) {
  42. this.config.set("settings.talkInStaffChat", "!");
  43. }
  44. if (this.config.get("settings.banMessage") == null) {
  45. this.config.set("settings.banMessage", "&cYou cannot join as you have been banned for: \n%reason%");
  46. }
  47. if (this.config.get("settings.kickOnWarn") == null) {
  48. this.config.set("settings.kickOnWarn", true);
  49. }
  50. if (this.config.get("settings.database.hostname") == null) {
  51. this.config.set("settings.database.hostname", "test.nl");
  52. }
  53. if (this.config.get("settings.database.port") == null) {
  54. this.config.set("settings.database.port", 3306);
  55. }
  56. if (this.config.get("settings.database.database") == null) {
  57. this.config.set("settings.database.database", "test");
  58. }
  59. if (this.config.get("settings.database.username") == null) {
  60. this.config.set("settings.database.username", "test");
  61. }
  62. if (this.config.get("settings.database.password") == null) {
  63. this.config.set("settings.database.password", "test");
  64. }
  65. saveConfig();
  66. isSetup = true;
  67. }
  68.  
  69.  
  70. public void saveConfig() {
  71. try {
  72. prov.save(config, cfile);
  73. } catch (IOException e) {
  74. e.printStackTrace();
  75. }
  76. }
  77.  
  78. public Configuration getConfig() {
  79. return this.config;
  80. }
  81.  
  82. public void reloadConfig() {
  83. try {
  84. config = prov.load(cfile);
  85. Main.init();
  86. } catch (IOException e) {
  87. e.printStackTrace();
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement