Guest User

Untitled

a guest
May 24th, 2019
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import net.md_5.bungee.api.plugin.Plugin;
  2. import net.md_5.bungee.config.Configuration;
  3. import net.md_5.bungee.config.ConfigurationProvider;
  4. import net.md_5.bungee.config.YamlConfiguration;
  5.  
  6. import java.io.File;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.nio.file.Files;
  10.  
  11. /**
  12. * Small utility class to load and save configuration on BungeeCord
  13. *
  14. * @author MrMicky
  15. */
  16. public final class BungeeConfigUtils {
  17.  
  18. public static Configuration loadConfig(Plugin plugin) {
  19. try {
  20. File configFile = new File(plugin.getDataFolder(), "config.yml");
  21.  
  22. if (!configFile.exists()) {
  23. plugin.getDataFolder().mkdir();
  24.  
  25. try (InputStream is = plugin.getResourceAsStream("config.yml")) {
  26. Files.copy(is, configFile.toPath());
  27. }
  28. }
  29. return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
  30. } catch (IOException e) {
  31. throw new RuntimeException("Unable to load configuration file", e);
  32. }
  33. }
  34.  
  35. public static void saveConfig(Plugin plugin, Configuration config) {
  36. File configFile = new File(plugin.getDataFolder(), "config.yml");
  37.  
  38. if (config != null) {
  39. try {
  40. ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, configFile);
  41. } catch (IOException e) {
  42. throw new RuntimeException("Unable to save configuration file", e);
  43. }
  44. }
  45. }
  46. }
RAW Paste Data