Advertisement
Dudemister1999

PackagedFile class (Without logging)

Mar 27th, 2014
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. package test;
  2.  
  3. import java.io.File;
  4. import org.bukkit.configuration.file.YamlConfiguration;
  5. import org.bukkit.plugin.java.JavaPlugin;
  6.  
  7. public final class PackagedFile
  8. {
  9.     private String filename;
  10.     private File file;
  11.     private YamlConfiguration cfg;
  12.    
  13.     /**
  14.      * @param pl   The plugin, needed to get the folder.
  15.      * @param fileName    The file you want, OMIT .yml!
  16.      */
  17.     public PackagedFile(JavaPlugin pl, String fileName)
  18.     {
  19.         filename = fileName + ".yml";
  20.         file = new File(pl.getDataFolder(), filename);
  21.        
  22.         if(pl.getDataFolder().exists())
  23.         {
  24.             check(pl, file);
  25.         }
  26.         else
  27.         {
  28.             pl.getDataFolder().mkdir();
  29.             check(pl, file);
  30.         }
  31.     }
  32.    
  33.     private void check(JavaPlugin pl, File file)
  34.     {
  35.         if (file.exists())
  36.         {
  37.             cfg = YamlConfiguration.loadConfiguration(file);
  38.         }
  39.         else
  40.         {
  41.             cfg = YamlConfiguration.loadConfiguration(pl.getResource(filename));    
  42.         }
  43.     }
  44.    
  45.     /**
  46.      * @return The created YamlConfiguration
  47.      */
  48.     public YamlConfiguration getCFG()
  49.     {
  50.         return cfg;
  51.     }
  52.    
  53.     /**
  54.      * @return The name of the file
  55.      */
  56.     public String getFilename()
  57.     {
  58.         return filename;
  59.     }
  60.    
  61.     /**
  62.      * @return The file that the YamlConfiguration is saved in
  63.      */
  64.     public File getFile()
  65.     {
  66.         return file;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement