mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +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"
|
group = "xyz.alexcrea"
|
||||||
version = "1.6.4"
|
version = "1.6.5"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
// EcoEnchants
|
// EcoEnchants
|
||||||
|
|
|
||||||
|
|
@ -170,27 +170,37 @@ public class EnchantmentApi {
|
||||||
*/
|
*/
|
||||||
public static boolean writeDefaultConfig(CAEnchantment enchantment, boolean override){
|
public static boolean writeDefaultConfig(CAEnchantment enchantment, boolean override){
|
||||||
FileConfiguration config = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
FileConfiguration config = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
||||||
if(!override && containEnchantment(config, enchantment)) return false;
|
|
||||||
|
|
||||||
writeDefaultConfig(config, enchantment);
|
if(tryWriteDefaultConfig(config, enchantment, override)){
|
||||||
|
prepareSaveTask();
|
||||||
prepareSaveTask();
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean containEnchantment(FileConfiguration config, CAEnchantment enchantment) {
|
private static boolean tryWriteDefaultConfig(FileConfiguration defaultConfig, CAEnchantment enchantment, boolean override) {
|
||||||
return config.contains(enchantment.getName()) || config.contains(enchantment.getKey().toString());
|
boolean hasChange = false;
|
||||||
}
|
|
||||||
|
|
||||||
|
String levelPath = "enchant_limits." + enchantment.getKey();
|
||||||
private static void writeDefaultConfig(FileConfiguration defaultConfig, CAEnchantment enchantment) {
|
if(override || !defaultConfig.isSet(levelPath)){
|
||||||
defaultConfig.set("enchant_limits." + enchantment.getKey(), enchantment.defaultMaxLevel());
|
defaultConfig.set(levelPath, enchantment.defaultMaxLevel());
|
||||||
|
hasChange = true;
|
||||||
|
}
|
||||||
|
|
||||||
String basePath = "enchant_values." + enchantment.getKey();
|
String basePath = "enchant_values." + enchantment.getKey();
|
||||||
EnchantmentRarity rarity = enchantment.defaultRarity();
|
EnchantmentRarity rarity = enchantment.defaultRarity();
|
||||||
|
|
||||||
defaultConfig.set(basePath + ".item", rarity.getItemValue());
|
String itemPath = basePath + ".item";
|
||||||
defaultConfig.set(basePath + ".book", rarity.getBookValue());
|
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