Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

OpenChestEvent

Comments in 'Plugin Development' started by Yosshi999, Jul 24, 2014.

  1. Yosshi999
    Offline

    Yosshi999 New Member Plugin Developer

    Joined:
    Mar 13, 2014
    Posts:
    29
    Plugins:
    1
    Minecraft User:
    Yosshi999
    I'm looking for an event which is called when a chest is opened.
    I tried
    PHP:
    public function onOpenChest(DataPacketSendEvent $event){
            if(
    $event->getPacket() instanceof ContainerOpenPacket){
                
    $this->getLogger()->info("Open");
            }
        }
    but the server also said "Open" when a double chest is opened.
    Would you tell me how to check if it is a (single)chest's packet?
  2. Dutok
    Offline

    Dutok Notable Member Plugin Developer

    Joined:
    Jun 20, 2014
    Posts:
    371
    Plugins:
    3
    Minecraft User:
    Dutok
    I used
    PHP:
    public function onPlayerInteract(PlayerInteractEvent $event){
      if (
    $event->getBlock()->getID() == 54){ //if chest
    This detects when a chest is used, single or double. I'm sure you could make it apply to single only though by telling if the nearby block is a chest or not.
  3. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    and you should specify what type of inventory you want
    use this
    $event->getInventory()->getNetworktype();
    and that well return a number


    chest =0
    Double chest = 1
    player = 2
    furnace = 3
    crafting = 4
    workbench = 5
    stonecutter = 6
    and for closing the inventory use InventoryCloseEvent and the same thing as InventoryOpenEvent
    Last edited: Jul 24, 2014
    PEMapModder and Dutok like this.
  4. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    and you should specify what type of inventory you want
    Dutok likes this.
  5. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    use this
    $event->getInventory()->getNetworktype();
    and that well return a number


    chest =0
    Double chest = 1
    player = 2
    furnace = 3
    crafting = 4
    workbench = 5
    stonecutter = 6
    Dutok likes this.
  6. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    and for closing the inventory use InventoryCloseEvent and the same thing as InventoryOpenEvent
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Can you use the edit button? You made four consecutive posts.
    Jon likes this.
  8. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    i well
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Or, since he wanted to monitor the packet, ContainerOpenPacket->type.
  10. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    as you say "let pocketmine api do the dirty job"
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
  12. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
  13. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That is different...
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Network ID should be referred to as the third parameter in the constructor actually. The IDs you gave are purely the offsets of the inventory type, but it is internal and PocketMine never sends internal things into packets.
  16. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    can you tell me what should i use then ?
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    My link. Parameter 3.
  18. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    oh okay , got it
  19. Yosshi999
    Offline

    Yosshi999 New Member Plugin Developer

    Joined:
    Mar 13, 2014
    Posts:
    29
    Plugins:
    1
    Minecraft User:
    Yosshi999
    Thank you for replying.
    I'm making the ender chest so what i want to do is to catch the inventory packet and to rewrite the packet.
    Sorry,poor English
    Dutok likes this.

Share This Page

Advertisement