Advertisement
PerryPlaysMC

PluginConfiguration class

Jul 18th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. package plugin.goldengalaxy.co.managers;
  2.  
  3. import java.io.File;
  4.  
  5. import org.bukkit.configuration.file.YamlConfiguration;
  6. import org.bukkit.plugin.Plugin;
  7.  
  8. @SuppressWarnings("unused")
  9. public class PluginConfiguration {
  10.  
  11.     private Plugin plugin;
  12.     private File file, folder;
  13.     private YamlConfiguration config;
  14.  
  15.    
  16.     public PluginConfiguration(Plugin plugin, String FolderName, String FileName) {
  17.         this.folder = new File(plugin.getDataFolder(), FolderName);
  18.         this.plugin = plugin;
  19.        
  20.  
  21.  
  22.             try {
  23.                 this.folder.mkdir();
  24.             } catch (Exception e) {
  25.                 e.printStackTrace();
  26.             }
  27.             this.file = new File(this.folder, FileName + ".yml");
  28.             try {
  29.                 file.createNewFile();
  30.             } catch (Exception e) {
  31.                 e.printStackTrace();
  32.             }
  33.            
  34.         reloadConfig();
  35.  
  36.     }
  37.    
  38.     public PluginConfiguration(Plugin plugin, String FileName, boolean copy) {
  39.         this.plugin = plugin;
  40.         this.file = new File(plugin.getDataFolder(), FileName + ".yml");
  41.  
  42.         if(copy) {
  43.  
  44.             plugin.saveResource(file.getName(), true);
  45.  
  46.         } else {
  47.  
  48.             try {
  49.                 file.createNewFile();
  50.             } catch (Exception e) {
  51.  
  52.                 e.printStackTrace();
  53.  
  54.             }
  55.  
  56.         }
  57.         reloadConfig();
  58.  
  59.     }
  60.     public boolean exists(File pf) {
  61.         if(pf.exists()) {
  62.             return true;
  63.         }
  64.         else {
  65.             return false;
  66.         }
  67.        
  68.     }
  69.     public YamlConfiguration getConfig() {
  70.         return config;
  71.     }
  72.  
  73.     public void reloadConfig() {
  74.         config = YamlConfiguration.loadConfiguration(file);
  75.     }
  76.  
  77.     public void saveConfig() {
  78.  
  79.         try {
  80.             config.save(file);
  81.         } catch (Exception e) {
  82.             e.printStackTrace();
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement