1.16.5 event.getInventory() does not work

Discussion in 'Spigot Plugin Development' started by luan2809, Jul 7, 2021.

  1. I created a custom Inventory and I want to disable player to taking item out of it but it seems doesn't work. And there is no error on the console.
    My "Inventory" code

    And the disable part
  2. Did you register the event in the main class?
  3. Since Invento doesn't implement Inventory,
    Code (Java):
    if(event.getInventory() instanceof Invento){
    will always be false. I think you want to use a custom inventory holder to know if an inventoy is from your plugin or not (not recomended to do this), but if you want it this way, your check should be
    Code (Java):
    if(event.getInventory().getHolder() instanceof Invento){
    and you should change the constructor to
    Code (Java):
    public Invento() {
      inv = Bukkit.createInventory(this, 9, "A");
  4. It's works but this line of code doesn't work yet.

    Attached Files:

  5. I presume you have 9 as the size of your inventory so slot 9 is really not existed in the first place. only available slots are from 0 to 8 that is the reason that code is not firing.
    • Agree Agree x 1
  6. Oh, thank you.