Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.filipenock.sw.Utils;
- import java.io.File;
- import java.io.IOException;
- import org.bukkit.configuration.file.YamlConfiguration;
- import me.filipenock.sw.Main;
- public class Config {
- private String path;
- private File file;
- private YamlConfiguration cfg;
- private boolean savedefault;
- public Config(String path, boolean savedefault) {
- this.path = path;
- this.savedefault = savedefault;
- this.file = new File(Main.main.getDataFolder()+"/"+path+".yml");
- this.cfg = YamlConfiguration.loadConfiguration(this.file);
- File folder = new File(Main.main.getDataFolder()+"/");
- if (!folder.exists()) {
- folder.mkdirs();
- }
- if (!this.file.exists()) {
- if (this.savedefault) {
- Main.main.saveResource(path+".yml", true);
- } else {
- try {
- this.file.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- reload();
- }
- public void reload() {
- this.file = new File(Main.main.getDataFolder()+"/"+path+".yml");
- this.cfg = YamlConfiguration.loadConfiguration(this.file);
- }
- public void save() {
- try {
- this.cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- reload();
- }
- public File getFile() {
- return file;
- }
- public void setFile(File file) {
- this.file = file;
- }
- public YamlConfiguration getCfg() {
- return cfg;
- }
- public void setCfg(YamlConfiguration cfg) {
- this.cfg = cfg;
- }
- }
Add Comment
Please, Sign In to add comment