Mortem420

(ApplJuze) MyConfig

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