2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.config;
|
2020-10-28 03:49:56 +00:00
|
|
|
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.Plex;
|
2022-01-04 03:04:39 +00:00
|
|
|
import java.io.File;
|
2022-01-27 21:23:01 +00:00
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2022-01-04 03:04:39 +00:00
|
|
|
|
2022-02-07 17:07:48 +00:00
|
|
|
/**
|
|
|
|
* Creates a custom Config object
|
|
|
|
*/
|
2020-10-31 15:09:13 +00:00
|
|
|
public class Config extends YamlConfiguration
|
2020-10-28 03:49:56 +00:00
|
|
|
{
|
2022-02-07 17:07:48 +00:00
|
|
|
/**
|
|
|
|
* The plugin instance
|
|
|
|
*/
|
2020-10-29 02:10:47 +00:00
|
|
|
private Plex plugin;
|
2022-02-07 17:07:48 +00:00
|
|
|
/**
|
|
|
|
* The File instance
|
|
|
|
*/
|
2020-10-29 02:10:47 +00:00
|
|
|
private File file;
|
2022-02-07 17:07:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The file name
|
|
|
|
*/
|
2020-10-31 15:09:13 +00:00
|
|
|
private String name;
|
2020-10-28 03:49:56 +00:00
|
|
|
|
2022-02-07 17:07:48 +00:00
|
|
|
/**
|
|
|
|
* Creates a config object
|
|
|
|
* @param plugin The plugin instance
|
|
|
|
* @param name The file name
|
|
|
|
*/
|
2020-10-31 15:09:13 +00:00
|
|
|
public Config(Plex plugin, String name)
|
2020-10-28 03:49:56 +00:00
|
|
|
{
|
|
|
|
this.plugin = plugin;
|
2020-10-31 15:09:13 +00:00
|
|
|
this.file = new File(plugin.getDataFolder(), name);
|
|
|
|
this.name = name;
|
2020-10-28 03:49:56 +00:00
|
|
|
|
|
|
|
if (!file.exists())
|
|
|
|
{
|
2020-10-29 00:54:23 +00:00
|
|
|
saveDefault();
|
2020-10-28 03:49:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 17:07:48 +00:00
|
|
|
/**
|
|
|
|
* Loads the configuration file
|
|
|
|
*/
|
2020-10-28 03:49:56 +00:00
|
|
|
public void load()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
super.load(file);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 17:07:48 +00:00
|
|
|
/**
|
|
|
|
* Saves the configuration file
|
|
|
|
*/
|
2020-10-28 03:49:56 +00:00
|
|
|
public void save()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
super.save(file);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 17:07:48 +00:00
|
|
|
/**
|
|
|
|
* Moves the configuration file from the plugin's resources folder to the data folder (plugins/Plex/)
|
|
|
|
*/
|
2020-10-29 00:54:23 +00:00
|
|
|
private void saveDefault()
|
2020-10-28 03:49:56 +00:00
|
|
|
{
|
2020-10-31 15:09:13 +00:00
|
|
|
plugin.saveResource(name, false);
|
2020-10-28 03:49:56 +00:00
|
|
|
}
|
|
|
|
}
|