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

Break a specific block.

Comments in 'Plugin Development' started by BSHRMG, Jun 26, 2016.

  1. BSHRMG
    Offline

    BSHRMG New Member

    Joined:
    Mar 15, 2016
    Posts:
    21
    I would like know how to make a player just can break a specific block?
    Like in a minigame can break just TNT but no others block, thanks :)
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You would need to handle BlockBreakEvent, which is fired when a block is broken by a player. Then check if the block is a TNT block. If it is, allow the player to break it. If it is not, cancel the event.
    BSHRMG, applqpak and PocketKiller like this.
  3. Yeelze
    Offline

    Yeelze New Member

    Joined:
    Apr 2, 2016
    Posts:
    31
    Minecraft User:
    Yeelze
    I don't tested.
    PHP:
    public function onBreak(BlockBreakEvent $event){
        if(!
    $event->getBlock()->getID() == 46){
            
    $player $event->getPlayer();
            
    $player->sendMessage("You can't break this block!");
        }
    }
    BSHRMG likes this.
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    That is useless, it will just send that message, and he wants players to be only able to break TNT.
    applqpak likes this.
  5. Yeelze
    Offline

    Yeelze New Member

    Joined:
    Apr 2, 2016
    Posts:
    31
    Minecraft User:
    Yeelze
    Sorry I forget to put one thing
    PHP:
    $event->setCancelled();
    Done.
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    For code readability, use Block::TNT instead.
    applqpak likes this.
  7. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Why use !() and == if you can use !=?
    And why you store $event->getPlayer() if you only use it one time?
    applqpak likes this.

Share This Page

Advertisement