Solved Dispenser / Armorstand Question

Discussion in 'Spigot Plugin Development' started by Cerus, Sep 7, 2018.

  1. Hey everyone,
    is there an event wich is getting fired when a dispenser "places" armor at a armorstand?
    - Cerus
     
  2. Choco

    Moderator

    After looking through NMS, I've determined that there is no event for this. I do know, however, that it's handled by ItemArmor.a (the field of type IDispenseBehaviour). While that may not be useful to you, it may help me make a PR to have an event called for this. I'll see what I can do. In the mean time, there's no way to catch this. I'll write something for 1.13.1 to improve the BlockDispenseEvent.
     
  3. Alright, thank you :D
     
  4. Choco

    Moderator

    I've actually double checked and it seems as though a BlockDispenseEvent is called for armour equipment by a dispenser. You cannot, however, get the Entity. I will be pull requesting that. So unless you need the entity, you may use BlockDispenseEvent

    EDIT: I have since written a PR to implement the following (https://gfycat.com/DefiniteEachAmericancreamdraft). PR can be found at https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/pull-requests/370/overview

    The code used to execute the above functionality was as follows:
    Code (Java):
    public class TestingPlugin extends JavaPlugin implements Listener {
     
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
        }
     
        @EventHandler
        public void onDispenseArmour(BlockDispenseEvent event) {
            Block block = event.getBlock();
            if (event.getEntity() != null) {
                Bukkit.broadcastMessage(String.format(ChatColor.GRAY + "Dispenser " + ChatColor.YELLOW + "(x:%d, y:%d, z:%d) " + ChatColor.GRAY + "dispensed "
                            + ChatColor.AQUA + "%s " + ChatColor.GRAY + "to entity with name " + ChatColor.GREEN + "%s",
                        block.getX(), block.getY(), block.getZ(), event.getItem().getType().getKey(), event.getEntity().getName())
                );
            }
        }
    }
     
    #4 Choco, Sep 7, 2018
    Last edited: Sep 7, 2018
    • Winner Winner x 2
    • Friendly Friendly x 2
  5. Looks like I have a commit to wait for.
     
    • Like Like x 1
  6. That really cool. Thank you!
     
  7. Choco

    Moderator

    Do note that the above code is currently non-functional. BlockDispenseEvent#getEntity() does not yet exist. I will update this reply if/when the commit gets merged :)
     
  8. Yes, I know that it does not exist ;) But Im confident that it will be added.
     
    • Friendly Friendly x 1
  9. Choco

    Moderator

    After discussion about design changes, the PR was merged and the BlockDispenseArmorEvent now exists
     
  10. Wonderful! Thank you for that feature.
     
    • Like Like x 1