PEMapModder

PocketMine indirect killing (LegionPE implementation)

Jan 6th, 2015
28
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/LegionPE-Core/src/legionpe/games/kitpvp/PvpGame.php b/LegionPE-Core/src/legionpe/games/kitpvp/PvpGame.php
  2. index 8cc33f9..7b303f3 100644
  3. --- a/LegionPE-Core/src/legionpe/games/kitpvp/PvpGame.php
  4. +++ b/LegionPE-Core/src/legionpe/games/kitpvp/PvpGame.php
  5. @@ -7,7 +7,9 @@ use legionpe\games\Game;
  6.  use legionpe\LegionPE;
  7.  use legionpe\MysqlConnection;
  8.  use legionpe\session\Session;
  9. +use pocketmine\block\Block;
  10.  use pocketmine\command\Command;
  11. +use pocketmine\entity\Arrow;
  12.  use pocketmine\entity\Egg;
  13.  use pocketmine\entity\Snowball;
  14.  use pocketmine\event\entity\EntityDamageByChildEntityEvent;
  15. @@ -192,6 +194,14 @@ class PvpGame implements Game{
  16.         $origCancelled = $event->isCancelled();
  17.         $event->setCancelled(false);
  18.         if(!($event instanceof EntityDamageByEntityEvent)){
  19. +           if($event->getCause() === EntityDamageEvent::CAUSE_FALL){
  20. +               $fallCause = $victim->getLastDamageCause();
  21. +               if($fallCause instanceof EntityDamageByEntityEvent){
  22. +                   if(isset($fallCause->_legionpeEta_timestamp) and microtime(true) - $fallCause->_legionpeEta_timestamp < 1){
  23. +                       $event->_legionpeEta_fallCause = $fallCause;
  24. +                   }
  25. +               }
  26. +           }
  27.             return;
  28.         }
  29.         $victim = $event->getEntity();
  30. @@ -199,15 +209,15 @@ class PvpGame implements Game{
  31.         if(!($victim instanceof Player) or !($damager instanceof Player)){
  32.             return;
  33.         }
  34. -       $session = $this->main->getSessions()->getSession($damager);
  35. -       if(!$session->inSession($this)){
  36. +       $attackerSession = $this->main->getSessions()->getSession($damager);
  37. +       if(!$attackerSession->inSession($this)){
  38.             $event->setCancelled($origCancelled);
  39.             return;
  40.         }
  41. -       $hitterData = $this->playerData[$session->getUID()];
  42. +       $hitterData = $this->playerData[$attackerSession->getUID()];
  43.         if(Settings::kitpvp_isSafeArea($victim) or Settings::kitpvp_isSafeArea($damager)){
  44.             $event->setCancelled();
  45. -           $session->tell("You may not attack players at/from spawn!");
  46. +           $attackerSession->tell("You may not attack players at/from spawn!");
  47.         }
  48.         elseif($hitterData->isFriends($victimSession->getUID())){
  49.             $event->setCancelled();
  50. @@ -218,6 +228,8 @@ class PvpGame implements Game{
  51.                 return;
  52.             }
  53.             $hitterData->hitCooldown = microtime(true);
  54. +           $event->_legionpeEta_timestamp = microtime(true);
  55. +           $event->_legionpeEta_isLadder = ($victim->getLevel()->getBlockIdAt($victim->getFloorX(), $victim->getFloorY(), $victim->getFloorZ()) === Block::LADDER);
  56.             if($event instanceof EntityDamageByChildEntityEvent){
  57.                 $child = $event->getChild();
  58.                 if($child instanceof Snowball){
  59. @@ -238,12 +250,10 @@ class PvpGame implements Game{
  60.     public function e_onDeath(PlayerDeathEvent $event){
  61.         $victim = $event->getEntity();
  62.         if($victim instanceof Player){
  63. -           $this->getMain()->getLogger()->debug("PlayerDeathEvent passed to PvpGame::e_onDeath()");
  64.             $session = $this->main->getSessions()->getSession($victim);
  65.             if(!$session->inSession($this)){
  66.                 return;
  67.             }
  68. -           $this->getMain()->getLogger()->debug("{$victim->getName()} died");
  69.             $this->i_onDead($victim);
  70.             $cause = $victim->getLastDamageCause();
  71.             if($cause instanceof EntityDamageByEntityEvent){
  72. @@ -252,6 +262,18 @@ class PvpGame implements Game{
  73.                     $this->i_onKill($killer, $victim);
  74.                 }
  75.             }
  76. +           elseif($cause->getCause() === EntityDamageEvent::CAUSE_FALL and isset($cause->_legionpeEta_fallCause)){
  77. +               /** @var object $fallCause */
  78. +               $fallCause = $cause->_legionpeEta_fallCause;
  79. +               // $cause: fall event that led to death
  80. +               // $fallCause: damageByEntity event that led to fall
  81. +               /** @var bool $ladder */
  82. +               $ladder = $fallCause->_legionpeEta_isLadder;
  83. +               $shoot = $fallCause instanceof EntityDamageByChildEntityEvent and $fallCause->getChild() instanceof Arrow;
  84. +               $damager = $fallCause->getDamager();
  85. +               $this->i_onKill($damager, $victim, true, $ladder, $shoot);
  86. +               unset($cause->_legionpeEta_fallCause);
  87. +           }
  88.         }
  89.     }
  90.     public function onRespawn(PlayerRespawnEvent $event, Session $session){
  91. @@ -272,13 +294,25 @@ class PvpGame implements Game{
  92.         $data->streakCnt = 0;
  93.         $s->tell("You died! Your number of deaths: %d", $data->getDeaths());
  94.     }
  95. -   private function i_onKill(Player $killer, Player $victim){
  96. -       $this->getMain()->getLogger()->debug("{$killer->getName()} killed {$victim->getName()}");
  97. +   private function i_onKill(Player $killer, Player $victim, $isFall = false, $isLadder = false, $isArrow = false){
  98.         $killerSession = $this->main->getSessions()->getSession($killer);
  99.         $killerData = $this->playerData[$killerSession->getUID()];
  100.         $killerData->incrementKills();
  101. -       $killerSession->tell("You killed %s! Your number of kills: %d", $victim->getNameTag(), $killerData->getKills());
  102. -       $victim->sendMessage("You were killed by $killerSession!");
  103. +       if($isFall){
  104. +           $action = $isArrow ? "shot":"knocked";
  105. +           if($isLadder){
  106. +               $killerSession->tell("%s was $action off a ladder by you and fell to death! Your number of kills: %d", $victim->getNameTag(), $killerData->getKills());
  107. +               $victim->sendMessage("You were $action off a ladder by $killerSession and fell to death!");
  108. +           }
  109. +           else{
  110. +               $killerSession->tell("%s was doomed to fall by you! Your number of kills: %d", $victim->getNameTag(), $killerData->getKills());
  111. +               $victim->sendMessage("You were doomed to fall by $killerSession!");
  112. +           }
  113. +       }
  114. +       else{
  115. +           $killerSession->tell("You killed %s! Your number of kills: %d", $victim->getNameTag(), $killerData->getKills());
  116. +           $victim->sendMessage("You were killed by $killerSession!");
  117. +       }
  118.         $killerSession->setCoins($killerSession->getCoins() + 1);
  119.         $killerSession->tell("Your number of coins +1. You now have %d coins.", $killerSession->getCoins());
  120.         $killerData->streakCnt++;
  121. diff --git a/build/LegionPE_Eta.phar b/build/LegionPE_Eta.phar
  122. index b3cfd9a..4230219 100644
  123. Binary files a/build/LegionPE_Eta.phar and b/build/LegionPE_Eta.phar differ
RAW Paste Data