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

Listener and EventExecutor????

Discussion in 'Facepalm' started by XdmingXD, Mar 11, 2017.

Thread Status:
Not open for further replies.
  1. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Hello I made a plugin unsuccessfully
    However,I don't know what's going with it.
    Its keep saying "
    [Server thread/CRITICAL]: pocketmine\plugin\PluginException: "pocketmine\event\entity\EntityDamageByEntityEvent does not have a handler list" (EXCEPTION) in "/src/pocketmine/plugin/PluginManager" at line 790"
    I can't understand why would EntityDamgedByEntityEvent need EventExecutor
    Is there any update?
    Here is my code...
    PHP:
    use pocketmine\plugin\PluginBase;
    use 
    pocketmine\plugin\EventExecutor;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\utils\TextFormat as C;

    class 
    vf extends PluginBase implements Listener{
     
        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info(C::GOLD "Loaded!");
        }

    public function 
    checkCombat(EntityDamageByEntityEvent $event) {
            if(
    $event instanceof EntityDamageByEntityEvent) {
                
    $player $event->getEntity();
                
    $damager $event->getDamager();
                if(
    $player instanceof Player && $damager instanceof Player) {
                    
    $player->sendMessage(C::YELLOW "(!)You are in combat!");
                    
    $damager->sendMessage(C::YELLOW "(!)You are in combat!");
                    unset(
    $this->check);
                }
            }
        }
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    EntityDamageByEntityEvent doesn't have a handler list, like it says. Use EntityDamageEvent, then check if its instanceof EntityDamageByEntityEvent, which you already do.
     
    XdmingXD likes this.
  3. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    So in the EntityDamageByEntityEvent you are checking if its an instance of an EntityDamageByEntityEvent?

    OK, heres the corrected code
    PHP:
    use pocketmine\plugin\PluginBase;
    use 
    pocketmine\plugin\EventExecutor;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\utils\TextFormat as C;

    class 
    vf extends PluginBase implements Listener{
     
        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info(C::GOLD "Loaded!");
        }

    public function 
    checkCombat(EntityDamageEvent $event) {
            if(
    $event instanceof EntityDamageByEntityEvent) {
                
    $player $event->getEntity();
                
    $damager $event->getDamager();
                if(
    $player instanceof Player && $damager instanceof Player) {
                    
    $player->sendMessage(C::YELLOW "(!)You are in combat!");
                    
    $damager->sendMessage(C::YELLOW "(!)You are in combat!");
                    unset(
    $this->check);
                }
            }
        }
    You must use EntityDamageEvent and check if its an instance of EntityDamageByEntityEvent.
     
    XdmingXD likes this.
  4. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    oic thanks
     
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Do we need a warning specialized for duplicated threads? Or do we need to make this forum like StackOverflow? :facepalm:
     
Thread Status:
Not open for further replies.
  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.