Solved Is there any way to tell if a player destroyed an armor stand if that player was holding an object?

Discussion in 'Spigot Plugin Development' started by Fredashay, Nov 14, 2017.

  1. Is there any way to tell if a player destroyed an armor stand if that player was holding an object, such as, for example, a cookie?
  2. Code (Text):

    public void onArmorStandDestroy(EntityDeathEvent event) {
      LivingEntity entity = event.getEntity();
      if(!(entity instanceof ArmorStand)) return;
      Player destroyer = entity.getKiller();
      if(destroyer.getInventory().getInventory().getItemInMainHand().getType() != Material.COOKIE) return;
      // Do your work here
    • Like Like x 1
    • Agree Agree x 1
    • Winner Winner x 1
  3. Aha! An armor stand is an entity, so test if someone "killed" it, lol. Thanks! :)

    P.S. I hate armor stands!!!
  4. Oh, wait! That event is not cancelable! It's useless for my purposes :-(

    P.P.S. Did I tell you I HATE armor stands!!!!!!
  5. BlockBreakEvent?
  6. Armor stands are entities, not blocks.
    • Agree Agree x 1
    • Informative Informative x 1
  7. I'm not sure how well this will work, but you could use an EntityDamageByEntityEvent, and check if the armor stand's health has been set to 0. Not sure if Armor Stands even have health...
  8. Armor stands do have something with BlockEvents. I cant remember if its place or break. Make a quick block break, and then print e.getBlock().getType().name(); to test this. If its a blockbreak event you’re set
  9. Just an idea, not sure if it'd work:

    Use the EntityDeathEvent, and if the player is holding a cookie, use Entity.setInvulnerable(true); Like I said, unsure, but only 1 way to find out :)
  10. ItzDemeng7215

    ItzDemeng7215 Previously Demeng7215

    Next time try explaining it instead of just spoonfeeding the code.
  11. Next time try contributing something valuable to the topic instead of complaining about those who do.

    PlayerInteractEntityEvent is cancellable and should work fine. I don't know if that helps in your specific case though since it doesn't tell you if the entity was hurt.
    • Agree Agree x 2
    • Optimistic Optimistic x 1
  12. You can heal an entity in the death event, preventing it from dying.
  13. I wrote a plugin that fires every cancellable event listed in the Javadocs here:

    It's too big to post in a message, but I'll email the source to anyone who wants it...

    Block events don't fire for actions on armor stands.

    If you place an armor stand, it fires PlayerInteractEvent.

    If you put an item or remove an item on an armor stand, it fires both PlayerArmorStandManipulateEvent and PlayerInteractAtEntityEvent.

    If you destroy an armor stand...
    - It fires EntityDamageByEntityEvent, but this gets fired even if the armor stand is touched, not necessarily destroyed.
    - it fires PlayerInteractEvent, but if you're holding an item in your hand (such as, for example, a sign) it only tells you the object you were holding, but no mention whatsoever that an armor stand was involved in the event.
    - It fires EntityDeathEvent, but it doesn't tell you who destroyed the armor stand, nor can you cancel the event.

    P.P.P.S. Did I mention that I absolutely DESPISE armor stands!!!!!
  14. Armor stands have a health system, yes? Use the damage in the event to calculate if it should die from the hit.
    Yes it does - Entity#getLastDamageCause returns the last EntityDamageEvent last fired when the entity was hurt. If it was an EntityDamageByEntityEvent, you can get the killer from that. Then, as previously stated in this thread, you just heal it to prevent death.

    Either solution should work. Just a bit of legwork.
    • Like Like x 1
  15. Next time why don't you learn more Java
    • Optimistic Optimistic x 1
  16. ItzDemeng7215

    ItzDemeng7215 Previously Demeng7215

    You need to stop fucking following me around and making useless replies. @Sataniel, you better tell him to
    • Optimistic Optimistic x 1
  17. Yes! A quick build and test shows that seems to work! Thanks!!!

    And to the rest of you, please stop making references to Noobs and Spoon Feeding, and let's all just help each other. Thanks :)
    • Like Like x 1

Share This Page