From 2c5027b3b20b7e8fb1243d875bf7592c95df0b93 Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Fri, 21 Aug 2026 14:25:36 +0100 Subject: [PATCH] Add locator function to adoption papers --- .../bestbuds/modules/AdoptionModule.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/kotlin/ch/offbeatwit/bestbuds/modules/AdoptionModule.kt b/src/main/kotlin/ch/offbeatwit/bestbuds/modules/AdoptionModule.kt index cfb1b83..d6b2811 100644 --- a/src/main/kotlin/ch/offbeatwit/bestbuds/modules/AdoptionModule.kt +++ b/src/main/kotlin/ch/offbeatwit/bestbuds/modules/AdoptionModule.kt @@ -2,6 +2,7 @@ package ch.offbeatwit.bestbuds.modules import ch.offbeatwit.bestbuds.ADOPTION_OWNER import ch.offbeatwit.bestbuds.ADOPTION_TARGET +import ch.offbeatwit.bestbuds.inTicks import ch.offbeatwit.bestbuds.isOwnerOf import ch.offbeatwit.bestbuds.managers.Context import ch.offbeatwit.bestbuds.pet.PetInfo @@ -17,9 +18,13 @@ import org.bukkit.entity.Tameable import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.player.PlayerInteractEntityEvent +import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.inventory.EquipmentSlot import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.BookMeta +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType +import kotlin.time.Duration.Companion.seconds class AdoptionModule(ctx: Context) : BestBudsModule(ctx), Listener { val adoptionItem = Material.PAPER @@ -39,6 +44,27 @@ class AdoptionModule(ctx: Context) : BestBudsModule(ctx), Listener { } } + @EventHandler + fun onLocate(ev: PlayerInteractEvent) { + if (!ev.action.isRightClick || !ev.player.isSneaking) return + + val held = ev.item + if (held != null && held.type == Material.WRITTEN_BOOK) { + val bookTarget = held.persistentDataContainer[ADOPTION_TARGET, UUIDDataType] + ?.let { ev.player.world.getEntity(it) } + ?: return + + if (bookTarget is Tameable) { + ev.isCancelled = true + val info = PetInfo(bookTarget) + + ev.player.sendPotionEffectChange(bookTarget, + PotionEffect(PotionEffectType.GLOWING, 5.seconds.inTicks.toInt(), 1)) + ev.player.sendActionBar(tr("Highlighted ").append(info.nameComponent)) + } + } + } + fun setupAdoption(sender: Player, hand: EquipmentSlot, pet: Tameable) { val info = PetInfo(pet) val stack = sender.inventory.getItem(hand)