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

Solved How to run command when a player breaks X amt of blocks?

Comments in 'Plugin Development' started by Muqsit, Apr 8, 2016.

  1. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    I am thinking of making a skill-based plugin. I'd like to know how to send message to a player when a player breaks X amount of blocks.
    Supposedly, if a player breaks 64 blocks of wood, how would I run a command when the player breaks the wooden block 64th time?
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Manual instructions for this comes in free package called common sense :D

    1. Data saving
    2. Event capturing
    3. Parsing data

    PHP:
    /** @var array $breaks */
    private $breaks;

    // Event capturing
    public function e_block_break(BlockBreakEvent $event){
       if(
    $event->isCancelled()) return;
       
    $name strtolower(trim($event->getPlayer()->getName()));
       
    // Save
       
    $this->breaks[]);
       
    //  Parsing data, of course you can make more advanced one
       
    if($this->breaks[$name] >= 60){
          
    $event->getPlayer()->sendMessage("You breaked 60 blocks")); // This will be spammed once he breaks a block again.
       
    }
    }
    Skullex and Muqsit like this.
  3. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    TYSFM! :D:D:D
    Skullex likes this.

Share This Page

Advertisement