Advertisement
Brord

Untitled

Dec 23rd, 2012
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 3.53 KB | None | 0 0
  1. package net.castegaming.plugins.FPSCaste.config;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import net.castegaming.plugins.FPSCaste.FPSCaste;
  7. import org.bukkit.configuration.file.FileConfiguration;
  8. import org.bukkit.configuration.file.YamlConfiguration;
  9.  
  10. public class Config {
  11.  
  12.         public FPSCaste plugin;
  13.  
  14.         public Config(FPSCaste plugin) {
  15.                 this.plugin = plugin;
  16.         }
  17.  
  18.         public FileConfiguration createConfig(String name) {
  19.                 if (!name.endsWith(".yml")) {
  20.                         name = name + ".yml";
  21.                 }
  22.                 File file = new File(plugin.getDataFolder(),name);
  23.                 if (!file.exists()) {
  24.                         plugin.getDataFolder().mkdir();
  25.                         try {
  26.                                 file.createNewFile();
  27.                         } catch (IOException e) {
  28.                                 e.printStackTrace();
  29.                         }
  30.                 }
  31.                 return YamlConfiguration.loadConfiguration(file);// returns the newly created configuration object.
  32.         }
  33.  
  34.         public void saveConfig(String name, FileConfiguration config) {
  35.                 if (!name.endsWith(".yml")) {
  36.                         name = name + ".yml";
  37.                 }
  38.                 File file = new File(plugin.getDataFolder(),name);
  39.                 try {
  40.                         config.save(file);
  41.                 } catch (IOException e) {
  42.                         e.printStackTrace();
  43.                 }
  44.         }
  45.  
  46.         public FileConfiguration getConfig(String name) {
  47.             if (!name.endsWith(".yml")) {
  48.                 name = name + ".yml";
  49.             }
  50.             //createConfig(name);
  51.             System.out.println(plugin);
  52.             File file = new File(plugin.getDataFolder(),name);
  53.             return YamlConfiguration.loadConfiguration(file); // file found, load into config and return it.
  54.         }
  55.        
  56.         /******************************Player configs***************************************/
  57.  
  58.         public void createPlayerConfig(String name) {
  59.             if (!name.endsWith(".yml")) {
  60.                 name = name + ".yml";
  61.             }
  62.            
  63.             File file = new File(plugin.getDataFolder() + File.separator + "players", name);
  64.             if (!file.exists()) {
  65.                 try {
  66.                      file.createNewFile();
  67.                 } catch (IOException e) {
  68.                       e.printStackTrace();
  69.                 }
  70.             }
  71.             FileConfiguration playerfile = getPlayerConfig(name);
  72.            
  73.             playerfile.set("class", "assault");
  74.             playerfile.set("kills", 0);
  75.             playerfile.set("deaths", 0);
  76.             playerfile.set("assists", 0);
  77.             playerfile.set("wins", 0);
  78.             playerfile.set("losses", 0);
  79.            
  80.             savePlayerConfig(name, playerfile);
  81.         }
  82.        
  83.         public void savePlayerConfig(String name, FileConfiguration config) {
  84.             if (!name.endsWith(".yml")) {
  85.                     name = name + ".yml";
  86.             }
  87.             File file = new File(plugin.getDataFolder() + File.separator + "players", name);
  88.             try {
  89.                     config.save(file);
  90.             } catch (IOException e) {
  91.                     e.printStackTrace();
  92.             }
  93.     }
  94.  
  95.     public FileConfiguration getPlayerConfig(String name) {
  96.         if (!name.endsWith(".yml")) {
  97.             name = name + ".yml";
  98.         }
  99.        
  100.         File file = new File(plugin.getDataFolder() + File.separator + "players", name);
  101.         return YamlConfiguration.loadConfiguration(file);
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement