Solved How to get a player's inventory from "EntityDamageByEntityEvent"

Discussion in 'Spigot Plugin Development' started by Hackzz, Jul 20, 2021.

Thread Status:
Not open for further replies.
  1. I can't seem to be able to get a player's inventory using this code:

    public void PlayerHitEvent(EntityDamageByEntityEvent e)
  2. You should use another event, this one in not working on a player(I'm not sure tho)
  3. hmm not sure what other event I should be using though.
    Also the issue is that the entity class doesen't have a .getInventory() method wich is wierd to me..
  4. You will have to check if the Entity is an instance of Player and cast it then.
    Code (Java):
    if(event.getDamager() instanceof Player) {
        Player player = (Player) event.getDamager();
        PlayerInventory inventory = player.getInventory();
    #4 Sxlver_, Jul 20, 2021
    Last edited: Jul 20, 2021
  5. Thanks I had thought about that but I couldn't access the method still, I'll try and see what happens :O
    • Like Like x 1
  6. Seems to work, I'll close the thread :)
Thread Status:
Not open for further replies.