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

Why onInventoryOpen doesn't work.

Comments in 'Plugin Development' started by RunFMe, May 2, 2015.

  1. RunFMe
    Offline

    RunFMe New Member

    Joined:
    Apr 30, 2015
    Posts:
    10
    Minecraft User:
    RunFMe
    PHP:
    <?php
    namespace runfme/a;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\event\inventory\InventoryOpenEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Server;
    class 
    Main extends PluginBase implements Listener{
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
            if (!
    is_dir($this->getDataFolder())) mkdir($this->getDataFolder());
         
        }
        public  function 
    onInventotoryOpen(InventoryOpenEvent $event){
            
    $event->setCancelled();
        }
    }
    ?>
    Why inventory opens?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Syntax error at line 2.

    That event only gets fired for chest inventory opening.
  3. shoghicp
    Offline

    shoghicp Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    433
    Plugins:
    14
    Minecraft User:
    shoghicp
    Players don't send a notification when opening their inventory, if you want to do so.
    PEMapModder likes this.
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    <?php
    namespace runfme\a// Syntax Error, change / to \
    use pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\event\inventory\InventoryOpenEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Server;
    class 
    Main extends PluginBase implements Listener{
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
            if (!
    is_dir($this->getDataFolder())) mkdir($this->getDataFolder()); //You don't need a DataFolder?
        
        
    }
        public  function 
    onInventoryOpen(InventoryOpenEvent $event){ // InventoryOpenEvent is only for ChestInventorys, like PEMapModder and shoghicp said
            
    $event->setCancelled();
        }
    }
    ?>
    RunFMe likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    ?> is not required. If you put that in my phar converter in the future, it will be auto deleted.
  6. RunFMe
    Offline

    RunFMe New Member

    Joined:
    Apr 30, 2015
    Posts:
    10
    Minecraft User:
    RunFMe
    Thx everybody for help.
    PEMapModder likes this.

Share This Page

Advertisement