Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package spigot.headhunting.files;
- /*
- * Spigot HeadHunting created by MisterFantasy on 23-7-2017
- */
- import org.bukkit.configuration.file.YamlConfiguration;
- import spigot.headhunting.Main;
- import spigot.headhunting.utils.Util;
- import java.io.File;
- import java.io.IOException;
- public class FileHandler {
- private Main plugin;
- private Util util;
- private File langFile, levelFile, playerFile;
- private YamlConfiguration langConfiguration, levelConfiguration, playerConfiguration;
- public FileHandler(Main plugin)
- {
- this.plugin = plugin;
- this.util = new Util(this.getPlugin());
- this.langFile = new File(this.getPlugin().getDataFolder(), "lang.yml");
- this.langConfiguration = YamlConfiguration.loadConfiguration(this.langFile);
- this.levelFile = new File(this.getPlugin().getDataFolder(), "levels.yml");
- this.levelConfiguration = YamlConfiguration.loadConfiguration(this.levelFile);
- this.playerFile = new File(this.getPlugin().getDataFolder(), "playerdata.yml");
- this.playerConfiguration = YamlConfiguration.loadConfiguration(this.playerFile);
- }
- public void createFile()
- {
- File[] files = {this.getLangFile(), this.getLevelFile(), this.getPlayerFile()};
- try {
- if (!this.getPlugin().getDataFolder().exists()) {
- this.getPlugin().getDataFolder().mkdirs();
- }
- for (File file : files)
- {
- if (!file.exists()) {
- this.getUtil().log("The file " + file.getName() + " could not be found, creating!");
- this.saveDefaultConfig(file);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void saveFile(File file, YamlConfiguration yamlConfiguration)
- {
- try {
- yamlConfiguration.save(file);
- this.getUtil().log("The file " + file.getName() + " has been saved!");
- } catch (IOException e) {
- this.getUtil().warn("File " + file.getName() + " could not be saved, printing stacktrace!");
- e.printStackTrace();
- }
- }
- public void saveDefaultConfig(File file)
- {
- this.getPlugin().saveResource(file.getName(), false);
- }
- public YamlConfiguration getLangConfiguration() {
- return langConfiguration;
- }
- public File getLangFile() {
- return langFile;
- }
- public YamlConfiguration getLevelConfiguration() {
- return levelConfiguration;
- }
- public File getLevelFile() {
- return levelFile;
- }
- public YamlConfiguration getPlayerConfiguration() {
- return playerConfiguration;
- }
- public File getPlayerFile() {
- return playerFile;
- }
- public Main getPlugin() {
- return plugin;
- }
- public Util getUtil() {
- return util;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement