1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Execute a command when break block

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

  1. Kkora

    Kkora Baby Zombie

    Messages:
    189
    GitHub:
    shisui203
    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 Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    corytortoise likes this.
  3. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    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 Zombie Pigman

    Messages:
    598
    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 Baby Zombie

    Messages:
    189
    GitHub:
    shisui203
    ok tks.
     
  6. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    I would use getName() instead of getFolderName()
     
    Last edited: Nov 7, 2018
  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.