use of org.bukkit.configuration.MemoryConfiguration in project Essentials by EssentialsX.
the class Settings method _getCommandCosts.
private ConfigurationSection _getCommandCosts() {
if (config.isConfigurationSection("command-costs")) {
final ConfigurationSection section = config.getConfigurationSection("command-costs");
final ConfigurationSection newSection = new MemoryConfiguration();
for (String command : section.getKeys(false)) {
if (command.charAt(0) == '/') {
ess.getLogger().warning("Invalid command cost. '" + command + "' should not start with '/'.");
}
if (section.isDouble(command)) {
newSection.set(command.toLowerCase(Locale.ENGLISH), section.getDouble(command));
} else if (section.isInt(command)) {
newSection.set(command.toLowerCase(Locale.ENGLISH), (double) section.getInt(command));
} else if (section.isString(command)) {
String costString = section.getString(command);
try {
double cost = Double.parseDouble(costString.trim().replace(getCurrencySymbol(), "").replaceAll("\\W", ""));
newSection.set(command.toLowerCase(Locale.ENGLISH), cost);
} catch (NumberFormatException ex) {
ess.getLogger().warning("Invalid command cost for: " + command + " (" + costString + ")");
}
} else {
ess.getLogger().warning("Invalid command cost for: " + command);
}
}
return newSection;
}
return null;
}
use of org.bukkit.configuration.MemoryConfiguration in project Essentials by EssentialsX.
the class Kits method _getKits.
private ConfigurationSection _getKits() {
if (config.isConfigurationSection("kits")) {
final ConfigurationSection section = config.getConfigurationSection("kits");
final ConfigurationSection newSection = new MemoryConfiguration();
for (String kitItem : section.getKeys(false)) {
if (section.isConfigurationSection(kitItem)) {
newSection.set(kitItem.toLowerCase(Locale.ENGLISH), section.getConfigurationSection(kitItem));
}
}
return newSection;
}
return null;
}
use of org.bukkit.configuration.MemoryConfiguration in project Essentials by drtshock.
the class Commandcreatekit method run.
// /createkit <name> <delay>
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (args.length != 2) {
throw new NotEnoughArgumentsException();
}
// Command handler will auto fail if this fails.
long delay = Long.valueOf(args[1]);
String kitname = args[0];
ItemStack[] items = user.getBase().getInventory().getContents();
List<String> list = new ArrayList<>();
for (ItemStack is : items) {
if (is != null && is.getType() != null && is.getType() != Material.AIR) {
String serialized = ess.getItemDb().serialize(is);
list.add(serialized);
}
}
// Some users might want to directly write to config knowing the consequences. *shrug*
if (!ess.getSettings().isPastebinCreateKit()) {
ess.getKits().addKit(kitname, list, delay);
user.sendMessage(tl("createdKit", kitname, list.size(), delay));
} else {
ConfigurationSection config = new MemoryConfiguration();
config.set("kits." + kitname + ".delay", delay);
config.set("kits." + kitname + ".items", list);
final Yaml yaml = new Yaml(yamlConstructor, yamlRepresenter, yamlOptions);
String fileContents = "# Copy the kit code below into the kits section in your config.yml file\n";
fileContents += yaml.dump(config.getValues(false));
uploadPaste(user.getSource(), kitname, delay, fileContents);
}
}
use of org.bukkit.configuration.MemoryConfiguration in project NoCheatPlus by NoCheatPlus.
the class ConfigManager method init.
/**
* Initializes the configuration manager. Must be called in the main thread.
*
* @param plugin
* the instance of NoCheatPlus
*/
public static synchronized void init(final Plugin plugin, final WorldDataManager worldDataManager) {
// (This can lead to minor problems with async checks during reloading.)
LinkedHashMap<String, ConfigFile> newWorldsMap = new LinkedHashMap<String, ConfigFile>();
// Try to obtain and parse the global configuration file.
final File globalFile = new File(plugin.getDataFolder(), "config.yml");
final ConfigFile defaultConfig = new DefaultConfig();
final int maxBuildContained = defaultConfig.getMaxLastChangedBuildNumber();
// TODO: Detect changes to the configuration (only save back if necessary.).
PathUtils.processPaths(globalFile, "global config", false);
final ConfigFile globalConfig = new ConfigFile();
globalConfig.setDefaults(defaultConfig);
globalConfig.options().copyDefaults(true);
if (globalFile.exists()) {
try {
globalConfig.load(globalFile);
// Quick shallow ugly fix: only save back if loading was successful.
try {
if (globalConfig.getBoolean(ConfPaths.SAVEBACKCONFIG)) {
boolean overrideCreated = false;
if (!globalConfig.contains(ConfPaths.CONFIGVERSION_CREATED)) {
// Workaround.
overrideCreated = true;
}
if (!overrideCreated && globalConfig.getInt(ConfPaths.CONFIGVERSION_CREATED, 0) >= 0 && ConfigManager.isConfigUpToDate(globalConfig, 0) == null) {
// Workaround: Update the created build number, to not warn on further changes.
overrideCreated = true;
}
globalConfig.set(ConfPaths.CONFIGVERSION_SAVED, maxBuildContained);
if (overrideCreated) {
globalConfig.set(ConfPaths.CONFIGVERSION_CREATED, maxBuildContained);
}
// TODO: Only save back if really changed?
globalConfig.save(globalFile);
}
} catch (final Exception e) {
StaticLog.logSevere("Could not save back config.yml (see exception below).");
StaticLog.logSevere(e);
}
} catch (final Exception e) {
StaticLog.logSevere("Could not load config.yml (see exception below). Continue with default settings...");
StaticLog.logSevere(e);
}
} else {
globalConfig.options().header("This configuration was auto-generated by NoCheatPlus.");
globalConfig.options().copyHeader(true);
try {
globalConfig.set(ConfPaths.CONFIGVERSION_CREATED, maxBuildContained);
globalConfig.set(ConfPaths.CONFIGVERSION_SAVED, maxBuildContained);
globalConfig.save(globalFile);
} catch (final Exception e) {
StaticLog.logSevere(e);
}
}
// globalConfig.setActionFactory();
newWorldsMap.put(null, globalConfig);
final MemoryConfiguration worldDefaults = PathUtils.getWorldsDefaultConfig(globalConfig);
// Try to obtain and parse the world-specific configuration files.
final HashMap<String, File> worldFiles = new HashMap<String, File>();
if (plugin.getDataFolder().isDirectory()) {
for (final File file : plugin.getDataFolder().listFiles()) {
if (file.isFile()) {
final String fileName = file.getName();
if (fileName.matches(".+_config.yml$")) {
final String worldname = fileName.substring(0, fileName.length() - 11);
worldFiles.put(worldname, file);
}
}
}
}
for (final Entry<String, File> worldEntry : worldFiles.entrySet()) {
final File worldFile = worldEntry.getValue();
PathUtils.processPaths(worldFile, "world " + worldEntry.getKey(), true);
final ConfigFile worldConfig = new ConfigFile();
worldConfig.setDefaults(worldDefaults);
worldConfig.options().copyDefaults(true);
try {
worldConfig.load(worldFile);
newWorldsMap.put(worldEntry.getKey(), worldConfig);
try {
if (worldConfig.getBoolean(ConfPaths.SAVEBACKCONFIG)) {
worldConfig.save(worldFile);
}
} catch (final Exception e) {
StaticLog.logSevere("Couldn't save back world-specific configuration for " + worldEntry.getKey() + " (see exception below).");
StaticLog.logSevere(e);
}
} catch (final Exception e) {
StaticLog.logSevere("Couldn't load world-specific configuration for " + worldEntry.getKey() + " (see exception below). Continue with global default settings...");
StaticLog.logSevere(e);
}
worldConfig.setDefaults(globalConfig);
worldConfig.options().copyDefaults(true);
// worldConfig.setActionFactory();
}
worldDataManager.applyConfiguration(newWorldsMap);
isInitialized = true;
}
Aggregations