Last active
March 10, 2018 20:13
-
-
Save GrimEpp/92cf202084ca60c2284663579a0baa3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.bukkit.configuration.Configuration; | |
| import org.bukkit.configuration.InvalidConfigurationException; | |
| import org.bukkit.configuration.file.FileConfiguration; | |
| import org.bukkit.configuration.file.YamlConfiguration; | |
| import org.bukkit.plugin.Plugin; | |
| import java.io.File; | |
| import java.io.IOException; | |
| public class ConfigApi { | |
| private static Plugin p; | |
| private static Map<String, ConfigApi> configs; | |
| public static void enable(Plugin p) { | |
| ConfigApi.p = p; | |
| ConfigApi.configs = new HashMap<>(); | |
| } | |
| public static ConfigApi getConfig(String fileName) { | |
| if (configs.containsKey(fileName.toLowerCase())) { | |
| return configs.get(fileName); | |
| } | |
| if (p == null) { | |
| throw new NullPointerException("Plugin initialize feilet!"); | |
| } | |
| File file = new File(p.getDataFolder(), fileName); | |
| if (!file.exists()) { | |
| file.getParentFile().mkdirs(); | |
| p.saveResource(fileName, false); | |
| } | |
| return new ConfigApi(file, fileName); | |
| } | |
| private FileConfiguration c; | |
| private ConfigApi(File config, String name) { | |
| c = new YamlConfiguration(); | |
| try { | |
| c.load(config); | |
| } catch (IOException | InvalidConfigurationException e) { | |
| e.printStackTrace(); | |
| } | |
| configs.put(name.toLowerCase(), this); | |
| } | |
| private ConfigApi() { } | |
| public Configuration getConfig() { | |
| return c; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment