Chest

Discussion in 'Plugin Help' started by ResooTR43, Apr 9, 2021.

  1. ResooTR43

    ResooTR43 Spider

    Messages:
    7
    When I click on the Chest, I want it not to open. How can I do it?
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    746
    Most efficient way to do this would be to cancel InventoryOpenEvent

    PHP:
    public function onInventoryOpen(InventoryOpenEvent $event) {
        if(
    $event->getInventory() instanceof ChestInventory) {
            
    $event->setCancelled();
        }
    }
     
    minijaham likes this.
  3. minijaham

    minijaham Zombie Pigman

    Messages:
    799
    GitHub:
    minijaham
    You can also try cancelling the PlayerInteractEvent!

    PHP:
    public function onInteract(PlayerInteractEvent $event) {
        if(
    $event->getBlock()->getId() === Block::CHEST) { 
            
    $event->setCancelled();
        }
    }
     
  4. Primus

    Primus Zombie Pigman

    Messages:
    746
    That would also work, but will get triggered more unnecessarily. Not all interaction events results in chest being open.
     
    DavyCraft648 and minijaham like this.
  5. minijaham

    minijaham Zombie Pigman

    Messages:
    799
    GitHub:
    minijaham
    Ah, I see. Thanks for pointing that out!
     
    Primus likes this.
  6. ResooTR43

    ResooTR43 Spider

    Messages:
    7
    Thank you
     
  7. minijaham

    minijaham Zombie Pigman

    Messages:
    799
    GitHub:
    minijaham
    Wait, but wouldn't that get triggered for enderchests too? Or is there a separate inventory for enderchests?
     
  8. Primus

    Primus Zombie Pigman

    Messages:
    746
    Yes it would, but its not being spammed as interactions packets are.
     
    minijaham likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.