Compare commits
1 commit
main
...
next/1.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c5027b3b2 |
1 changed files with 26 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue