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

Damage not enabled, when autoclicker detector on! help!

Discussion in 'Development' started by Remarkabless, Nov 3, 2017.

  1. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    I have this autoclicker detector, the detector works fine there is nothing wrong with the actual detection but when the plugin is on the server pvp is disabled. The pvp doesnt enable at all I dont know what it is but 100% it is the plugin any help. Here is the only code for the plugin. please try and help me figure out why it doesnt enable pvp when on

    PHP:
    <?php
    declare(strict_types=1);

    namespace 
    anticheat;

    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;

    class 
    AntiCheatListener implements Listener{

        private 
    $plugin;

        
    //AutoClicker AntiCheat.
        
    public $hits = [];
        public 
    $timer = [];

        public function 
    __construct(AntiCheat $plugin){
            
    $plugin->getServer()->getPluginManager()->registerEvents($this$plugin);
            
    $this->plugin $plugin;
        }

        public function 
    handleDamage(EntityDamageEvent $event){
            if(
    $event instanceof EntityDamageByEntityEvent){
                
    $damager $event->getDamager();
                if(
    $damager instanceof Player){
                    
    $name $damager->getName();
                    if(isset(
    $this->hits[$name])){
                        if(!isset(
    $this->timer[$name]) or time() > $this->timer[$name]){
                            
    $this->timer[$name] = time() + $this->getConfig("autoclicker""timer");
                            
    $this->hits[$name] = 0;
                        }else{
                            
    $this->hits[$name] = $this->hits[$name] + 1;
                        }
                    }else{
                        
    $this->hits[$name] = 0;
                    }

                    if(
    $this->hits[$name] >= $this->getConfig("autoclicker""max-hits")){
                        unset(
    $this->hits[$name]);
                        
    $damager->kick((string)$this->getConfig("autoclicker""kick-message"), false);
                    }
                }


                if(!
    $damager->canInteract($event->getEntity(), $this->getConfig("max-reach"))){
                    
    $event->setCancelled(true);
                }
            }
        }

        
    //makes my life easier lol
        
    private function getConfig(string $key$key2 ""){
            return 
    $this->plugin->config->get($key)[$key2];
        }
    }
     
  2. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    Please help, I really need to get this plugin working thanks.
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    canInteract sometimes doesn't check correctly
     
  4. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    Anyway I can fix, caus pvp isn’t active at all with the plugin on the server
     
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    So when you remove $event->setCancelled() pvp is still disabled?
     
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Your canInteract() function is probably incorrect and causing the if statement to always return true, which in-turn cancels pvp
     
  7. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    consider trying to debug by adding echos on each condition and execution
     
    Vaxrp 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.