Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement