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

could someone tell me how i would count the number of blocks the player broke? i tried this but onl

Discussion in 'Plugin Help' started by charada, Sep 24, 2020.

  1. charada

    charada Spider

    Messages:
    11
    GitHub:
    Ntem
    PHP:
    public function onBreak(BlockBreakEvent $event){
        
    $player $event->getPlayer();
        
    $block $event->getBlock();
       
    $pro 0;
          if (
    $block->getId() == 1) {
           
             
    $pro += 1;
            
           
                 
    $player->SendPopup("§aBreak: ".$pro);
           
              }
    }
     
  2. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    Just save an integer variable for each player and increase it by 1 whenever someone breaks a block
     
  3. charada

    charada Spider

    Messages:
    11
    GitHub:
    Ntem
    I did it over counted only once and then stopped
     
  4. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    Sorry I can't understand you
     
  5. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    I think this code help
    PHP:

    public function onBreak(BlockBreakEvent $event){
    $data = array();
        foreach(
    $this->getServer()->getOnlinePlayers() as $pf){
      
    $name =  $pf->getName();
       
    $data[$name] = 0;
       }
      
        
    $player $event->getPlayer();
        
    $block $event->getBlock();
        if(
    $block === 1){
         
    $data[$name] = $data[$name]+0;
    $player->SendPopup("§aBreak: ".$data[$name]);
        }else{
        
    $data[$p->getName()] = 0;
       }
        
    I recommend use config save
     
  6. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    No, don't abuse config for storing that kind of data, use a database instead if you want to save the amount even after restarting the server.
     
  7. charada

    charada Spider

    Messages:
    11
    GitHub:
    Ntem
    I created a file on the date where the quantity will be stored and it worked more now I don't know how I will get the number of blocks broken by the person to display in the popup

    PHP:
    public function onJoin(PlayerJoinEvent $ev){
        
        
    $player $ev->getPlayer();
        
    $inv $player->getInventory();
        
    $player->getInventory()->clearAll();
        
        
    /*Vai armazenar os dados de mineracao*/
        
        
    $config = new Config($this->getDataFolder() . "Miner.yml"Config::YAML);
        
        
    /*vai ver e o player existe na data ao logar se não vai criar um nome do player nela e vai da 0 de xp em mineracao*/
        
        
    if (!$config->exists($player->getName())) {
                
    $config->set($player->getName(), 0);
                
    $config->save();
            }

    public function 
    onBreak(BlockBreakEvent $event){
     
        
    $player $event->getPlayer();
        
    $block $event->getBlock();
        
    $name $player->getName();
        
        
    $config = new Config($this->getDataFolder() . "Miner.yml"Config::YAML);
        
        if(
    $block->getId() == 1){
          
          
    $config->set($name$config->get($name) + 1);
          
    $config->save();
          
          
    $player->SendPopup("§aProgresso: ".$name);
          
              if (
    $name >= 10) {
                
    $player->SendTitle("fpi");
              }
              
    }
    }
     
  8. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    $config->get($name)
     
  9. charada

    charada Spider

    Messages:
    11
    GitHub:
    Ntem
    Funcionou muito obrigado!!
     
    Diduhless likes this.
  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.