Advertisement
Guest User

PlayerConfig

a guest
Dec 28th, 2012
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. package me.KeybordPiano459.kEssentials.config;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.util.logging.Logger;
  7.  
  8. import me.KeybordPiano459.kEssentials.kEssentials;
  9.  
  10. import org.bukkit.configuration.file.FileConfiguration;
  11. import org.bukkit.configuration.file.YamlConfiguration;
  12.  
  13. public class PlayerConfig {
  14.     static kEssentials plugin;
  15.     public PlayerConfig(kEssentials plugin) {
  16.         PlayerConfig.plugin = plugin;
  17.     }
  18.    
  19.     public static FileConfiguration customConfig = null;
  20.     public static File customConfigFile = null;
  21.    
  22.     public static void reloadPlayerConfig(String player) {
  23.         if (customConfigFile == null) {
  24.             customConfigFile = new File(plugin.getDataFolder(), "playerdata/" + player + ".yml");
  25.         }
  26.         customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
  27.        
  28.         InputStream defConfigStream = plugin.getResource("playerdata/" + player + ".yml");
  29.         if (defConfigStream != null) {
  30.             YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
  31.             customConfig.setDefaults(defConfig);
  32.         }
  33.     }
  34.    
  35.     public static FileConfiguration getPlayerConfig(String player) {
  36.         if (customConfig == null) {
  37.             reloadPlayerConfig(player);
  38.         }
  39.         return customConfig;
  40.     }
  41.    
  42.     public static void savePlayerConfig(String player) {
  43.         if (customConfig == null || customConfigFile == null) {
  44.             return;
  45.         }
  46.        
  47.         try {
  48.             customConfig.save(customConfigFile);
  49.         } catch (IOException e) {
  50.             Logger.getLogger("Minecraft").severe("Could not save " + player + "'s config to the disk!");
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement