Use namespace for disable merge over

This commit is contained in:
alexcrea 2024-09-29 19:42:29 +02:00
parent b0b1777883
commit 4bc959d76f
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
3 changed files with 41 additions and 19 deletions

View file

@ -1,6 +1,7 @@
package xyz.alexcrea.cuanvil.gui.config.global; package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import io.delilaheve.util.ConfigOptions;
import org.bukkit.Material; import org.bukkit.Material;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
@ -34,8 +35,8 @@ public class EnchantMergeLimitConfigGui extends AbstractEnchantConfigGui<IntSett
@Override @Override
public IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant) { public IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant) {
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT); String key = enchant.getKey().toString().toLowerCase(Locale.ROOT);
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key); String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
return new IntSettingsGui.IntSettingFactory(prettyKey + " Merge Limit", this, return new IntSettingsGui.IntSettingFactory(prettyKey + " Merge Limit", this,
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG, SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
@ -48,7 +49,13 @@ public class EnchantMergeLimitConfigGui extends AbstractEnchantConfigGui<IntSett
"§e-1 §7(default) will set the merge limit to enchantment's maximum level" "§e-1 §7(default) will set the merge limit to enchantment's maximum level"
), ),
-1, 255, -1, -1, 255, -1,
1, 5, 10, 50, 100); 1, 5, 10, 50, 100){
@Override
public int getConfiguredValue() {
return ConfigOptions.INSTANCE.maxBeforeMergeDisabled(enchant);
}
};
} }
@Override @Override

View file

@ -381,9 +381,13 @@ object ConfigOptions {
private fun getDefaultValue(enchantment: CAEnchantment, // compatibility with 1.20.5. TODO better update system private fun getDefaultValue(enchantment: CAEnchantment, // compatibility with 1.20.5. TODO better update system
isFromBook: Boolean) : Int { isFromBook: Boolean) : Int {
val enchantmentName = enchantment.enchantmentName val enchantmentName = enchantment.key.toString()
if(enchantmentName == "sweeping_edge"){ if(enchantmentName == "minecraft:sweeping_edge"){
val limit = enchantmentValue("sweeping", isFromBook) var limit = enchantmentValue("minecraft:sweeping", isFromBook)
if(limit != null) return limit
// legacy name
limit = enchantmentValue("sweeping", isFromBook)
if(limit != null) return limit if(limit != null) return limit
} }
@ -399,28 +403,39 @@ object ConfigOptions {
* a negative value would mean never disabled * a negative value would mean never disabled
*/ */
fun maxBeforeMergeDisabled(enchantment: CAEnchantment): Int { fun maxBeforeMergeDisabled(enchantment: CAEnchantment): Int {
return maxBeforeMergeDisabled(enchantment.enchantmentName) val key = enchantment.key.toString()
var value = maxBeforeMergeDisabled(key)
if(value != null) return value
// Legacy name
val legacy = enchantment.enchantmentName
value = maxBeforeMergeDisabled(legacy)
if(value != null) return value
if(key == "minecraft:sweeping_edge"){
value = maxBeforeMergeDisabled("minecraft:sweeping")
if(value != null) return value
// legacy name of legacy enchantment name
value = maxBeforeMergeDisabled("sweeping")
if(value != null) return value
}
return DEFAULT_MAX_BEFORE_MERGE_DISABLED
} }
/** /**
* Get the given [enchantmentName]'s level before merge is disabled * Get the given [enchantmentName]'s level before merge is disabled
* a negative value would mean never disabled * a negative value would mean never disabled
*/ */
private fun maxBeforeMergeDisabled(enchantmentName: String) : Int { private fun maxBeforeMergeDisabled(enchantmentName: String) : Int? {
// find if set // find if set
val path = "${DISABLE_MERGE_OVER_ROOT}.$enchantmentName" val path = "${DISABLE_MERGE_OVER_ROOT}.$enchantmentName"
val value = CustomAnvil.instance return CustomAnvil.instance
.config .config
.getInt(path, DEFAULT_MAX_BEFORE_MERGE_DISABLED) .getInt(path, ENCHANT_LIMIT_RANGE.min() - 1)
.takeIf { it in ENCHANT_LIMIT_RANGE } .takeIf { it in ENCHANT_LIMIT_RANGE }
?: DEFAULT_MAX_BEFORE_MERGE_DISABLED;
if((value == DEFAULT_MAX_BEFORE_MERGE_DISABLED) && (enchantmentName == "sweeping_edge")){
return maxBeforeMergeDisabled("sweeping")
}
return value
} }
} }

View file

@ -278,9 +278,9 @@ enchant_values:
# -1 mean enchantment merge for this enchantment is not disabled. default to -1 if absent. # -1 mean enchantment merge for this enchantment is not disabled. default to -1 if absent.
disable-merge-over: disable-merge-over:
# Sharpness is set to -1. it equivalent to it not being set to anything (and work as vanilla) # Sharpness is set to -1. it equivalent to it not being set to anything (and work as vanilla)
sharpness: -1 minecraft:sharpness: -1
# If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied # If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied
#unbreaking: 2 #minecraft:unbreaking: 2
# Whether to show debug logging # Whether to show debug logging
debug_log: false debug_log: false