Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Added the ability to have unlimited custom configs! - v0.8.5 - 2/15/2017
- private FileConfiguration otherConfig = null; //customConfig
- private File otherFiles = null; //customConfigFile
- public void reloadOther(String file) {
- file = file.replace("\\", File.separator);
- otherFiles = new File(getDataFolder(), file);
- otherConfig = YamlConfiguration.loadConfiguration(otherFiles);
- // Look for defaults in the jar
- Reader defConfigStream;
- InputStream is = null;
- try {
- try {
- is = new FileInputStream(getDataFolder().toString() + file);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- defConfigStream = new InputStreamReader(is, "UTF8");
- if (defConfigStream != null) {
- YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
- otherConfig.setDefaults(defConfig);
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- }
- public FileConfiguration getOther(String file) {
- file = file.replace("\\", File.separator);
- otherFiles = new File(getDataFolder(), file);
- otherConfig = YamlConfiguration.loadConfiguration(otherFiles);
- if (otherConfig == null) {
- reloadOther(file);
- }
- return otherConfig;
- }
- public void ssOther(String file, String path, Object value) {
- file = file.replace("\\", File.separator);
- getOther(file).set(path, value);
- if (otherConfig == null || otherFiles == null) {
- return;
- }
- try {
- otherConfig.save(otherFiles);
- } catch (IOException ex) {
- getLogger().log(Level.SEVERE, "Could not save config to " + otherFiles, ex);
- }
- reloadOther(file);
- }
- public void saveOther(String file) {
- file = file.replace("\\", File.separator);
- if (otherConfig == null || otherFiles == null) {
- return;
- }
- try {
- getOther(file).save(otherFiles);
- } catch (IOException ex) {
- getLogger().log(Level.SEVERE, "Could not save config to " + otherFiles, ex);
- }
- }
- public void tcOther(String file, String type) {
- file = file.replace("\\", File.separator);
- switch (type) {
- case "b":
- if (!getOther(file).contains("blacklist")){
- ssOther(file, "blacklist.exampleuuid", null);
- }
- break;
- case "i":
- if (!getOther(file).contains("ignorelist")){
- ssOther(file, "ignorelist.exampleuuid", null);
- }
- break;
- case "d":
- if (!getOther(file).contains("Dictionary")){
- ssOther(file, "Dictionary.exampleword", null);
- }
- break;
- default:
- break;
- }
- }
- public void saveDefaultOther(String file) {
- otherFiles = new File(getDataFolder(), file.replace("\\", File.separator));
- otherConfig = YamlConfiguration.loadConfiguration(otherFiles);
- if (otherFiles == null) {
- otherFiles = new File(getDataFolder(), file);
- }
- if (file.contains("\\")) {
- String temp_file = file.replace("\\", "/");
- int i = 0;
- String path = "";
- for (String s : temp_file.split("/")) {
- i++;
- if (i != 1) {
- if (i != temp_file.split("/").length) {
- if (path.equalsIgnoreCase("")) { path = File.separator + s; } else { path = path + File.separator + s; }
- }
- }
- }
- File path_file = new File(getDataFolder() + path);
- if (!path_file.exists()) {
- path_file.mkdirs();
- }
- }
- if (!otherFiles.exists()) {
- try {
- otherFiles.createNewFile();
- } catch (IOException e) {
- //e.printStackTrace();
- }
- }
- }
- public void delOther(String file) {
- file = file.replace("\\", File.separator);
- otherFiles = new File(getDataFolder(), file);
- otherConfig = YamlConfiguration.loadConfiguration(otherFiles);
- otherFiles.delete();
- }
- //--- End unlimited custom configs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement