diff --git a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt index 828e9fd..c8a8028 100644 --- a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt +++ b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt @@ -89,8 +89,11 @@ class AnvilEventListener : Listener { val inventory = event.inventory as? AnvilInventory ?: return val output = inventory.getItem(ANVIL_OUTPUT_SLOT) ?: return if(!player.hasPermission(bypassPermission)){ - if (output.findEnchantments().hasConflicts() && !player.hasPermission(requirePermission)) { return } + if (output.findEnchantments().hasConflicts() && !player.hasPermission(requirePermission)) { + + return + } } if (event.rawSlot != ANVIL_OUTPUT_SLOT) { return } event.result = Event.Result.ALLOW diff --git a/src/main/kotlin/xyz/alexcrea/group/EnchantConflictGroup.kt b/src/main/kotlin/xyz/alexcrea/group/EnchantConflictGroup.kt new file mode 100644 index 0000000..5405ee0 --- /dev/null +++ b/src/main/kotlin/xyz/alexcrea/group/EnchantConflictGroup.kt @@ -0,0 +1,40 @@ +package xyz.alexcrea.group + +import io.delilaheve.util.ItemUtil.findEnchantments +import org.bukkit.enchantments.Enchantment +import org.bukkit.inventory.ItemStack + +class EnchantConflictGroup(val cantConflict: MaterialGroup, val minBeforeBlock: Int){ + + private val enchantments = HashSet() + + fun addEnchantment(ench: Enchantment){ + enchantments.add(ench) + } + + fun allow(item: ItemStack) : Boolean{ + if(enchantments.size > minBeforeBlock){ + return true + } + if(cantConflict.contain(item.type)){ + return true + } + if(minBeforeBlock == 0){ + return false + } + + // Count the amount of enchantment that are in the list + var enchantAmount = 0 + for (enchantment in item.findEnchantments().keys) { + if(enchantment !in enchantments) continue + if(++enchantAmount > minBeforeBlock){ + return false + } + + } + + return true + } + + +} \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/group/ExcludeGroup.kt b/src/main/kotlin/xyz/alexcrea/group/ExcludeGroup.kt index d12378e8..26c2f45 100644 --- a/src/main/kotlin/xyz/alexcrea/group/ExcludeGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/group/ExcludeGroup.kt @@ -5,7 +5,6 @@ import org.bukkit.Material class ExcludeGroup(name: String): IncludeGroup(name) { override fun contain(mat: Material): Boolean { - Material.POLISHED_DIORITE return !super.contain(mat) } diff --git a/src/main/kotlin/xyz/alexcrea/group/IncludeGroup.kt b/src/main/kotlin/xyz/alexcrea/group/IncludeGroup.kt index 2b574d6..f524612 100644 --- a/src/main/kotlin/xyz/alexcrea/group/IncludeGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/group/IncludeGroup.kt @@ -1,15 +1,17 @@ package xyz.alexcrea.group import org.bukkit.Material +import java.util.EnumSet open class IncludeGroup(private val name: String): MaterialGroup{ - private val includedMaterial = HashSet() + private val includedMaterial = EnumSet.noneOf(Material::class.java) private val includedGroup = HashSet() override fun contain(mat: Material): Boolean { if(mat in includedMaterial){ return true } + for (materialGroup in includedGroup.iterator()) { if(materialGroup.contain(mat)){ return true diff --git a/src/main/kotlin/xyz/alexcrea/group/ItemGroupManager.kt b/src/main/kotlin/xyz/alexcrea/group/ItemGroupManager.kt index 5a6a3e6..e56f6d4 100644 --- a/src/main/kotlin/xyz/alexcrea/group/ItemGroupManager.kt +++ b/src/main/kotlin/xyz/alexcrea/group/ItemGroupManager.kt @@ -12,7 +12,9 @@ class ItemGroupManager { companion object { // Path for group type private const val GROUP_TYPE_PATH = "type" + // Path for included items list private const val MATERIAL_LIST_PATH = "items" + // Path for included groups list private const val GROUP_LIST_PATH = "groups" } diff --git a/src/main/resources/enchant_conflict.yml b/src/main/resources/enchant_conflict.yml new file mode 100644 index 0000000..3370f65 --- /dev/null +++ b/src/main/resources/enchant_conflict.yml @@ -0,0 +1,222 @@ +# material conflicts +# +# If you want to edit this file: +# - You need to take into account that multiple conflict can be applied to an item +# (exemple: protection can be applied to chestplate AND should not have other "protection") + +# These restriction are about not allowing enchantment on illegal items +restriction_aqua_infinity: + enchantments: [aqua_infinity] + notAffectedGroups: [helmet] + +restriction_bane_of_arthropods: + enchantments: [bane_of_arthropods] + notAffectedGroups: [melee_weapons] + +restriction_blast_protection: + enchantments: [blast_protection] + notAffectedGroups: [armors] + +restriction_channeling: + enchantments: [channeling] + notAffectedGroups: [trident] + +restriction_binding_curse: + enchantments: [binding_curse] + notAffectedGroups: [wearable] + +restriction_vanishing_curse: + enchantments: [vanishing_curse] + notAffectedGroups: [can_vanish] + +restriction_depth_strider: + enchantments: [depth_strider] + notAffectedGroups: [boots] + +restriction_efficiency: + enchantments: [efficiency] + notAffectedGroups: [tools, shears] + +restriction_feather_falling: + enchantments: [feather_falling] + notAffectedGroups: [boots] + +restriction_fire_aspect: + enchantments: [fire_aspect] + notAffectedGroups: [swords] + +restriction_fire_protection: + enchantments: [fire_protection] + notAffectedGroups: [armors] + +restriction_flame: + enchantments: [flame] + notAffectedGroups: [bow] + +restriction_fortune: + enchantments: [fortune] + notAffectedGroups: [tools] + +restriction_frost_walker: + enchantments: [frost_walker] + notAffectedGroups: [boots] + +restriction_impaling: + enchantments: [impaling] + notAffectedGroups: [trident] + +restriction_infinity: + enchantments: [infinity] + notAffectedGroups: [bow] + +restriction_knockback: + enchantments: [knockback] + notAffectedGroups: [swords] + +restriction_looting: + enchantments: [looting] + notAffectedGroups: [swords] + +restriction_loyalty: + enchantments: [loyalty] + notAffectedGroups: [trident] + +restriction_lure: + enchantments: [lure] + notAffectedGroups: [fishing_rod] + +restriction_mending: + enchantments: [ending] + notAffectedGroups: [can_unbreak] + +restriction_multishot: + enchantments: [multishot] + notAffectedGroups: [crossbow] + +restriction_piercing: + enchantments: [piercing] + notAffectedGroups: [crossbow] + +restriction_power: + enchantments: [power] + notAffectedGroups: [bow] + +restriction_projectile_protection: + enchantments: [projectile_protection] + notAffectedGroups: [armors] + +restriction_protection: + enchantments: [protection] + notAffectedGroups: [armors] + +restriction_punch: + enchantments: [punch] + notAffectedGroups: [bow] + +restriction_quick_charge: + enchantments: [quick_charge] + notAffectedGroups: [crossbow] + +restriction_respiration: + enchantments: [respiration] + notAffectedGroups: [helmet] + +restriction_riptide: + enchantments: [riptide] + notAffectedGroups: [trident] + +restriction_sharpness: + enchantments: [sharpness] + notAffectedGroups: [melee_weapons] + +restriction_silk_touch: + enchantments: [silk_touch] + notAffectedGroups: [tools] + +restriction_smite: + enchantments: [smite] + notAffectedGroups: [melee_weapons] + +restriction_soul_speed: + enchantments: [soul_speed] + notAffectedGroups: [boots] + +restriction_sweeping: + enchantments: [sweeping] + notAffectedGroups: [swords] + +restriction_swift_sneak: + enchantments: [swift_sneak] + notAffectedGroups: [boots] + +restriction_thorns: + enchantments: [thorns] + notAffectedGroups: [chestplate] + +restriction_unbreaking: + enchantments: [unbreaking] + notAffectedGroups: [can_unbreak] + +# Now we have Incompatibility +# Because we have filtered before this step, we will use nothing as notAffectedGroups +# We can an exclude group to exclude elements of group from the conflict + +sword_enchant_conflict: + enchantments: + - bane_of_arthropods + - smite + - sharpness + notAffectedGroups: [nothing] + maxEnchantmentBeforeConflict: 1 + +protection_enchant_conflict: + enchantments: + - blast_protection + - fire_protection + - projectile_protection + - protection + notAffectedGroups: [nothing] + maxEnchantmentBeforeConflict: 1 + +trident_conflict1: + enchantments: + - channeling + - riptide + notAffectedGroups: [nothing] + maxEnchantmentBeforeConflict: 1 + +trident_conflict2: + enchantments: + - loyalty + - riptide + notAffectedGroups: [nothing] + maxEnchantmentBeforeConflict: 1 + +boot_conflict: + enchantments: + - depth_strider + - frost_walker + notAffectedGroups: [nothing] + maxEnchantmentBeforeConflict: 1 + +tool_conflict: + enchantments: + - fortune + - silk_touch + notAffectedGroups: [nothing] + maxEnchantmentBeforeConflict: 1 + +bow_conflict: + enchantments: + - mending + - infinity + notAffectedGroups: [nothing] + maxEnchantmentBeforeConflict: 1 + +crossbow_conflict: + enchantments: + - multishot + - piercing + notAffectedGroups: [nothing] + maxEnchantmentBeforeConflict: 1 + diff --git a/src/main/resources/item_groups.yml b/src/main/resources/item_groups.yml index 095dd2c..e8a0153 100644 --- a/src/main/resources/item_groups.yml +++ b/src/main/resources/item_groups.yml @@ -25,3 +25,173 @@ example_exclude: - polished_granite groups: - example_include + +# Default configuration should be vanilla enchantment conflict group +# there may have error, if you find one you can fix it ! +# https://minecraft.fandom.com/wiki/Enchanting + +swords: + type: include + items: + - wooden_sword + - stone_sword + - iron_sword + - diamond_sword + - golden_sword + - netherite_sword + +axes: + type: include + items: + - wooden_axe + - stone_axe + - iron_axe + - diamond_axe + - golden_axe + - netherite_axe + +melee_weapons: + groups: + - swords + - axes + +helmets: + type: include + items: + - leather_helmet + - chainmail_helmet + - iron_helmet + - diamond_helmet + - golden_helmet + - netherite_helmet + - turtle_helme + +chestplate: + type: include + items: + - leather_chestplate + - chainmail_chestplate + - iron_chestplate + - diamond_chestplate + - golden_chestplate + - netherite_chestplate + +leggings: + type: include + items: + - leather_leggings + - chainmail_leggings + - iron_leggings + - diamond_leggings + - golden_leggings + - netherite_leggings + +boots: + type: include + items: + - leather_boots + - chainmail_boots + - iron_boots + - diamond_boots + - golden_boots + - netherite_boots + +armors: + type: include + groups: + - helmets + - chestplate + - leggings + - boots + +wearable: + type: include + items: + - elytra + - carved_pumpkin + - skeleton_skull + - wither_skeleton_skull + - zombie_head + - player_head + - creeper_head + - dragon_head + - piglin_head + groups: + - armors + +tools: + type: include + items: + - wooden_pickaxe + - stone_pickaxe + - iron_pickaxe + - diamond_pickaxe + - golden_pickaxe + - netherite_pickaxe + - wooden_shovel + - stone_shovel + - iron_shovel + - diamond_shovel + - golden_shovel + - netherite_shovel + - wooden_hoe + - stone_hoe + - iron_hoe + - diamond_hoe + - golden_hoe + - netherite_hoe + groups: + - axes + +trident: + type: include + items: + - trident + +bow: + type: include + items: + - bow + +crossbow: + type: include + items: + - crossbow + +fishing_rod: + type: include + items: + - fishing_rod + +shears: + type: include + items: + - shears + +can_unbreak: + type: include + items: + - elytra + - flint_and_steel + - shield + - carrot_on_a_stick + - warped_fungus_on_a_stick + - brush + groups: + - melee_weapons + - tools + - armors + - trident + - bow + - crossbow + - fishing_rod + - shears + +can_vanish: + type: include + items: + - compass + groups: + - wearable + - can_unbreak +