Created
December 9, 2016 22:51
-
-
Save TheMasteredPanda/0dbf048df9828215c1dc3fdaf6817f2b 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
package net.zoramagic.bungee.files.configs; | |
import net.md_5.bungee.api.ProxyServer; | |
import net.md_5.bungee.config.Configuration; | |
import net.md_5.bungee.config.ConfigurationProvider; | |
import net.md_5.bungee.config.YamlConfiguration; | |
import net.zoramagic.bungee.ZMBungeeCore; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.nio.file.Files; | |
import java.util.logging.Logger; | |
/** | |
* Created by TheMasteredPanda on 11/11/2016. | |
*/ | |
public class BaseConfig | |
{ | |
private ZMBungeeCore plugin = ZMBungeeCore.getPlugin(); | |
private final Logger logger = this.plugin.logger; | |
private File configFile = null; | |
private String configName = null; | |
protected volatile Configuration config = null; | |
public BaseConfig(String configName) | |
{ | |
this.configName = configName; | |
} | |
public void loadConfig() | |
{ | |
if (this.logger == null) { | |
ProxyServer.getInstance().getLogger().info("Logger is null."); | |
} | |
if (!this.plugin.getDataFolder().exists()) { | |
this.logger.info("Creating folder " + this.plugin.getDataFolder().getName() + "."); | |
this.plugin.getDataFolder().mkdir(); | |
} | |
save(); | |
try { | |
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); | |
} catch (IOException cannotLoadConfigurationFile) { | |
cannotLoadConfigurationFile.printStackTrace(); | |
} | |
} | |
public synchronized void save() | |
{ | |
this.plugin.runOnThreadPool(() -> { | |
File f = new File(this.plugin.getDataFolder(), configName); | |
if (!f.exists()) { | |
try { | |
this.logger.info("Saving file " + configName); | |
InputStream in = this.plugin.getResourceAsStream(configName); | |
Files.copy(in, f.toPath()); | |
} catch (IOException fileSaveFailureException) { | |
fileSaveFailureException.printStackTrace(); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment