use of org.bukkit.configuration.ConfigurationSection in project TokenManager by RealizedMC.
the class ShopConfig method loadValues.
@Override
protected void loadValues(final FileConfiguration configuration) {
final ConfigurationSection section = configuration.getConfigurationSection("shops");
if (section == null) {
return;
}
for (final String name : section.getKeys(false)) {
final ConfigurationSection shopSection = section.getConfigurationSection(name);
final Shop shop;
try {
shop = new Shop(name, shopSection.getString("title", "&cShop title was not specified."), shopSection.getInt("rows", 1), shopSection.getBoolean("auto-close", false), shopSection.getBoolean("use-permission", false), shopSection.getBoolean("confirm-purchase", false));
} catch (IllegalArgumentException ex) {
Log.error(this, "Failed to initialize shop '" + name + "': " + ex.getMessage());
continue;
}
final ConfigurationSection itemsSection = shopSection.getConfigurationSection("items");
if (itemsSection != null) {
for (final String num : itemsSection.getKeys(false)) {
final OptionalLong slot = NumberUtil.parseLong(num);
if (!slot.isPresent() || slot.getAsLong() < 0 || slot.getAsLong() >= shop.getGui().getSize()) {
Log.error(this, "Failed to load slot '" + num + "' for shop '" + name + "': '" + slot + "' is not a valid number or is over the shop size.");
continue;
}
final ConfigurationSection slotSection = itemsSection.getConfigurationSection(num);
final ItemStack displayed;
try {
displayed = ItemUtil.loadFromString(slotSection.getString("displayed"));
} catch (Exception ex) {
shop.getGui().setItem((int) slot.getAsLong(), ItemBuilder.of(Material.REDSTONE_BLOCK).name("&4&m------------------").lore("&cThere was an error", "&cwhile loading this", "&citem, please contact", "&can administrator.", "&4&m------------------").build());
Log.error(this, "Failed to load displayed item for slot '" + num + "' of shop '" + name + "': " + ex.getMessage());
continue;
}
shop.setSlot((int) slot.getAsLong(), displayed, new Slot((int) slot.getAsLong(), slotSection.getInt("cost", 1000000), displayed, slotSection.getString("message"), slotSection.getString("subshop"), slotSection.getStringList("commands"), slotSection.getBoolean("use-permission", false), slotSection.getBoolean("confirm-purchase", false)));
}
}
register(name, shop);
}
}
use of org.bukkit.configuration.ConfigurationSection in project TokenManager by RealizedMC.
the class MySQLDatabase method transfer.
public void transfer(final CommandSender sender, final Consumer<String> errorHandler) {
executor.submit(() -> {
final File file = new File(plugin.getDataFolder(), "data.yml");
if (!file.exists()) {
sender.sendMessage(ChatColor.RED + "File not found!");
return;
}
sender.sendMessage(ChatColor.BLUE + plugin.getDescription().getFullName() + ": Loading user data from " + file.getName() + "...");
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
final ConfigurationSection section = config.getConfigurationSection("Players");
if (section == null) {
sender.sendMessage(ChatColor.RED + "Data not found!");
return;
}
sender.sendMessage(ChatColor.BLUE + plugin.getDescription().getFullName() + ": Load Complete. Starting the transfer...");
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(Query.INSERT_OR_UPDATE.query)) {
connection.setAutoCommit(false);
int i = 0;
final Set<String> keys = section.getKeys(false);
for (final String key : keys) {
final long value = section.getLong(key);
statement.setString(1, key);
statement.setLong(2, value);
statement.setLong(3, value);
statement.addBatch();
if (++i % 100 == 0 || i == keys.size()) {
statement.executeBatch();
}
}
connection.commit();
connection.setAutoCommit(true);
sender.sendMessage(ChatColor.BLUE + plugin.getDescription().getFullName() + ": Transfer Complete. Total Transferred Data: " + keys.size());
} catch (SQLException ex) {
errorHandler.accept(ex.getMessage());
Log.error("Failed to transfer data from file: " + ex.getMessage());
ex.printStackTrace();
}
});
}
use of org.bukkit.configuration.ConfigurationSection in project NoCheatPlus by NoCheatPlus.
the class PathUtils method getWorldsDefaultConfig.
/**
* A config file only containing the entries that are not set as global only.
* @param defaultConfig
* @return
*/
public static MemoryConfiguration getWorldsDefaultConfig(final MemoryConfiguration defaultConfig) {
final char sep = defaultConfig.options().pathSeparator();
final MemoryConfiguration config = new ConfigFile();
config.options().pathSeparator(sep);
final Map<String, Object> defaults = defaultConfig.getValues(false);
for (final Entry<String, Object> entry : defaults.entrySet()) {
final String part = entry.getKey();
if (!part.isEmpty() && !mayBeInWorldConfig(part)) {
continue;
}
final Object value = entry.getValue();
if (value instanceof ConfigurationSection) {
addWorldConfigSection(config, (ConfigurationSection) value, part, sep);
} else {
config.set(part, value);
}
}
return config;
}
use of org.bukkit.configuration.ConfigurationSection in project NoCheatPlus by NoCheatPlus.
the class PathUtils method removePaths.
/**
* Get a new ConfigFile instance with all paths removed (recursively by prefix).
* @param config
* @param removePaths
* @return
*/
public static ConfigFile removePaths(final ConfigFile config, final Collection<String> removePaths) {
final SimpleCharPrefixTree prefixes = new SimpleCharPrefixTree();
for (final String path : removePaths) {
prefixes.feed(path);
}
final ConfigFile newConfig = new ConfigFile();
for (final Entry<String, Object> entry : config.getValues(true).entrySet()) {
final String path = entry.getKey();
final Object value = entry.getValue();
// TODO: To support moving entire sections, this needs to be changed.
if (value instanceof ConfigurationSection) {
continue;
}
if (!prefixes.hasPrefix(path)) {
newConfig.set(path, value);
}
}
return newConfig;
}
use of org.bukkit.configuration.ConfigurationSection in project NoCheatPlus by NoCheatPlus.
the class RawConfigFile method readDoubleValuesForEntityTypes.
/**
* Read double for entity type, ignoring case. Uses bukkit names for
* EntityType.
*
* @param path
* @param map
* @param defaultValue
* @param allowDefault
* If set to true, the default value will be added for the null
* key, unless present, and it will be set/overridden if a
* section key equals 'default', ignoring case.
*/
public void readDoubleValuesForEntityTypes(final String sectionPath, final Map<EntityType, Double> map, double defaultValue, final boolean allowDefault) {
final ConfigurationSection section = getConfigurationSection(sectionPath);
if (section == null) {
if (allowDefault && !map.containsKey(null)) {
map.put(null, defaultValue);
}
return;
}
if (allowDefault) {
for (final String key : section.getKeys(false)) {
final String ucKey = key.trim().toUpperCase();
final String path = sectionPath + "." + key;
if (ucKey.equals("DEFAULT")) {
defaultValue = getDouble(path, defaultValue);
map.put(null, defaultValue);
}
}
if (!map.containsKey(null)) {
map.put(null, defaultValue);
}
}
for (final String key : section.getKeys(false)) {
final String ucKey = key.trim().toUpperCase();
final String path = sectionPath + "." + key;
if (allowDefault && ucKey.equals("DEFAULT")) {
// Ignore.
} else {
// TODO: Validate values further.
EntityType type = null;
try {
type = EntityType.valueOf(ucKey);
} catch (IllegalArgumentException e) {
}
if (type == null) {
// TODO: Log once per file only (needs new framework)?
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, "Bad entity type at '" + path + "': " + key);
} else {
map.put(type, getDouble(path, defaultValue));
}
}
}
}
Aggregations