From 89f252222b6d218eab415d3d7cf06ebd8a5b7366 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:42:17 +0100 Subject: [PATCH 1/8] collect_honeycomb trigger This trigger specifically fires when right-clicking a beehive or bee_nest with shears when it has honey level 5. --- .../willfp/libreforge/triggers/Triggers.kt | 92 +------------------ .../triggers/impl/TriggerCollectHoneycomb.kt | 67 ++++++++++++++ 2 files changed, 69 insertions(+), 90 deletions(-) create mode 100644 core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoneycomb.kt diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt index d458645b..e0201709 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt @@ -2,96 +2,7 @@ package com.willfp.libreforge.triggers import com.willfp.eco.core.registry.Registry import com.willfp.libreforge.mutators.MutatorList -import com.willfp.libreforge.triggers.impl.TriggerAltClick -import com.willfp.libreforge.triggers.impl.TriggerBite -import com.willfp.libreforge.triggers.impl.TriggerBlockItemDrop -import com.willfp.libreforge.triggers.impl.TriggerBowAttack -import com.willfp.libreforge.triggers.impl.TriggerBreed -import com.willfp.libreforge.triggers.impl.TriggerBrew -import com.willfp.libreforge.triggers.impl.TriggerBrewIngredient -import com.willfp.libreforge.triggers.impl.TriggerCastRod -import com.willfp.libreforge.triggers.impl.TriggerCatchEntity -import com.willfp.libreforge.triggers.impl.TriggerCatchFish -import com.willfp.libreforge.triggers.impl.TriggerCatchFishFail -import com.willfp.libreforge.triggers.impl.TriggerChangeArmor -import com.willfp.libreforge.triggers.impl.TriggerChangeChunk -import com.willfp.libreforge.triggers.impl.TriggerChangeWorld -import com.willfp.libreforge.triggers.impl.TriggerClickBlock -import com.willfp.libreforge.triggers.impl.TriggerClickEntity -import com.willfp.libreforge.triggers.impl.TriggerCompleteAdvancement -import com.willfp.libreforge.triggers.impl.TriggerConsume -import com.willfp.libreforge.triggers.impl.TriggerCraft -import com.willfp.libreforge.triggers.impl.TriggerDamageItem -import com.willfp.libreforge.triggers.impl.TriggerDeath -import com.willfp.libreforge.triggers.impl.TriggerDeployElytra -import com.willfp.libreforge.triggers.impl.TriggerDisable -import com.willfp.libreforge.triggers.impl.TriggerDrink -import com.willfp.libreforge.triggers.impl.TriggerDropItem -import com.willfp.libreforge.triggers.impl.TriggerEmptyBucket -import com.willfp.libreforge.triggers.impl.TriggerEnable -import com.willfp.libreforge.triggers.impl.TriggerEnchantItem -import com.willfp.libreforge.triggers.impl.TriggerEnterBed -import com.willfp.libreforge.triggers.impl.TriggerEntityBreakDoor -import com.willfp.libreforge.triggers.impl.TriggerEntityCatchFireFromBlock -import com.willfp.libreforge.triggers.impl.TriggerEntityCatchFireFromEntity -import com.willfp.libreforge.triggers.impl.TriggerEntityDamage -import com.willfp.libreforge.triggers.impl.TriggerEntityDamageByEntity -import com.willfp.libreforge.triggers.impl.TriggerEntityDeath -import com.willfp.libreforge.triggers.impl.TriggerEntityItemDrop -import com.willfp.libreforge.triggers.impl.TriggerEntitySpawn -import com.willfp.libreforge.triggers.impl.TriggerEntityTarget -import com.willfp.libreforge.triggers.impl.TriggerEntityTeleport -import com.willfp.libreforge.triggers.impl.TriggerFallDamage -import com.willfp.libreforge.triggers.impl.TriggerFillBucket -import com.willfp.libreforge.triggers.impl.TriggerGainHunger -import com.willfp.libreforge.triggers.impl.TriggerGainXp -import com.willfp.libreforge.triggers.impl.TriggerGroupCustom -import com.willfp.libreforge.triggers.impl.TriggerGroupGlobalStatic -import com.willfp.libreforge.triggers.impl.TriggerGroupStatic -import com.willfp.libreforge.triggers.impl.TriggerHeadshot -import com.willfp.libreforge.triggers.impl.TriggerHeal -import com.willfp.libreforge.triggers.impl.TriggerHoldItem -import com.willfp.libreforge.triggers.impl.TriggerHookInGround -import com.willfp.libreforge.triggers.impl.TriggerItemBreak -import com.willfp.libreforge.triggers.impl.TriggerJoin -import com.willfp.libreforge.triggers.impl.TriggerJump -import com.willfp.libreforge.triggers.impl.TriggerKill -import com.willfp.libreforge.triggers.impl.TriggerLeashEntity -import com.willfp.libreforge.triggers.impl.TriggerLeave -import com.willfp.libreforge.triggers.impl.TriggerLeaveBed -import com.willfp.libreforge.triggers.impl.TriggerLevelUpItem -import com.willfp.libreforge.triggers.impl.TriggerLevelUpXp -import com.willfp.libreforge.triggers.impl.TriggerLoseHunger -import com.willfp.libreforge.triggers.impl.TriggerLosePotionEffect -import com.willfp.libreforge.triggers.impl.TriggerMeleeAttack -import com.willfp.libreforge.triggers.impl.TriggerMineBlock -import com.willfp.libreforge.triggers.impl.TriggerMineBlockProgress -import com.willfp.libreforge.triggers.impl.TriggerMove -import com.willfp.libreforge.triggers.impl.TriggerPickUpItem -import com.willfp.libreforge.triggers.impl.TriggerPlaceBlock -import com.willfp.libreforge.triggers.impl.TriggerPotionEffect -import com.willfp.libreforge.triggers.impl.TriggerProjectileHit -import com.willfp.libreforge.triggers.impl.TriggerProjectileLaunch -import com.willfp.libreforge.triggers.impl.TriggerReelIn -import com.willfp.libreforge.triggers.impl.TriggerRespawn -import com.willfp.libreforge.triggers.impl.TriggerRunCommand -import com.willfp.libreforge.triggers.impl.TriggerSellItem -import com.willfp.libreforge.triggers.impl.TriggerSendMessage -import com.willfp.libreforge.triggers.impl.TriggerShearEntity -import com.willfp.libreforge.triggers.impl.TriggerShieldBlock -import com.willfp.libreforge.triggers.impl.TriggerShootBow -import com.willfp.libreforge.triggers.impl.TriggerSmelt -import com.willfp.libreforge.triggers.impl.TriggerSmithItem -import com.willfp.libreforge.triggers.impl.TriggerSwapHands -import com.willfp.libreforge.triggers.impl.TriggerTakeDamage -import com.willfp.libreforge.triggers.impl.TriggerTakeEntityDamage -import com.willfp.libreforge.triggers.impl.TriggerTameAnimal -import com.willfp.libreforge.triggers.impl.TriggerTeleport -import com.willfp.libreforge.triggers.impl.TriggerToggleFlight -import com.willfp.libreforge.triggers.impl.TriggerToggleSneak -import com.willfp.libreforge.triggers.impl.TriggerToggleSprint -import com.willfp.libreforge.integrations.paper.impl.TriggerTridentAttack -import com.willfp.libreforge.triggers.impl.TriggerWinRaid +import com.willfp.libreforge.triggers.impl.* object Triggers : Registry() { private val groupRegistry = Registry() @@ -227,5 +138,6 @@ object Triggers : Registry() { register(TriggerEntityTeleport) register(TriggerCompleteAdvancement) register(TriggerSmithItem) + register(TriggerCollectHoneycomb) } } diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoneycomb.kt b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoneycomb.kt new file mode 100644 index 00000000..62cd26b1 --- /dev/null +++ b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoneycomb.kt @@ -0,0 +1,67 @@ +package com.willfp.libreforge.triggers.impl + +import com.willfp.libreforge.toDispatcher +import com.willfp.libreforge.triggers.Trigger +import com.willfp.libreforge.triggers.TriggerData +import com.willfp.libreforge.triggers.TriggerParameter +import org.bukkit.Material +import org.bukkit.block.data.type.Beehive +import org.bukkit.event.EventHandler +import org.bukkit.event.block.Action +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.EquipmentSlot + +object TriggerCollectHoneycomb : Trigger("collect_honeycomb") { + override val parameters = setOf( + TriggerParameter.PLAYER, + TriggerParameter.LOCATION, + TriggerParameter.BLOCK, + TriggerParameter.EVENT + ) + + @EventHandler(ignoreCancelled = true) + fun handle(event: PlayerInteractEvent) { + val block = event.clickedBlock ?: return + val player = event.player + + if (event.action != Action.RIGHT_CLICK_BLOCK) { + return + } + + if (block.type != Material.BEEHIVE && block.type != Material.BEE_NEST) { + return + } + + val beehive = block.blockData as? Beehive ?: return + if (beehive.honeyLevel != 5) { + return + } + + val mainHandItem = player.inventory.itemInMainHand + val offHandItem = player.inventory.itemInOffHand + val isShearsInMainHand = mainHandItem.type == Material.SHEARS + val isShearsInOffHand = offHandItem.type == Material.SHEARS + + if (!isShearsInMainHand && !isShearsInOffHand) { + return + } + + if (event.hand == EquipmentSlot.HAND && isShearsInMainHand) { + triggerEvent(player, block, event) + } else if (event.hand == EquipmentSlot.OFF_HAND && isShearsInOffHand) { + triggerEvent(player, block, event) + } + } + + private fun triggerEvent(player: org.bukkit.entity.Player, block: org.bukkit.block.Block, event: PlayerInteractEvent) { + this.dispatch( + player.toDispatcher(), + TriggerData( + player = player, + location = block.location, + block = block, + event = event + ) + ) + } +} From d6c691f3bd713d01b6149184aac6daadb586b3c0 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:48:41 +0100 Subject: [PATCH 2/8] collect_honey trigger This trigger will fire specifically when a player collects honey in a bottle from a beehive or bee_nest with a honey level of 5 --- .../willfp/libreforge/triggers/Triggers.kt | 1 + .../triggers/impl/TriggerCollectHoney.kt | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoney.kt diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt index e0201709..7b9c36fe 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt @@ -139,5 +139,6 @@ object Triggers : Registry() { register(TriggerCompleteAdvancement) register(TriggerSmithItem) register(TriggerCollectHoneycomb) + register(TriggerCollectHoney) } } diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoney.kt b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoney.kt new file mode 100644 index 00000000..afd8dc30 --- /dev/null +++ b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoney.kt @@ -0,0 +1,67 @@ +package com.willfp.libreforge.triggers.impl + +import com.willfp.libreforge.toDispatcher +import com.willfp.libreforge.triggers.Trigger +import com.willfp.libreforge.triggers.TriggerData +import com.willfp.libreforge.triggers.TriggerParameter +import org.bukkit.Material +import org.bukkit.block.data.type.Beehive +import org.bukkit.event.EventHandler +import org.bukkit.event.block.Action +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.EquipmentSlot + +object TriggerCollectHoney : Trigger("collect_honey") { + override val parameters = setOf( + TriggerParameter.PLAYER, + TriggerParameter.LOCATION, + TriggerParameter.BLOCK, + TriggerParameter.EVENT + ) + + @EventHandler(ignoreCancelled = true) + fun handle(event: PlayerInteractEvent) { + val block = event.clickedBlock ?: return + val player = event.player + + if (event.action != Action.RIGHT_CLICK_BLOCK) { + return + } + + if (block.type != Material.BEEHIVE && block.type != Material.BEE_NEST) { + return + } + + val beehive = block.blockData as? Beehive ?: return + if (beehive.honeyLevel != 5) { + return + } + + val mainHandItem = player.inventory.itemInMainHand + val offHandItem = player.inventory.itemInOffHand + val isBottleInMainHand = mainHandItem.type == Material.GLASS_BOTTLE + val isBottleInOffHand = offHandItem.type == Material.GLASS_BOTTLE + + if (!isBottleInMainHand && !isBottleInOffHand) { + return + } + + if (event.hand == EquipmentSlot.HAND && isBottleInMainHand) { + triggerEvent(player, block, event) + } else if (event.hand == EquipmentSlot.OFF_HAND && isBottleInOffHand) { + triggerEvent(player, block, event) + } + } + + private fun triggerEvent(player: org.bukkit.entity.Player, block: org.bukkit.block.Block, event: PlayerInteractEvent) { + this.dispatch( + player.toDispatcher(), + TriggerData( + player = player, + location = block.location, + block = block, + event = event + ) + ) + } +} From f66687c574fc8cc841d49e5a86142164982442b2 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Thu, 19 Sep 2024 20:15:15 +0100 Subject: [PATCH 3/8] added `honey_level_full` filter this checks if the beehive/bee_nest is full of honey (honey-level:5). --- .../com/willfp/libreforge/filters/Filters.kt | 38 +---------- .../filters/impl/FilterHoneyLevelFull.kt | 25 +++++++ .../willfp/libreforge/triggers/Triggers.kt | 2 - .../triggers/impl/TriggerCollectHoney.kt | 67 ------------------- .../triggers/impl/TriggerCollectHoneycomb.kt | 67 ------------------- 5 files changed, 27 insertions(+), 172 deletions(-) create mode 100644 core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterHoneyLevelFull.kt delete mode 100644 core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoney.kt delete mode 100644 core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoneycomb.kt diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt b/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt index 84734cb1..283803b5 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt @@ -7,42 +7,7 @@ import com.willfp.eco.core.registry.Registry import com.willfp.libreforge.ConfigWarning import com.willfp.libreforge.ViolationContext import com.willfp.libreforge.deprecationMessage -import com.willfp.libreforge.filters.impl.FilterAboveHealthPercent -import com.willfp.libreforge.filters.impl.FilterAdvancements -import com.willfp.libreforge.filters.impl.FilterBlocks -import com.willfp.libreforge.filters.impl.FilterDamageCause -import com.willfp.libreforge.filters.impl.FilterEnchant -import com.willfp.libreforge.filters.impl.FilterEntities -import com.willfp.libreforge.filters.impl.FilterFromSpawner -import com.willfp.libreforge.filters.impl.FilterFullyCharged -import com.willfp.libreforge.filters.impl.FilterFullyGrown -import com.willfp.libreforge.filters.impl.FilterIsBehindVictim -import com.willfp.libreforge.filters.impl.FilterIsBoss -import com.willfp.libreforge.filters.impl.FilterIsExpressionTrue -import com.willfp.libreforge.filters.impl.FilterIsNPC -import com.willfp.libreforge.filters.impl.FilterIsPassive -import com.willfp.libreforge.filters.impl.FilterItemDurabilityAbove -import com.willfp.libreforge.filters.impl.FilterItemDurabilityAbovePercent -import com.willfp.libreforge.filters.impl.FilterItemDurabilityBelow -import com.willfp.libreforge.filters.impl.FilterItemDurabilityBelowPercent -import com.willfp.libreforge.filters.impl.FilterItems -import com.willfp.libreforge.filters.impl.FilterOnMaxHealth -import com.willfp.libreforge.filters.impl.FilterOnlyBosses -import com.willfp.libreforge.filters.impl.FilterOnlyNonBosses -import com.willfp.libreforge.filters.impl.FilterPlayerName -import com.willfp.libreforge.filters.impl.FilterPlayerPlaced -import com.willfp.libreforge.filters.impl.FilterPotionEffect -import com.willfp.libreforge.filters.impl.FilterProjectiles -import com.willfp.libreforge.filters.impl.FilterSpawnerEntity -import com.willfp.libreforge.filters.impl.FilterSwept -import com.willfp.libreforge.filters.impl.FilterText -import com.willfp.libreforge.filters.impl.FilterTextContains -import com.willfp.libreforge.filters.impl.FilterThisItem -import com.willfp.libreforge.filters.impl.FilterValueAbove -import com.willfp.libreforge.filters.impl.FilterValueBelow -import com.willfp.libreforge.filters.impl.FilterValueEquals -import com.willfp.libreforge.filters.impl.FilterVictimConditions -import com.willfp.libreforge.filters.impl.FilterVictimName +import com.willfp.libreforge.filters.impl.* object Filters : Registry>() { /** @@ -130,5 +95,6 @@ object Filters : Registry>() { register(FilterEnchant) register(FilterSpawnerEntity) register(FilterSwept) + register(FilterHoneyLevelFull) } } diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterHoneyLevelFull.kt b/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterHoneyLevelFull.kt new file mode 100644 index 00000000..26b03db5 --- /dev/null +++ b/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterHoneyLevelFull.kt @@ -0,0 +1,25 @@ +package com.willfp.libreforge.filters.impl + +import com.willfp.eco.core.config.interfaces.Config +import com.willfp.libreforge.NoCompileData +import com.willfp.libreforge.filters.Filter +import com.willfp.libreforge.triggers.TriggerData +import org.bukkit.Material +import org.bukkit.block.data.type.Beehive + +object FilterHoneyLevelFull : Filter("honey_level_full") { + override fun getValue(config: Config, data: TriggerData?, key: String): Boolean { + return true // This filter checks for maximum honey level (5) + } + + override fun isMet(data: TriggerData, value: Boolean, compileData: NoCompileData): Boolean { + val block = data.block ?: return false + + if (block.type == Material.BEEHIVE || block.type == Material.BEE_NEST) { + val beehiveData = block.blockData as? Beehive ?: return false + return beehiveData.honeyLevel == 5 + } + + return false + } +} diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt index 7b9c36fe..abc2ff5d 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/Triggers.kt @@ -138,7 +138,5 @@ object Triggers : Registry() { register(TriggerEntityTeleport) register(TriggerCompleteAdvancement) register(TriggerSmithItem) - register(TriggerCollectHoneycomb) - register(TriggerCollectHoney) } } diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoney.kt b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoney.kt deleted file mode 100644 index afd8dc30..00000000 --- a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoney.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.willfp.libreforge.triggers.impl - -import com.willfp.libreforge.toDispatcher -import com.willfp.libreforge.triggers.Trigger -import com.willfp.libreforge.triggers.TriggerData -import com.willfp.libreforge.triggers.TriggerParameter -import org.bukkit.Material -import org.bukkit.block.data.type.Beehive -import org.bukkit.event.EventHandler -import org.bukkit.event.block.Action -import org.bukkit.event.player.PlayerInteractEvent -import org.bukkit.inventory.EquipmentSlot - -object TriggerCollectHoney : Trigger("collect_honey") { - override val parameters = setOf( - TriggerParameter.PLAYER, - TriggerParameter.LOCATION, - TriggerParameter.BLOCK, - TriggerParameter.EVENT - ) - - @EventHandler(ignoreCancelled = true) - fun handle(event: PlayerInteractEvent) { - val block = event.clickedBlock ?: return - val player = event.player - - if (event.action != Action.RIGHT_CLICK_BLOCK) { - return - } - - if (block.type != Material.BEEHIVE && block.type != Material.BEE_NEST) { - return - } - - val beehive = block.blockData as? Beehive ?: return - if (beehive.honeyLevel != 5) { - return - } - - val mainHandItem = player.inventory.itemInMainHand - val offHandItem = player.inventory.itemInOffHand - val isBottleInMainHand = mainHandItem.type == Material.GLASS_BOTTLE - val isBottleInOffHand = offHandItem.type == Material.GLASS_BOTTLE - - if (!isBottleInMainHand && !isBottleInOffHand) { - return - } - - if (event.hand == EquipmentSlot.HAND && isBottleInMainHand) { - triggerEvent(player, block, event) - } else if (event.hand == EquipmentSlot.OFF_HAND && isBottleInOffHand) { - triggerEvent(player, block, event) - } - } - - private fun triggerEvent(player: org.bukkit.entity.Player, block: org.bukkit.block.Block, event: PlayerInteractEvent) { - this.dispatch( - player.toDispatcher(), - TriggerData( - player = player, - location = block.location, - block = block, - event = event - ) - ) - } -} diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoneycomb.kt b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoneycomb.kt deleted file mode 100644 index 62cd26b1..00000000 --- a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerCollectHoneycomb.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.willfp.libreforge.triggers.impl - -import com.willfp.libreforge.toDispatcher -import com.willfp.libreforge.triggers.Trigger -import com.willfp.libreforge.triggers.TriggerData -import com.willfp.libreforge.triggers.TriggerParameter -import org.bukkit.Material -import org.bukkit.block.data.type.Beehive -import org.bukkit.event.EventHandler -import org.bukkit.event.block.Action -import org.bukkit.event.player.PlayerInteractEvent -import org.bukkit.inventory.EquipmentSlot - -object TriggerCollectHoneycomb : Trigger("collect_honeycomb") { - override val parameters = setOf( - TriggerParameter.PLAYER, - TriggerParameter.LOCATION, - TriggerParameter.BLOCK, - TriggerParameter.EVENT - ) - - @EventHandler(ignoreCancelled = true) - fun handle(event: PlayerInteractEvent) { - val block = event.clickedBlock ?: return - val player = event.player - - if (event.action != Action.RIGHT_CLICK_BLOCK) { - return - } - - if (block.type != Material.BEEHIVE && block.type != Material.BEE_NEST) { - return - } - - val beehive = block.blockData as? Beehive ?: return - if (beehive.honeyLevel != 5) { - return - } - - val mainHandItem = player.inventory.itemInMainHand - val offHandItem = player.inventory.itemInOffHand - val isShearsInMainHand = mainHandItem.type == Material.SHEARS - val isShearsInOffHand = offHandItem.type == Material.SHEARS - - if (!isShearsInMainHand && !isShearsInOffHand) { - return - } - - if (event.hand == EquipmentSlot.HAND && isShearsInMainHand) { - triggerEvent(player, block, event) - } else if (event.hand == EquipmentSlot.OFF_HAND && isShearsInOffHand) { - triggerEvent(player, block, event) - } - } - - private fun triggerEvent(player: org.bukkit.entity.Player, block: org.bukkit.block.Block, event: PlayerInteractEvent) { - this.dispatch( - player.toDispatcher(), - TriggerData( - player = player, - location = block.location, - block = block, - event = event - ) - ) - } -} From 4fa6df8da105892bda0182da06c61330f882cba7 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:49:33 +0100 Subject: [PATCH 4/8] Update FilterHoneyLevelFull.kt --- .../com/willfp/libreforge/filters/impl/FilterHoneyLevelFull.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterHoneyLevelFull.kt b/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterHoneyLevelFull.kt index 26b03db5..3ba6a256 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterHoneyLevelFull.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterHoneyLevelFull.kt @@ -9,7 +9,7 @@ import org.bukkit.block.data.type.Beehive object FilterHoneyLevelFull : Filter("honey_level_full") { override fun getValue(config: Config, data: TriggerData?, key: String): Boolean { - return true // This filter checks for maximum honey level (5) + return true } override fun isMet(data: TriggerData, value: Boolean, compileData: NoCompileData): Boolean { From e9490b155b9a6dcef45151f5d2945909a5b737cf Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Sat, 21 Sep 2024 17:31:20 +0100 Subject: [PATCH 5/8] added `sheep_color` filter Adds a filter that checks for sheep's color when killed, sheared, etc. --- .../com/willfp/libreforge/filters/Filters.kt | 1 + .../filters/impl/FilterSheepColor.kt | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterSheepColor.kt diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt b/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt index 283803b5..519bbf57 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt @@ -96,5 +96,6 @@ object Filters : Registry>() { register(FilterSpawnerEntity) register(FilterSwept) register(FilterHoneyLevelFull) + register(FilterEntityColor) } } diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterSheepColor.kt b/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterSheepColor.kt new file mode 100644 index 00000000..cf824805 --- /dev/null +++ b/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterSheepColor.kt @@ -0,0 +1,20 @@ +package com.willfp.libreforge.filters.impl + +import com.willfp.eco.core.config.interfaces.Config +import com.willfp.libreforge.NoCompileData +import com.willfp.libreforge.filters.Filter +import com.willfp.libreforge.triggers.TriggerData +import org.bukkit.entity.Sheep + +object FilterEntityColor : Filter>("entity_color") { + override fun getValue(config: Config, data: TriggerData?, key: String): Collection { + return config.getStrings(key) + } + + override fun isMet(data: TriggerData, value: Collection, compileData: NoCompileData): Boolean { + val entity = data.victim as? Sheep ?: return false + val entityColor = entity.color?.name + + return value.any { it.equals(entityColor, ignoreCase = true) } + } +} From 3aee26dff268d91d02bca5d8a91ae2d754222f30 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Sat, 21 Sep 2024 17:32:40 +0100 Subject: [PATCH 6/8] `shear_entity` now works on snowman/snow_golem --- .../com/willfp/libreforge/triggers/impl/TriggerShearEntity.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerShearEntity.kt b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerShearEntity.kt index da6f6f8d..e140d3a3 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerShearEntity.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerShearEntity.kt @@ -1,6 +1,5 @@ package com.willfp.libreforge.triggers.impl -import com.willfp.eco.core.Prerequisite import com.willfp.libreforge.proxy.renamedValues import com.willfp.libreforge.toDispatcher import com.willfp.libreforge.triggers.Trigger @@ -23,7 +22,7 @@ object TriggerShearEntity : Trigger("shear_entity") { fun handle(event: PlayerShearEntityEvent) { val entity = event.entity as? LivingEntity ?: return - if (entity.type !in listOf(EntityType.SHEEP, renamedValues().entities.mooshroom)) { + if (entity.type !in listOf(EntityType.SHEEP, EntityType.SNOWMAN, renamedValues().entities.mooshroom)) { return } From 0bc9989bf123cd3525d95f30c103b93ae743e393 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Sat, 21 Sep 2024 17:36:13 +0100 Subject: [PATCH 7/8] Corrected file name --- .../filters/impl/{FilterSheepColor.kt => FilterEntityColor.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/{FilterSheepColor.kt => FilterEntityColor.kt} (100%) diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterSheepColor.kt b/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterEntityColor.kt similarity index 100% rename from core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterSheepColor.kt rename to core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterEntityColor.kt From 14a25cbb9340b26843d27bc1c95be79c1df3fefb Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Sat, 21 Sep 2024 17:39:21 +0100 Subject: [PATCH 8/8] reverted back to `sheep_color` to avoid confusion --- .../main/kotlin/com/willfp/libreforge/filters/Filters.kt | 2 +- .../impl/{FilterEntityColor.kt => FilterSheepColor.kt} | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/{FilterEntityColor.kt => FilterSheepColor.kt} (74%) diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt b/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt index 519bbf57..cdb4e269 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/filters/Filters.kt @@ -96,6 +96,6 @@ object Filters : Registry>() { register(FilterSpawnerEntity) register(FilterSwept) register(FilterHoneyLevelFull) - register(FilterEntityColor) + register(FilterSheepColor) } } diff --git a/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterEntityColor.kt b/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterSheepColor.kt similarity index 74% rename from core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterEntityColor.kt rename to core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterSheepColor.kt index cf824805..a6f9a9fb 100644 --- a/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterEntityColor.kt +++ b/core/common/src/main/kotlin/com/willfp/libreforge/filters/impl/FilterSheepColor.kt @@ -6,15 +6,15 @@ import com.willfp.libreforge.filters.Filter import com.willfp.libreforge.triggers.TriggerData import org.bukkit.entity.Sheep -object FilterEntityColor : Filter>("entity_color") { +object FilterSheepColor : Filter>("sheep_color") { override fun getValue(config: Config, data: TriggerData?, key: String): Collection { return config.getStrings(key) } override fun isMet(data: TriggerData, value: Collection, compileData: NoCompileData): Boolean { val entity = data.victim as? Sheep ?: return false - val entityColor = entity.color?.name + val sheepColor = entity.color?.name - return value.any { it.equals(entityColor, ignoreCase = true) } + return value.any { it.equals(sheepColor, ignoreCase = true) } } }