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

Breaking speed

Discussion in 'Development' started by Kyd, Mar 10, 2017.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    How would I check how fast is player breaking?
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Use DataPacketReceiveEvent to capture PlayerActionPacket of action PlayerActionPacket::ACTION_START_BREAK, store the time somewhere under player's name
    Then at BlockBreakEvent, compare the time stored of player with current time
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Ah, I tried and it is working:D But can anything improve?
    PHP:

    public function startBreak(DataPacketReceiveEvent $e){
        
    $p $e->getPlayer();
        
    $time $this->break[strtolower($p->getName())][0];
        
    $pk $e->getPacket();
        if(
    $pk instanceof PlayerActionPacket){
            if(
    $pk->action == 0){
                if(isset(
    $this->break[strtolower($p->getName())][0])){
                    
    $this->break[strtolower($p->getName())[1]];
                    
    $p->sendMessage("Debug");
            }else{
                    
    $this->break[strtolower($p->getName())][0];
                }
            }
        }
    }

    public function 
    onFastBreak(BlockBreakEvent $event)
    {
        
    $player $event->getPlayer();
        
    $block $event->getBlock();
        
    $time $this->break[strtolower($player->getName())][0];
        if (isset(
    $this->break[strtolower($player->getName())])) {
            
    $time $this->break[strtolower($player->getName())][0];
            
    $oldbreak $this->break[strtolower($player->getName())][1];
            if (
    $block == $oldbreak || $this->getServer()->getTick() - 10 $time) {
                    
    $player->kick("§eFastBreak not allowed"false);
                    
    $event->setCancelled();
                    return 
    false;
                }
                
    $this->break[strtolower($player->getName())] = array($this->getServer()->getTick(), $block);
                return 
    true;
            }
            
    $this->break[strtolower($player->getName())] = array($this->getServer()->getTick(), $block);
            return 
    true;
        }
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
  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.