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

Help!

Discussion in 'Development' started by A354-PH, Feb 15, 2019.

  1. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    How to fix?
    Code:
    [09:46:55] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\event\entity\EntityDamageByEntityEvent::getDamage()" (EXCEPTION) in "plugins/TheBridge v1.2.0.phar/src/bridge/utils/arena/Arena" at line 232
    
    CODE:
    PHP:
        public function onDamage(EntityDamageEvent $e){
            
    $ent $e->getEntity();
            if(
    $ent instanceof Player){
                
    $name strtolower($ent->getName());
                
    $arena $this->getPlugin()->getPlayerArena($ent);
                if(
    is_null($arena)){
                    return 
    true;
                }
                if(
    $arena->stat or $arena->stat 3){
                    
    $e->setCancelled();
                    if(
    $e->getCause() == 11){
                        if(
    $arena->stat 3){
                            
    $ent->getInventory()->clearAll();
                            
    $arena->respawnPlayer($entfalse);
                            return 
    true;
                        }
                        
    $level $ent->getLevel();
                        
    $ent->teleport($level->getSafeSpawn());
                        return 
    true;
                    }
                }
                if(
    $e->getCause() == 4){
                    
    $e->setCancelled();
                    return 
    true;
                }
                if(
    $e->getCause() == 10 or $e->getCause() == 9){
                    
    $e->setCancelled();
                    return 
    true;
                }
                if(
    $e->getCause() == 11){
                    
    $e->setCancelled();
                    
    $ent->getInventory()->clearAll();
                    
    $arena->respawnPlayer($ent);
                    return 
    true;
                }
                
    $cause $ent->getLastDamageCause();
                
    $damage $e->getFinalDamage();
                if(
    $e instanceof EntityDamageByEntityEvent){
                    
    $p $e->getDamager();
                    if(
    $p instanceof Player){
                        if(
    $arena->isTeamMode() && $arena->isTeam($p$ent)){
                            
    $e->setCancelled();
                            return 
    true;
                        }
                    }
                }
                if((
    $ent->getHealth() - round($damage)) <= 1){
                    
    $e->setCancelled();
                    
    $ent->getInventory()->clearAll();
                    
    $arena->respawnPlayer($ent);
                    if(
    $e instanceof EntityDamageByEntityEvent){
                        
    $p $e->getDamager();
                        if(
    $p instanceof Player){
                            
    $arena->broadcast("§c§l» §r§7 " $p->getNameTag() . " §7killed " $ent->getNameTag(), 3);
                            if(
    $arena->hasHab($p"matador")){
                                
    $eff Effect::getEffect(5);
                                
    $eff->setDuration(20*20);
                                
    $eff->setAmplifier(3);
                                
                                
    $p->addEffect($eff);
                            }
                            return 
    true;
                        }
                    }
                    
    $arena->broadcast("§c§l» §r§7 " $ent->getNameTag() . " §7died alone"3);
                    return 
    true;
                }
                switch(
    $e->getCause()){
                    case 
    1:
                    case 
    2:
                    case 
    4:
                    case 
    11:
                    if(
    $cause instanceof EntityDamageByEntityEvent){
                        
    $ev = new EntityDamageByEntityEvent($cause->getDamager(), $ent1$e->getDamage()); //line 232
                        
    $ent->setLastDamageCause($ev);
                    }
                    break;
                }
            }
        }
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    change getDamage() to getFinalDamage()
     
  3. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    Lemme try it
     
  4. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    Now it shows me this
    Code:
    [12:26:55] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to pocketmine\event\entity\EntityDamageByEntityEvent::__construct() must be an instance of pocketmine\entity\Entity, null given, called in phar:///home/minecraft/plugins/TheBridge v1.3.0.phar/src/bridge/utils/arena/Arena.php on line 232" (EXCEPTION) in "src/pocketmine/event/entity/EntityDamageByEntityEvent" at line 47
     
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    On line 232 change $e->getDamage() to $e->getBaseDamage()
     
    wolfdale and A354-PH like this.
  6. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    I'll try
     
  7. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    because $cause->getDamager() returns null
     
  8. UnknownOre

    UnknownOre Silverfish

    Messages:
    21
    GitHub:
    UnknownOre
    do you get this error when you hit player?
     
  9. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    PHP:
                switch($e->getCause()){
                    case 
    1:
                    case 
    2:
                    case 
    4:
                    case 
    11:
                    if(
    $cause instanceof EntityDamageByEntityEvent){
                        
    $ev = new EntityDamageByEntityEvent($cause->getDamager(), $ent1$e->getBaseDamage());
                        
    $ent->setLastDamageCause($ev);
                    }
                    return 
    true;
                    break;
                }
            }
        }
     
  10. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Did u fux it yet
     
  11. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You need to solve it by having a null check for $cause->getDamager(). It can return null in cases where a player shoots a bow, quits the server, and the arrow then hits an entity. EntityDamageEventg::getEntity() on the other hand will most likely never return null.

    https://github.com/pmmp/PocketMine-MP/pull/418
     
    Last edited: Feb 16, 2019
    A354-PH and wolfdale like this.
  12. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    Not yet
     
  13. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    Yes
     
  14. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    PHP:
                switch($e->getCause()){
                    case 
    1:
                    case 
    2:
                    case 
    4:
                    case 
    11:
                    if(
    $cause instanceof EntityDamageByEntityEvent){
                        if(
    $cause->getDamager() !== null){
                            
    $ev = new EntityDamageByEntityEvent($cause->getDamager(), $ent1$e->getBaseDamage());
                            
    $ent->setLastDamageCause($ev);
                        }
                    }
                    return 
    true;
                    break;
                }
            }
        } 
     
    A354-PH 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.