Advertisement
agentsix1

nothing to see here

May 13th, 2017
38,899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.09 KB | None | 0 0
  1.    
  2.     // Added the ability to have unlimited custom configs! - v0.8.5 - 2/15/2017
  3.     private FileConfiguration otherConfig = null; //customConfig
  4.     private File otherFiles = null; //customConfigFile
  5.    
  6.     public void reloadOther(String file) {
  7.         file = file.replace("\\", File.separator);
  8.         otherFiles = new File(getDataFolder(), file);
  9.         otherConfig = YamlConfiguration.loadConfiguration(otherFiles);
  10.         // Look for defaults in the jar
  11.         Reader defConfigStream;
  12.         InputStream is = null;
  13.         try {
  14.            
  15.             try {
  16.                 is = new FileInputStream(getDataFolder().toString() + file);
  17.             } catch (FileNotFoundException e) {
  18.                 e.printStackTrace();
  19.             }
  20.             defConfigStream = new InputStreamReader(is, "UTF8");
  21.        
  22.         if (defConfigStream != null) {
  23.             YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
  24.             otherConfig.setDefaults(defConfig);
  25.         }
  26.         } catch (UnsupportedEncodingException e) {
  27.             e.printStackTrace();
  28.         }
  29.     }
  30.    
  31.     public FileConfiguration getOther(String file) {
  32.         file = file.replace("\\", File.separator);
  33.         otherFiles = new File(getDataFolder(), file);
  34.         otherConfig = YamlConfiguration.loadConfiguration(otherFiles);
  35.         if (otherConfig == null) {
  36.             reloadOther(file);
  37.         }
  38.         return otherConfig;
  39.     }
  40.    
  41.     public void ssOther(String file, String path, Object value) {
  42.         file = file.replace("\\", File.separator);
  43.         getOther(file).set(path, value);
  44.         if (otherConfig == null || otherFiles == null) {
  45.             return;
  46.         }
  47.         try {
  48.             otherConfig.save(otherFiles);
  49.         } catch (IOException ex) {
  50.             getLogger().log(Level.SEVERE, "Could not save config to " + otherFiles, ex);
  51.         }
  52.         reloadOther(file);
  53.     }
  54.    
  55.     public void saveOther(String file) {
  56.         file = file.replace("\\", File.separator);
  57.         if (otherConfig == null || otherFiles == null) {
  58.             return;
  59.         }
  60.         try {
  61.             getOther(file).save(otherFiles);
  62.         } catch (IOException ex) {
  63.             getLogger().log(Level.SEVERE, "Could not save config to " + otherFiles, ex);
  64.         }
  65.     }
  66.     public void tcOther(String file, String type) {
  67.         file = file.replace("\\", File.separator);
  68.         switch (type) {
  69.         case "b":
  70.             if (!getOther(file).contains("blacklist")){
  71.                 ssOther(file, "blacklist.exampleuuid", null);
  72.             }
  73.             break;
  74.         case "i":
  75.             if (!getOther(file).contains("ignorelist")){
  76.                 ssOther(file, "ignorelist.exampleuuid", null);
  77.             }
  78.             break;
  79.         case "d":
  80.             if (!getOther(file).contains("Dictionary")){
  81.                 ssOther(file, "Dictionary.exampleword", null);
  82.             }
  83.             break;
  84.         default:
  85.             break;
  86.         }
  87.     }
  88.     public void saveDefaultOther(String file) {
  89.        
  90.         otherFiles = new File(getDataFolder(), file.replace("\\", File.separator));
  91.         otherConfig = YamlConfiguration.loadConfiguration(otherFiles);
  92.         if (otherFiles == null) {
  93.             otherFiles = new File(getDataFolder(), file);
  94.         }
  95.         if (file.contains("\\")) {
  96.             String temp_file = file.replace("\\", "/");
  97.             int i = 0;
  98.             String path = "";
  99.             for (String s : temp_file.split("/")) {
  100.                 i++;
  101.                 if (i != 1) {
  102.                     if (i != temp_file.split("/").length) {
  103.                         if (path.equalsIgnoreCase("")) { path = File.separator + s; } else { path = path + File.separator + s; }
  104.                     }  
  105.                 }
  106.             }
  107.             File path_file = new File(getDataFolder() + path);
  108.             if (!path_file.exists()) {
  109.                 path_file.mkdirs();
  110.             }
  111.         }
  112.         if (!otherFiles.exists()) {            
  113.             try {
  114.                 otherFiles.createNewFile();
  115.             } catch (IOException e) {
  116.                 //e.printStackTrace();
  117.             }
  118.          }
  119.     }
  120.    
  121.     public void delOther(String file) {
  122.         file = file.replace("\\", File.separator);
  123.         otherFiles = new File(getDataFolder(), file);
  124.         otherConfig = YamlConfiguration.loadConfiguration(otherFiles);
  125.         otherFiles.delete();
  126.     }
  127.    
  128.     //--- End unlimited custom configs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement