Brord icon

Untitled

Brord | PRO | 12/23/12 09:52:37 PM UTC | 0 ⭐ | 420 👁️ | Never ⏰ | []
Java 5 |

0 B

|

None

|

0 👍

/

0 👎

package net.castegaming.plugins.FPSCaste.config;
 
import java.io.File;
import java.io.IOException;
 
import net.castegaming.plugins.FPSCaste.FPSCaste;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
 
public class Config {
 
        public FPSCaste plugin;
 
        public Config(FPSCaste plugin) {
                this.plugin = plugin;
        }
 
        public FileConfiguration createConfig(String name) {
                if (!name.endsWith(".yml")) {
                        name = name + ".yml";
                }
                File file = new File(plugin.getDataFolder(),name);
                if (!file.exists()) {
                        plugin.getDataFolder().mkdir();
                        try {
                                file.createNewFile();
                        } catch (IOException e) {
                                e.printStackTrace();
                        }
                }
                return YamlConfiguration.loadConfiguration(file);// returns the newly created configuration object.
        }
 
        public void saveConfig(String name, FileConfiguration config) {
                if (!name.endsWith(".yml")) {
                        name = name + ".yml";
                }
                File file = new File(plugin.getDataFolder(),name);
                try {
                        config.save(file);
                } catch (IOException e) {
                        e.printStackTrace();
                }
        }
 
        public FileConfiguration getConfig(String name) {
            if (!name.endsWith(".yml")) {
                name = name + ".yml";
            }
            //createConfig(name);
            System.out.println(plugin);
            File file = new File(plugin.getDataFolder(),name);
            return YamlConfiguration.loadConfiguration(file); // file found, load into config and return it.
        }
        
        /******************************Player configs***************************************/
 
        public void createPlayerConfig(String name) {
            if (!name.endsWith(".yml")) {
                name = name + ".yml";
            }
            
            File file = new File(plugin.getDataFolder() + File.separator + "players", name);
            if (!file.exists()) {
                try {
                     file.createNewFile();
                } catch (IOException e) {
                      e.printStackTrace();
                }
            }
            FileConfiguration playerfile = getPlayerConfig(name);
            
            playerfile.set("class", "assault");
            playerfile.set("kills", 0);
            playerfile.set("deaths", 0);
            playerfile.set("assists", 0);
            playerfile.set("wins", 0);
            playerfile.set("losses", 0);
            
            savePlayerConfig(name, playerfile);
        }
        
        public void savePlayerConfig(String name, FileConfiguration config) {
            if (!name.endsWith(".yml")) {
                    name = name + ".yml";
            }
            File file = new File(plugin.getDataFolder() + File.separator + "players", name);
            try {
                    config.save(file);
            } catch (IOException e) {
                    e.printStackTrace();
            }
    }
 
    public FileConfiguration getPlayerConfig(String name) {
        if (!name.endsWith(".yml")) {
            name = name + ".yml";
        }
        
        File file = new File(plugin.getDataFolder() + File.separator + "players", name);
        return YamlConfiguration.loadConfiguration(file);
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎