Solved Execute a command when break block

Discussion in 'Help' started by Kkora, Nov 4, 2018.

  1. Kkora

    Kkora Witch

    Messages:
    61
    GitHub:
    kkora2k3
    Hi. How to execute block when breaking an specific block in an specific world? (Eg: Wool in Hub)
    Can anybody give me an example code?
     
  2. HimbeersaftLP

    HimbeersaftLP Wither Skeleton

    Messages:
    1,422
    GitHub:
    HimbeersaftLP
    corytortoise likes this.
  3. Diduhless

    Diduhless Spider Jockey

    Messages:
    36
    GitHub:
    Diduhless
    PHP:
    /**
    * @param BlockBreakEvent $event
    */
    public function onBreak(BlockBreakEvent $event) {
        if(
    $event->getBlock()->getId() == Block::WOOL && $event->getPlayer()->getLevel() == "Hub") {
            
    $this->getServer()->dispatchCommand($event->getPlayer(), "command");
        }
    }
    Hope it helps you.
     
  4. GamakCZ

    GamakCZ Baby Zombie

    Messages:
    151
    GitHub:
    GamakCZ
    $event->getPlayer()->getLevel() returns \pocketmine\level\Level, not string

    PHP:
    /**
    * @param BlockBreakEvent $event
    */
    public function onBreak(BlockBreakEvent $event) {
        if(
    $event->getBlock()->getId() == Block::WOOL && $event->getPlayer()->getLevel()->getFolderName()  == "Hub") {
            
    $this->getServer()->dispatchCommand($event->getPlayer(), "command");
        }
    }
     
  5. Kkora

    Kkora Witch

    Messages:
    61
    GitHub:
    kkora2k3
    ok tks.
     
  6. Diduhless

    Diduhless Spider Jockey

    Messages:
    36
    GitHub:
    Diduhless
    I would use getName() instead of getFolderName()
     
    Last edited: Nov 7, 2018

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.