mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-20 23:37:36 +01:00
d6bdb0486a
- Formatting - Warning about old Bukkit version - Renamed "TOWNY_CANNOT_CREATE_SHOP_HERE" to "CANNOT_CREATE_SHOP_HERE" to avoid confusion - Renamed "NOT_ENOUGH_LWC_PROTECTIONS" to "NOT_ENOUGH_PROTECTIONS" and changed its message - Fixed armour enchantments - Logging shop location - Fixed Heroes for the newest version - Removed redutant plugin object - Added dev-url for CraftBukkitUpToDate - Removed redutant plugins from softdepend - Fixed a bug when the player interacts with a shop with a sign in hand
89 lines
2.6 KiB
Java
89 lines
2.6 KiB
Java
package com.Acrobot.ChestShop.Config;
|
|
|
|
import com.Acrobot.ChestShop.ChestShop;
|
|
import com.Acrobot.ChestShop.Utils.uLongName;
|
|
import org.bukkit.configuration.Configuration;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import java.io.File;
|
|
import java.io.FileWriter;
|
|
|
|
/**
|
|
* @author Acrobot
|
|
*/
|
|
public class ConfigObject {
|
|
private final File configFile = new File(ChestShop.folder, "config.yml");
|
|
private final File langFile = new File(ChestShop.folder, "local.yml");
|
|
private final YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
|
private final YamlConfiguration language = YamlConfiguration.loadConfiguration(langFile);
|
|
|
|
public ConfigObject() {
|
|
if (!ChestShop.folder.exists()) ChestShop.folder.mkdir();
|
|
|
|
reloadConfig();
|
|
load(config, configFile);
|
|
|
|
reloadLanguage();
|
|
load(language, langFile);
|
|
|
|
uLongName.configFile = new File(ChestShop.folder, "longName.storage");
|
|
uLongName.config = YamlConfiguration.loadConfiguration(uLongName.configFile);
|
|
}
|
|
|
|
private void reloadConfig() {
|
|
for (Property def : Property.values()) {
|
|
if (config.get(def.name()) == null) {
|
|
writeToFile('\n' + def.name() + ": " + def.getValue() + "\n#" + def.getComment(), configFile);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void reloadLanguage() {
|
|
for (Language def : Language.values()) {
|
|
if (language.get(def.name()) == null) {
|
|
writeToFile('\n' + def.name() + ": \"" + def.toString() + '\"', langFile);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void writeToFile(String string, File file) {
|
|
try {
|
|
FileWriter fw = new FileWriter(file, true);
|
|
fw.write(string);
|
|
fw.close();
|
|
} catch (Exception e) {
|
|
System.err.println("Couldn't write to file - " + file.getName());
|
|
}
|
|
}
|
|
|
|
public Configuration getLanguageConfig() {
|
|
return language;
|
|
}
|
|
|
|
public Object getProperty(String property) {
|
|
return config.get(property);
|
|
}
|
|
|
|
public static void load(FileConfiguration config, File file) {
|
|
try {
|
|
config.load(file);
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static void save(FileConfiguration config, File file) {
|
|
try {
|
|
config.save(file);
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static void reloadConfig(FileConfiguration config, File file) {
|
|
save(config, file);
|
|
load(config, file);
|
|
}
|
|
}
|