add enchant conflict and it's yml and finished material groups yml

This commit is contained in:
alexcrea 2024-02-01 01:29:07 +01:00
parent b6ce69c45b
commit 8ba1b532df
7 changed files with 441 additions and 3 deletions

View file

@ -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

View file

@ -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<Enchantment>()
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
}
}

View file

@ -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)
}

View file

@ -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<Material>()
private val includedMaterial = EnumSet.noneOf(Material::class.java)
private val includedGroup = HashSet<MaterialGroup>()
override fun contain(mat: Material): Boolean {
if(mat in includedMaterial){
return true
}
for (materialGroup in includedGroup.iterator()) {
if(materialGroup.contain(mat)){
return true

View file

@ -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"
}