Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. package me.bman7842.slotlimiter.Managers;
  2.  
  3. import me.bman7842.slotlimiter.SlotLimiter;
  4. import org.bukkit.configuration.ConfigurationSection;
  5. import org.bukkit.configuration.file.FileConfiguration;
  6. import org.bukkit.configuration.file.YamlConfiguration;
  7.  
  8. import java.io.File;
  9. import java.util.List;
  10. import java.util.Set;
  11.  
  12. /**
  13. * Created by brand_000 on 8/2/2015.
  14. */
  15. public class ConfigManager {
  16.  
  17. File f;
  18. FileConfiguration config;
  19.  
  20. public ConfigManager(String path) {
  21. if (!SlotLimiter.getPlugin().getDataFolder().exists()) {
  22. SlotLimiter.getPlugin().getDataFolder().mkdir();
  23. }
  24.  
  25. f = new File(SlotLimiter.getPlugin().getDataFolder(), path+".yml");
  26.  
  27. if (!f.exists()) {
  28. try {
  29. f.createNewFile();
  30. } catch(Exception e) {
  31. e.printStackTrace();
  32. }
  33. }
  34.  
  35. config = YamlConfiguration.loadConfiguration(f);
  36. }
  37.  
  38. @SuppressWarnings("unchecked")
  39. public <T> T get(String path) {
  40. return (T) config.get(path);
  41. }
  42.  
  43. public List<String> getStringList(String path) { return config.getStringList(path); }
  44.  
  45. public List<Integer> getIntegerList(String path) {
  46. return config.getIntegerList(path);
  47. }
  48.  
  49. public Set<String> getKeys() {
  50. return config.getKeys(false);
  51. }
  52.  
  53. public void set(String path, Object value) {
  54. config.set(path, value);
  55. save();
  56. }
  57.  
  58. public ConfigurationSection getSection(String path) {
  59. return config.getConfigurationSection(path);
  60. }
  61.  
  62. public ConfigurationSection createSection(String path) {
  63. ConfigurationSection cs = config.createSection(path);
  64. save();
  65. return cs;
  66. }
  67.  
  68. public boolean contains(String path) {
  69. return config.contains(path);
  70. }
  71.  
  72. public void save() {
  73. try {
  74. config.save(f);
  75. } catch(Exception e) {
  76. e.printStackTrace();
  77. }
  78. }
  79.  
  80. public void addDefault(String path, Object value) {
  81. config.addDefault(path, value);
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement