Search code examples
javapluginsminecraftbukkit

How would I go with calling a function when changing inventory items


Ok, so the problem is the following...

I'm trying to make some kind of "invsee" plugin and I want to refresh the inventory every time the inventory has changed.

All I've tried 'till this point is InventoryClickEvent and InventoryInteractionEvent.

That's where I have a problem. InventoryClickEvent only updates after the player click again after moving the item for me to refresh it.

For example, when a player picks up an item, I don't see it gone, unless he places it back down. When he does, I don't see it until he picks up another item, which I don't see it disappear unless he places it back down. ETC!

I want it to be "realtime" and I don't want to use Scheduler, because I've already tried that, but when I do that, screen flashes.

Thanks for the help, if you need parts of code or something just say.

MGlolenstine


Solution

  • Unless you intend to perform more complex actions other than looking at and possibly manipulating a player's inventory you can simplify this task. Given two Player objects admin and target, where admin needs to look at target's inventory, you can view the inventory as follows:

    Player admin = ...
    Player target = ...
    admin.openInventory( target.getInventory() );
    

    This will allow you to view, add, remove, or change items in target's inventory.