mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +02:00
Add comment and Finish test of conflict for CAEnchant.
This commit is contained in:
parent
dafe595c5b
commit
3c60e157e4
5 changed files with 71 additions and 23 deletions
|
|
@ -99,7 +99,7 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener {
|
|||
// Test for merge
|
||||
if (first.canMergeWith(second)) {
|
||||
val newEnchants = first.findEnchantments()
|
||||
.combineWith(second.findEnchantments(), first.type, player)
|
||||
.combineWith(second.findEnchantments(), first, player)
|
||||
val resultItem = first.clone()
|
||||
resultItem.setEnchantmentsUnsafe(newEnchants)
|
||||
|
||||
|
|
@ -436,15 +436,15 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener {
|
|||
|
||||
val rightIsFormBook = right.isEnchantedBook()
|
||||
val resultEnchs = result.findEnchantments()
|
||||
val resultEnchsKeys = HashSet(resultEnchs.keys)
|
||||
val resultEnchsKeys = HashMap(resultEnchs)
|
||||
|
||||
for (enchantment in right.findEnchantments()) {
|
||||
// count enchant as illegal enchant if it conflicts with another enchant or not in result
|
||||
if ((enchantment.key !in resultEnchsKeys)) {
|
||||
resultEnchsKeys.add(enchantment.key)
|
||||
resultEnchsKeys[enchantment.key] = enchantment.value
|
||||
val conflictType = ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(
|
||||
resultEnchsKeys,
|
||||
result.type,
|
||||
result,
|
||||
enchantment.key
|
||||
)
|
||||
resultEnchsKeys.remove(enchantment.key)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package io.delilaheve.util
|
||||
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.entity.HumanEntity
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||
import xyz.alexcrea.cuanvil.group.ConflictType
|
||||
|
|
@ -25,10 +25,11 @@ object EnchantmentUtil {
|
|||
*/
|
||||
fun Map<CAEnchantment, Int>.combineWith(
|
||||
other: Map<CAEnchantment, Int>,
|
||||
mat: Material,
|
||||
item: ItemStack,
|
||||
player: HumanEntity
|
||||
) = mutableMapOf<CAEnchantment, Int>().apply {
|
||||
putAll(this@combineWith)
|
||||
|
||||
other.forEach { (enchantment, level) ->
|
||||
if(!enchantment.isAllowed(player)) return@forEach
|
||||
|
||||
|
|
@ -44,7 +45,7 @@ object EnchantmentUtil {
|
|||
// Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions
|
||||
this[enchantment] = cappedLevel
|
||||
val conflictType =
|
||||
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
||||
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this, item, enchantment)
|
||||
if (!player.hasPermission(CustomAnvil.bypassFusePermission) &&
|
||||
(conflictType != ConflictType.NO_CONFLICT)
|
||||
) {
|
||||
|
|
@ -59,7 +60,7 @@ object EnchantmentUtil {
|
|||
|
||||
// ... and they are conflicting
|
||||
val conflictType =
|
||||
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
||||
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this, item, enchantment)
|
||||
if ((conflictType != ConflictType.NO_CONFLICT)
|
||||
&& !player.hasPermission(CustomAnvil.bypassFusePermission)
|
||||
) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue