mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
Hotfix: Fix custom enchantments max level from supported enchantments resetting every restart.
This commit is contained in:
parent
3d320b1163
commit
1066508233
2 changed files with 23 additions and 13 deletions
|
|
@ -15,7 +15,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "xyz.alexcrea"
|
||||
version = "1.6.4"
|
||||
version = "1.6.5"
|
||||
|
||||
repositories {
|
||||
// EcoEnchants
|
||||
|
|
|
|||
|
|
@ -170,27 +170,37 @@ public class EnchantmentApi {
|
|||
*/
|
||||
public static boolean writeDefaultConfig(CAEnchantment enchantment, boolean override){
|
||||
FileConfiguration config = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
||||
if(!override && containEnchantment(config, enchantment)) return false;
|
||||
|
||||
writeDefaultConfig(config, enchantment);
|
||||
|
||||
prepareSaveTask();
|
||||
if(tryWriteDefaultConfig(config, enchantment, override)){
|
||||
prepareSaveTask();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean containEnchantment(FileConfiguration config, CAEnchantment enchantment) {
|
||||
return config.contains(enchantment.getName()) || config.contains(enchantment.getKey().toString());
|
||||
}
|
||||
private static boolean tryWriteDefaultConfig(FileConfiguration defaultConfig, CAEnchantment enchantment, boolean override) {
|
||||
boolean hasChange = false;
|
||||
|
||||
|
||||
private static void writeDefaultConfig(FileConfiguration defaultConfig, CAEnchantment enchantment) {
|
||||
defaultConfig.set("enchant_limits." + enchantment.getKey(), enchantment.defaultMaxLevel());
|
||||
String levelPath = "enchant_limits." + enchantment.getKey();
|
||||
if(override || !defaultConfig.isSet(levelPath)){
|
||||
defaultConfig.set(levelPath, enchantment.defaultMaxLevel());
|
||||
hasChange = true;
|
||||
}
|
||||
|
||||
String basePath = "enchant_values." + enchantment.getKey();
|
||||
EnchantmentRarity rarity = enchantment.defaultRarity();
|
||||
|
||||
defaultConfig.set(basePath + ".item", rarity.getItemValue());
|
||||
defaultConfig.set(basePath + ".book", rarity.getBookValue());
|
||||
String itemPath = basePath + ".item";
|
||||
String bookPath = basePath + ".book";
|
||||
if(override || !defaultConfig.isSet(itemPath)){
|
||||
defaultConfig.set(itemPath, rarity.getItemValue());
|
||||
hasChange = true;
|
||||
}
|
||||
if(override || !defaultConfig.isSet(bookPath)){
|
||||
defaultConfig.set(bookPath, rarity.getBookValue());
|
||||
hasChange = true;
|
||||
}
|
||||
|
||||
return hasChange;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue