Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with getDamager() Crash

Comments in 'Plugin Development' started by CrazedMiner, May 25, 2015.

  1. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    When I run /kill in game my plugin causes the server to crash....

    Code:
    PHP:
    public function onDeath(PlayerDeathEvent $event) {
            if(
    $event->getEntity()->getLastDamageCause()->getDamager() instanceof Player) {
                
    //Create variables to make things easier
                
    $player $event->getEntity();
                
    $killer $event->getEntity()->getLastDamageCause()->getDamager();
                
    //Replace @player and @killer with the actual names
                
    $ipublicdm str_replace("@player"$player->getName(), $this->getConfig()->get("Public-Death-Message"));
                
    $publicdm str_replace("@killer"$killer->getPlayer()->getName(), $ipublicdm);
                
    $iprivatedm str_replace("@player"$player->getName(), $this->getConfig()->get("Private-Death-Message"));
                
    $privatedm str_replace("@killer"$killer->getPlayer()->getName(), $iprivatedm);
                
    //Set Death Messages
                
    $event->setDeathMessage($publicdm);
                
    $player->getPlayer()->sendMessage($privatedm);
            }
            else {
                
    $event->setDeathMessage("");
            }
            if(
    $this->getConfig()->get("No Drops on Death") === true) {
                
    $event->setDrops(array(Item::get(000)));
            }
        }
    Crash Dump
    Code:
    PocketMine-MP Crash Dump Sun May 24 19:17:40 CHOT 2015
    
    Error: Call to undefined method pocketmine\event\entity\EntityDamageEvent::getDamager()
    File: /Shield_Plugin_1/src/Shield_Plugin_1/Main
    Line: 102
    Type: E_ERROR
    
    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: Shield_Plugin_1 v1
    
    Code:
    [93]         }
    [94]         if($this->getConfig()->get("Teleport-to-Spawn-on-Quit") === true) {
    [95]             $spawn = $this->getServer()->getDefaultLevel()->getSpawnLocation();
    [96]             $player->teleport($spawn);
    [97]         }
    [98]     }
    [99]    
    [100]     public function onDeath(PlayerDeathEvent $event) {
    [101]         $player = $event->getEntity();
    [102]         $killer = $event->getEntity()->getLastDamageCause()->getDamager();
    [103]         if($killer instanceof Player) {
    [104]             $ipublicdm = str_replace("@player", $player->getName(), $this->getConfig()->get("Public-Death-Message"));
    [105]             $publicdm = str_replace("@killer", $killer->getPlayer()->getName(), $ipublicdm);
    [106]             $iprivatedm = str_replace("@player", $player->getName(), $this->getConfig()->get("Private-Death-Message"));
    [107]             $privatedm = str_replace("@killer", $killer->getPlayer()->getName(), $iprivatedm);
    [108]             $event->setDeathMessage($publicdm);
    [109]             $player->getPlayer()->sendMessage($privatedm);
    [110]         }
    [111]         if($this->getConfig()->get("No Drops on Death") === true) {
    [112]             $event->setDrops(array(Item::get(0, 0, 0)));
    
    Backtrace:
    #0 /src/pocketmine/Server(0): pocketmine\Server->crashDump()
    #1 /src/pocketmine/plugin/MethodEventExecutor(36): Shield_Plugin_1\Main->onDeath()
    #2 /src/pocketmine/plugin/RegisteredListener(96): pocketmine\plugin\MethodEventExecutor->execute()
    #3 /src/pocketmine/plugin/PluginManager(670): pocketmine\plugin\RegisteredListener->callEvent()
    #4 /src/pocketmine/Player(2634): pocketmine\plugin\PluginManager->callEvent()
    #5 /src/pocketmine/entity/Entity(393): pocketmine\Player->kill()
    #6 /src/pocketmine/Player(2652): pocketmine\entity\Entity->setHealth()
    #7 /src/pocketmine/command/defaults/KillCommand(54): pocketmine\Player->setHealth()
    #8 /src/pocketmine/command/SimpleCommandMap(183): pocketmine\command\defaults\KillCommand->execute()
    #9 /src/pocketmine/Server(1826): pocketmine\command\SimpleCommandMap->dispatch()
    #10 /src/pocketmine/Player(2199): pocketmine\Server->dispatchCommand()
    #11 /src/pocketmine/network/RakLibInterface(192): pocketmine\Player->handleDataPacket()
    #12 /src/raklib/server/ServerHandler(92): pocketmine\network\RakLibInterface->handleEncapsulated()
    #13 /src/pocketmine/network/RakLibInterface(137): raklib\server\ServerHandler->handlePacket()
    #14 /src/pocketmine/Server(2215): pocketmine\network\RakLibInterface->process()
    #15 /src/pocketmine/Server(2109): pocketmine\Server->tick()
    #16 /src/pocketmine/Server(1985): pocketmine\Server->tickProcessor()
    #17 /src/pocketmine/Server(1702): pocketmine\Server->start()
    #18 /src/pocketmine/PocketMine(442): pocketmine\Server->__construct()
    #19 (1): ()
    #20 (0): {main}()
    
    PocketMine-MP version: 1.4.1dev #974 [Protocol 20; API 1.11.0]
    Git commit: 0000000000000000000000000000000000000000
    uname -a: Windows NT JACK 6.1 build 7601 (Windows 7 Enterprise Edition Service Pack 1) i586
    PHP Version: 5.6.4
    Zend version: 2.6.0
    OS : WINNT, win
    
    Loaded plugins:
    DevTools 1.10.0 by PocketMine Team for API(s) 1.3.1
    Shield_Plugin_1 1 by CrazedMiner for API(s) 1.8.0
    
    If anyone could help figure out how to fix this or give me a way around the crash that would be great! Thanks :)
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $cause $event->getEntity()->getLastDamageCause();
    if(
    $cause instanceof EntityDamageByEntityEvent){
    $killer $cause->getDamager();
    if(
    $killer instanceof Player){
    // Do something
    }
    }
    CrazedMiner, Lambo and PEMapModder like this.

Share This Page

Advertisement