Advertisement
ZP4RKER

Config

Aug 19th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.41 KB | None | 0 0
  1. package com.zp4rker.zlevels.config;
  2. import java.io.File;
  3. import java.io.InputStream;
  4. import java.util.List;
  5. import java.util.Set;
  6.  
  7. import org.bukkit.configuration.ConfigurationSection;
  8. import org.bukkit.configuration.file.FileConfiguration;
  9. import org.bukkit.configuration.file.YamlConfiguration;
  10. import org.bukkit.plugin.java.JavaPlugin;
  11.  
  12. public class Config
  13. {
  14.     private int comments;
  15.     private ConfigManager manager;
  16.  
  17.     private File file;
  18.     private FileConfiguration config;
  19.  
  20.     public Config(InputStream configStream, File configFile, int comments, JavaPlugin plugin)
  21.     {
  22.         this.comments = comments;
  23.         this.manager = new ConfigManager(plugin);
  24.         this.file = configFile;
  25.         this.config = YamlConfiguration.loadConfiguration(configStream);
  26.     }
  27.  
  28.     public Object get(String path) {return this.config.get(path);}
  29.  
  30.     public Object get(String path, Object def) {return this.config.get(path, def);}
  31.  
  32.     public String getString(String path) {return this.config.getString(path);}
  33.  
  34.     public String getString(String path, String def) {return this.config.getString(path, def);}
  35.  
  36.     public int getInt(String path) {return this.config.getInt(path);}
  37.  
  38.     public int getInt(String path, int def) {return this.config.getInt(path, def);}
  39.  
  40.     public boolean getBoolean(String path) {return this.config.getBoolean(path);}
  41.  
  42.     public boolean getBoolean(String path, boolean def) {return this.config.getBoolean(path, def);}
  43.  
  44.     public void createSection(String path) {this.config.createSection(path);}
  45.  
  46.     public ConfigurationSection getConfigurationSection(String path) {return this.config.getConfigurationSection(path);}
  47.  
  48.     public double getDouble(String path) {return this.config.getDouble(path);}
  49.  
  50.     public double getDouble(String path, double def) {return this.config.getDouble(path, def);}
  51.  
  52.     public List<?> getList(String path) {return this.config.getList(path);}
  53.  
  54.     public List<?> getList(String path, List<?> def) {return this.config.getList(path, def);}
  55.  
  56.     public boolean contains(String path) {return this.config.contains(path);}
  57.  
  58.     public void removeKey(String path) {this.config.set(path, null);}
  59.  
  60.     public void set(String path, Object value) {this.config.set(path, value);}
  61.  
  62.     public void set(String path, Object value, String comment)
  63.     {
  64.         if(!this.config.contains(path))
  65.         {
  66.             this.config.set(manager.getPluginName() + "_COMMENT_" + comments, " " + comment);
  67.             comments++;
  68.         }
  69.         this.config.set(path, value);
  70.     }
  71.  
  72.     public void set(String path, Object value, String[] comment)
  73.     {
  74.         for(String comm : comment)
  75.         {
  76.             if(!this.config.contains(path))
  77.             {
  78.                 this.config.set(manager.getPluginName() + "_COMMENT_" + comments, " " + comm);
  79.                 comments++;
  80.             }
  81.         }
  82.         this.config.set(path, value);
  83.     }
  84.  
  85.     public void setHeader(String[] header)
  86.     {
  87.         manager.setHeader(this.file, header);
  88.         this.comments = header.length + 2;
  89.         this.reloadConfig();
  90.     }
  91.  
  92.     public void reloadConfig() {this.config = YamlConfiguration.loadConfiguration(manager.getConfigContent(file));}
  93.  
  94.     public void saveConfig()
  95.     {
  96.         String config = this.config.saveToString();
  97.         manager.saveConfig(config, this.file);
  98.     }
  99.  
  100.     public Set<String> getKeys() {return this.config.getKeys(false);}
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement