Advertisement
Choohan

Untitled

Nov 22nd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1.  
  2.   private FileConfiguration player;
  3.   private File playerf;
  4.  
  5.   public void onEnable()
  6.   {
  7.       // Define the plugin
  8.       plugin = this;
  9.      
  10.       // Create the file
  11.       createFiles();
  12. }
  13.   public void onDisable()
  14.   {
  15.    
  16.       saveDefaultConfig();
  17.      
  18.       // Prevent memmory from leeking
  19.       plugin = null;
  20.   }
  21.  
  22. // work like getConfig()
  23.   public FileConfiguration getPlayerConfig() {
  24.       return this.player;
  25.   }
  26.  
  27. // createFiles();
  28.   private void createFiles(){
  29.      
  30.       // Define player.yml
  31.       playerf = new File(getDataFolder(), "player.yml");
  32.      
  33.      
  34.       // Create player.yml
  35.       if(!playerf.exists()) {
  36.           playerf.getParentFile().mkdirs();
  37.           saveResource("player.yml", false);
  38.       }
  39.      
  40.       // Load player.yml
  41.       player = new YamlConfiguration();
  42.       try{
  43.           player.load(playerf);
  44.       } catch (IOException e){
  45.           e.printStackTrace();
  46.       } catch (InvalidConfigurationException e) {
  47.         // TODO Auto-generated catch block
  48.         e.printStackTrace();
  49.     }
  50.   }
  51.  
  52. // getPlayerConfigFile()
  53.   public File getPlayerConfigFile() {
  54.       return this.playerf;
  55.   }
  56.  
  57.  
  58. // After set config
  59. // Put this after the code that you load the config to set a value
  60. main.plugin.saveDefaultConfig();
  61.             try {
  62.                main.plugin.getLuckyNumberConfig().save(main.plugin.getLuckyNumberConfigFile());
  63.             } catch (IOException fpe) {
  64.                //Whatever you want to print/etc for error purposes
  65.             }
  66.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement