Created
May 14, 2019 12:30
-
-
Save MrMicky-FR/8c9726ff33a8afbb081717d119cacd32 to your computer and use it in GitHub Desktop.
This file contains 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 net.md_5.bungee.api.plugin.Plugin; | |
import net.md_5.bungee.config.Configuration; | |
import net.md_5.bungee.config.ConfigurationProvider; | |
import net.md_5.bungee.config.YamlConfiguration; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.nio.file.Files; | |
/** | |
* Small utility class to load and save configuration on BungeeCord | |
* | |
* @author MrMicky | |
*/ | |
public final class BungeeConfigUtils { | |
public static Configuration loadConfig(Plugin plugin) { | |
try { | |
File configFile = new File(plugin.getDataFolder(), "config.yml"); | |
if (!configFile.exists()) { | |
plugin.getDataFolder().mkdir(); | |
try (InputStream is = plugin.getResourceAsStream("config.yml")) { | |
Files.copy(is, configFile.toPath()); | |
} | |
} | |
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); | |
} catch (IOException e) { | |
throw new RuntimeException("Unable to load configuration file", e); | |
} | |
} | |
public static void saveConfig(Plugin plugin, Configuration config) { | |
File configFile = new File(plugin.getDataFolder(), "config.yml"); | |
if (config != null) { | |
try { | |
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, configFile); | |
} catch (IOException e) { | |
throw new RuntimeException("Unable to save configuration file", e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment