Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.io.File;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.plugin.java.JavaPlugin;
- public final class PackagedFile
- {
- private String filename;
- private File file;
- private YamlConfiguration cfg;
- /**
- * @param level Level needed for logging.
- * @param message The message you want to log.
- */
- private void log(Level level, String message)
- {
- Logger.getLogger("Minecraft").log(level, message);
- }
- /**
- * @param pl The plugin, needed to get the folder.
- * @param fileName The file you want, OMIT .yml!
- */
- public PackagedFile(JavaPlugin pl, String fileName)
- {
- filename = fileName + ".yml";
- file = new File(pl.getDataFolder(), filename);
- if(pl.getDataFolder().exists())
- {
- check(pl, file);
- }
- else
- {
- pl.getDataFolder().mkdir();
- check(pl, file);
- }
- }
- private void check(JavaPlugin pl, File file)
- {
- log(Level.INFO, "Checking if file is unpacked.");
- if (file.exists())
- {
- log(Level.INFO, "File " + filename + " is already unpacked, loading data.");
- cfg = YamlConfiguration.loadConfiguration(file);
- }
- else
- {
- log(Level.INFO, "Unpacking file " + filename + ".");
- cfg = YamlConfiguration.loadConfiguration(pl.getResource(filename));
- }
- }
- /**
- * @return The created YamlConfiguration
- */
- public YamlConfiguration getCFG()
- {
- return cfg;
- }
- /**
- * @return The name of the file
- */
- public String getFilename()
- {
- return filename;
- }
- /**
- * @return The file that the YamlConfiguration is saved in
- */
- public File getFile()
- {
- return file;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement