| 1 | package me.fridtjof.minecarttrains.utils; |
| 2 | |
| 3 | import org.bukkit.configuration.file.FileConfiguration; |
| 4 | import org.bukkit.configuration.file.YamlConfiguration; |
| 5 | |
| 6 | import java.io.File; |
| 7 | import java.io.IOException; |
| 8 | import java.util.logging.Level; |
| 9 | import java.util.logging.Logger; |
| 10 | |
| 11 | public class YamlConfig |
| 12 | { |
| 13 | |
| 14 | private static final Logger LOGGER = Logger.getLogger("MinecartTrains"); |
| 15 | |
| 16 | private final File file; |
| 17 | private FileConfiguration config; |
| 18 | |
| 19 | public YamlConfig(File pluginDataFolder, String name) |
| 20 | { |
| 21 | this.file = new File(pluginDataFolder, name + ".yml"); |
| 22 | if (!pluginDataFolder.exists()) |
| 23 | { |
| 24 | pluginDataFolder.mkdirs(); |
| 25 | } |
| 26 | this.config = YamlConfiguration.loadConfiguration(file); |
| 27 | } |
| 28 | |
| 29 | public FileConfiguration getConfig() |
| 30 | { |
| 31 | return config; |
| 32 | } |
| 33 | |
| 34 | public File getFile() |
| 35 | { |
| 36 | return file; |
| 37 | } |
| 38 | |
| 39 | public String getName() |
| 40 | { |
| 41 | return file.getName(); |
| 42 | } |
| 43 | |
| 44 | public void save() |
| 45 | { |
| 46 | try |
| 47 | { |
| 48 | config.save(file); |
| 49 | } |
| 50 | catch (IOException exception) |
| 51 | { |
| 52 | LOGGER.log(Level.SEVERE, "Could not save " + file.getName(), exception); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | public void reload() |
| 57 | { |
| 58 | config = YamlConfiguration.loadConfiguration(file); |
| 59 | } |
| 60 | } |