Solved Get who dyed sheep

Discussion in 'Spigot Plugin Development' started by BanePig, Jul 18, 2021.

  1. There is a SheepDyeWoolEvent in Spigot, but I don't see any way to get who actually dyed the sheep. Is there really no way to do this? I just need to prevent a player holding a certain item from dying a sheep. Canceling an interact event doesn't seem to do this either.
     
  2. PlayerInteractEvent

    If
    1) Check if the entity clicked is an instance of a sheep.
    2) Check if dye is in hand
    Then the player is dying sheep.
     
  3. For testing I made this event:
    Code (Java):
    @EventHandler
    fun onInteract(ev: PlayerInteractEvent) {
        if(ev.player.inventory.itemInMainHand.type.name.contains("DYE"))
            ev.isCancelled = true
    }
    I can still dye sheep, even when ev.isCancelled = true is called.
    This is kotlin code, so isCancelled is used instead of setCancelled(), but it does the same thing.
     
  4. Try PlayerInteractEntityEvent and/or PlayerInteractAtEntityEvent

    https://hub.spigotmc.org/jira/browse/SPIGOT-6657
     
    #4 HexedHero, Jul 18, 2021
    Last edited: Jul 18, 2021
    • Winner Winner x 1
  5. PlayerInteractAtEntity event does not work, but PlayerInteractEntityEvent did, thanks!
     
  6. md_5

    Administrator Developer

    • Like Like x 3
    • Friendly Friendly x 3
    • Winner Winner x 1
  7. It is committed into https://hub.spigotmc.org/ so it is an official change.
     
  8. wow... unexpected but welcome change