getCause() публичный Метод

public getCause ( ) : integer
Результат integer
 /**
  * @param EntityDamageEvent $event
  * @priority HIGH
  * @ignoreCancelled true
  */
 public function onDamage(EntityDamageEvent $event)
 {
     $damaged = $event->getEntity();
     if ($damaged instanceof Player) {
         $area = $this->main->getDatabase()->searchAreaByPosition($damaged);
         if ($area instanceof Area) {
             $cause = $event->getCause();
             if ($this->areaHasFlag($damaged, Area::FLAG_DAMAGED, false, false)) {
                 $event->setCancelled();
             } elseif ($cause === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION) {
                 if ($this->areaHasFlag($damaged, Area::FLAG_DAMAGED_BY_EXPLOSION, false)) {
                     $event->setCancelled();
                 }
             } elseif ($cause === EntityDamageEvent::CAUSE_VOID) {
                 if ($this->areaHasFlag($damaged, Area::FLAG_DAMAGED_BY_VOID, false)) {
                     $event->setCancelled();
                 }
             } elseif ($cause === EntityDamageEvent::CAUSE_SUFFOCATION) {
                 if ($this->areaHasFlag($damaged, Area::FLAG_DAMAGED_BY_SUFFOCATE, false)) {
                     $event->setCancelled();
                 }
             } elseif ($cause === EntityDamageEvent::CAUSE_DROWNING) {
                 if ($this->areaHasFlag($damaged, Area::FLAG_DAMAGED_BY_DROWN, false)) {
                     $event->setCancelled();
                 }
             } elseif ($cause === EntityDamageEvent::CAUSE_FALL) {
                 if ($this->areaHasFlag($damaged, Area::FLAG_DAMAGED_BY_FALL, false)) {
                     $event->setCancelled();
                 }
             } elseif ($cause === EntityDamageEvent::CAUSE_FIRE or $cause === EntityDamageEvent::CAUSE_FIRE_TICK or $cause === EntityDamageEvent::CAUSE_LAVA) {
                 if ($this->areaHasFlag($damaged, Area::FLAG_DAMAGED_BY_FIRE, false)) {
                     $event->setCancelled();
                 }
             } elseif ($event instanceof EntityDamageByEntityEvent) {
                 $damager = $event->getDamager();
                 if ($damager instanceof Player) {
                     if ($this->areaHasFlag($damaged, Area::FLAG_DAMAGED_BY_PLAYER, false)) {
                         $event->setCancelled();
                     }
                 } elseif ($this->areaHasFlag($damaged, Area::FLAG_DAMAGED_BY_ENTITY, false)) {
                     $event->setCancelled();
                 }
             }
         }
     }
     if (!$event->setCancelled() and $event instanceof EntityDamageByEntityEvent) {
         $damager = $event->getDamager();
         if ($damager instanceof Player) {
             if ($damaged instanceof Player) {
                 if (!$this->areaHasFlag($damager, Area::FLAG_DAMAGE_PLAYER, true)) {
                     $event->setCancelled();
                 }
             } elseif (!$this->areaHasFlag($damager, Area::FLAG_DAMAGE_MOB, true)) {
                 $event->setCancelled();
             }
         }
     }
 }
Пример #2
2
 public function onDamage(EntityDamageEvent $event)
 {
     $cause = $event->getCause();
     if ($cause === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION || $cause === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION) {
         $event->setCancelled();
     }
 }
Пример #3
0
 public function fallenDamagePrevent(EntityDamageEvent $event)
 {
     if ($event->getCause() == EntityDamageEvent::CAUSE_FALL) {
         if (!$event->getEntity() instanceof Player) {
             return;
         }
         if ($event->getEntity()->y > 0) {
             $event->setDamage(0);
             $event->setCancelled();
         }
     }
 }
Пример #4
0
 public function onDamage(EntityDamageEvent $event)
 {
     $player = $event->getEntity();
     $entity = $event->getEntity();
     if ($player instanceof Player && $event->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION) {
         switch (mt_rand(1, 2)) {
             case 1:
                 $event->setDamage(10);
                 break;
             case 2:
                 $event->setDamage(8);
                 break;
         }
     }
 }
Пример #5
0
 public function onFall(EntityDamageEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     $cause = $ev->getCause();
     if ($cause !== EntityDamageEvent::CAUSE_FALL) {
         return;
     }
     $et = $ev->getEntity();
     $id = $et->getLevel()->getBlockIdAt($et->getX(), $et->getY() - 1, $et->getZ());
     if (isset($this->blocks[$id])) {
         // Soft landing!
         $ev->setCancelled();
     }
 }
Пример #6
0
 public function onDamageByPlayer(EntityDamageEvent $ev)
 {
     $cause = $ev->getCause();
     switch ($cause) {
         case EntityDamageEvent::CAUSE_ENTITY_ATTACK:
             $atkr = $ev->getDamager();
             $player = $ev->getEntity();
             if ($atkr instanceof Player and $player instanceof Player) {
                 if ($this->isFriend($player, $atkr->getName())) {
                     $ev->setCancelled();
                     $atkr->sendMessage("Cannot attack friend :(");
                 }
             }
             break;
     }
 }
Пример #7
0
 public function onDamageByPlayer(EntityDamageEvent $ev)
 {
     $cause = $ev->getCause();
     switch ($cause) {
         case EntityDamageEvent::CAUSE_ENTITY_ATTACK:
             $atkr = $ev->getDamager();
             $player = $ev->getEntity();
             $pl = $ev->getPlayer();
             if ($atkr instanceof Player and $player instanceof Player) {
                 if ($this->inParty($player, $atkr->getName())) {
                     $ev->setCancelled();
                     $atkr->sendMessage(TextFormat::RED . "{$pl} is in your party!");
                 }
             }
     }
     break;
 }
Пример #8
0
 public function onEntityDamage(EntityDamageEvent $event)
 {
     $p = $event->getEntity();
     if ($event->isCancelled() || !$p instanceof Player || $event->getCause() > 11) {
         return;
     }
     $w = strtolower($p->getLevel()->getFolderName());
     if ($event instanceof EntityDamageByEntityEvent) {
         if (!in_array($w, $this->wm["PVP"])) {
             $dmg = $event->getDamager();
             if ($dmg instanceof Player) {
                 if (!$dmg->hasPermission("mineblock.worldmanager.worldpvp.pvp")) {
                     $event->setCancelled();
                     $dmg->sendMessage("[PVP Manager] PVP 권한이 없습니다.");
                 }
             }
         }
     }
 }
Пример #9
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->dead === true) {
         return;
     }
     if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE and $source->getCause() !== EntityDamageEvent::CAUSE_VOID) {
         $source->setCancelled();
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     } elseif ($this->getLastDamageCause() === $source and $this->spawned) {
         $pk = new EntityEventPacket();
         $pk->eid = $this->getId();
         $pk->event = 2;
         $this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     }
 }
Пример #10
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if (!$this->isAlive()) {
         return;
     }
     if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE and $source->getCause() !== EntityDamageEvent::CAUSE_VOID) {
         $source->setCancelled();
     } elseif ($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL) {
         $source->setCancelled();
     } elseif ($source->getCause() === EntityDamageEvent::CAUSE_FALL) {
         if ($this->getLevel()->getBlock($this->getPosition()->add(0, -1, 0))->getId() == Item::SLIME_BLOCK) {
             if (!$this->isSneaking()) {
                 $source->setCancelled();
                 $this->resetFallDistance();
             }
             if (!$this->isSneaking() && !$this->getPosition()->distanceSquared($this->getPosition()->subtract(0, 1)) > 0.1) {
                 $this->setMotion($this->getMotion()->add(0, $this->getMotion()->getY() * 2 * 0.88, 0));
             }
             if ($this->motionY < 0) {
                 $this->motionY = -$this->motionY;
                 if (!$this instanceof Living) {
                     $this->motionY *= 0.8;
                 }
             }
         }
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return false;
     } elseif ($this->getLastDamageCause() === $source and $this->spawned) {
         $pk = new EntityEventPacket();
         $pk->eid = 0;
         $pk->event = EntityEventPacket::HURT_ANIMATION;
         $this->dataPacket($pk);
         if ($this->isSurvival()) {
             $this->exhaust(0.3, PlayerExhaustEvent::CAUSE_DAMAGE);
         }
     }
     return true;
 }
Пример #11
0
 public function onDamage(EntityDamageEvent $event)
 {
     if ($event->getEntity() instanceof Player) {
         if ($this->disableDamage) {
             $event->setCancelled();
         } elseif ($this->disableCollisionDamage && $event->getCause() instanceof EntityDamageByBlockEvent) {
             if ($this->disableCollisionDamage) {
                 $event->setCancelled();
             }
         }
     }
     return;
 }
Пример #12
0
 /**
  * @param float             $damage
  * @param EntityDamageEvent $source
  *
  * @return bool
  */
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->hasEffect(Effect::FIRE_RESISTANCE) and ($source->getCause() === EntityDamageEvent::CAUSE_FIRE or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or $source->getCause() === EntityDamageEvent::CAUSE_LAVA)) {
         $source->setCancelled();
     }
     $this->server->getPluginManager()->callEvent($source);
     if ($source->isCancelled()) {
         return false;
     }
     $this->setLastDamageCause($source);
     if ($this instanceof Human) {
         $damage = round($source->getFinalDamage());
         if ($this->getAbsorption() > 0) {
             $absorption = $this->getAbsorption() - $damage;
             $this->setAbsorption($absorption <= 0 ? 0 : $absorption);
             $this->setHealth($this->getHealth() + $absorption);
         } else {
             $this->setHealth($this->getHealth() - $damage);
         }
     } else {
         $this->setHealth($this->getHealth() - round($source->getFinalDamage()));
     }
     return true;
 }
Пример #13
0
 public function h_onDamage(EntityDamageEvent $event)
 {
     if ($event->getCause() === EntityDamageEvent::CAUSE_VOID) {
         $event->setCancelled();
         $this->player->teleport($this->player->getLevel()->getSpawnLocation());
     }
     if (!$this->isLoggedIn()) {
         $event->setCancelled();
         $this->disableTpListener = true;
         $this->teleport($this->spawningPosition);
         $this->disableTpListener = false;
     }
     /*if($event instanceof EntityDamageByEntityEvent){
     			$target = $this->getPlayer();
     			$hitter = $event->getDamager();
     			if(!($hitter instanceof Player)){
     				return;
     			}
     			if((pow($hitter->x - $target->x, 2) + pow($hitter->z - $target->z, 2)) <= 2.25){
     				return;
     			}
     			$dir = $hitter
     //				->add(0, $hitter->getEyeHeight(), 0)
     				->subtract(
     					$target
     //						->add(0, $target->height / 2, 0)
     				);
     			$yaw = rad2deg(atan2($dir->z, $dir->x)) + 90;
     //			if(($len = $dir->length()) === 0){
     //				$len = 1;
     //			}
     //			$pitch = rad2deg(asin($dir->y / $len));
     			if((180 - abs(abs($hitter->yaw - $yaw) - 180)) > 90
     //				or (180 - abs(abs($hitter->pitch - $pitch) - 180)) > 60
     			){
     				$event->setCancelled();
     				$hitter->sendMessage("You can't attack players behind you!");
     			}
     		}*/
 }
Пример #14
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($source->getCause() === EntityDamageEvent::CAUSE_VOID) {
         parent::attack($damage, $source);
     }
 }
Пример #15
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($source->getCause() === EntityDamageEvent::CAUSE_VOID or ($source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or $source->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION or $source->getCause() === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION) and $this->item->getId() !== ItemItem::NETHER_STAR) {
         parent::attack($damage, $source);
     }
 }
Пример #16
0
 /**
  * @param float             $damage
  * @param EntityDamageEvent $source
  *
  */
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->hasEffect(Effect::FIRE_RESISTANCE) and ($source->getCause() === EntityDamageEvent::CAUSE_FIRE or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or $source->getCause() === EntityDamageEvent::CAUSE_LAVA)) {
         $source->setCancelled();
     }
     if ($source instanceof EntityDamageByEntityEvent && $source->getCause() === EntityDamageEvent::CAUSE_PROJECTILE) {
         $e = $source->getDamager();
         if ($source instanceof EntityDamageByChildEntityEvent) {
             $e = $source->getChild();
         }
         if ($e instanceof ThrownExpBottle || $e instanceof ThrownPotion) {
             $source->setCancelled();
         }
     }
     $this->server->getPluginManager()->callEvent($source);
     if ($source->isCancelled()) {
         return;
     }
     $this->setLastDamageCause($source);
     $this->getHealth() - $source->getFinalDamage() <= 0 ? $this->setHealth(0) : $this->setHealth($this->getHealth() - $source->getFinalDamage());
 }
Пример #17
0
 public function onHit(EntityDamageEvent $e)
 {
     if ($e->getEntity() instanceof Player) {
         if ($e->getCause() !== 7 && $this->getPlayerMode($e->getEntity()) !== false) {
             $e->setCancelled(true);
         }
         if ($e instanceof EntityDamageByEntityEvent) {
             $p1 = $e->getDamager();
             $p2 = $e->getEntity();
             if ($this->getPlayerMode($p2) !== false) {
                 $e->setCancelled(true);
             }
         }
     }
 }
Пример #18
0
 public function onEntityDamage(EntityDamageEvent $event)
 {
     $player = $event->getEntity();
     if (!$player instanceof Player) {
         return;
     }
     if ($event->getCause() !== EntityDamageEvent::CAUSE_FALL) {
         return;
     }
     if (isset($this->flyingPlayers[$player->getName()])) {
         $lastGround = $this->flyingPlayers[$player->getName()]["lastground"];
         if ($lastGround === -1 || time() - $lastGround <= 3) {
             $event->setCancelled();
         }
         unset($this->flyingPlayers[$player->getName()]);
     }
 }
Пример #19
0
 public function fallenDamagePrevent(EntityDamageEvent $event)
 {
     if ($event->getCause() == EntityDamageEvent::CAUSE_FALL) {
         if (!$event->getEntity() instanceof Player) {
             return;
         }
         if (isset($this->fallen[$event->getEntity()->getName()])) {
             $event->setDamage(0);
             $this->fallen[$event->getEntity()->getName()]--;
             if ($this->fallen[$event->getEntity()->getName()] == 0) {
                 unset($this->fallen[$event->getEntity()->getName()]);
             }
         }
     }
 }
Пример #20
0
 public function calculateArmorModifiers(EntityDamageEvent $source)
 {
     $protection = 0;
     $protectionEnch = null;
     $modifier = 0;
     if ($source instanceof EntityDamageByEntityEvent || $source instanceof EntityDamageByChildEntityEvent) {
         $damager = $source->getDamager();
     } else {
         $damager = null;
     }
     switch ($source->getCause()) {
         case EntityDamageEvent::CAUSE_FIRE:
         case EntityDamageEvent::CAUSE_FIRE_TICK:
         case EntityDamageEvent::CAUSE_LAVA:
             $protectionEnch = Enchantment::TYPE_ARMOR_FIRE_PROTECTION;
             $modifier = 1.25;
             break;
         case EntityDamageEvent::CAUSE_FALL:
             $protectionEnch = Enchantment::TYPE_ARMOR_FALL_PROTECTION;
             $modifier = 2.5;
             break;
         case EntityDamageEvent::CAUSE_PROJECTILE:
             $protectionEnch = Enchantment::TYPE_ARMOR_PROJECTILE_PROTECTION;
             $modifier = 1.5;
             break;
         case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION:
         case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
             $protectionEnch = Enchantment::TYPE_ARMOR_EXPLOSION_PROTECTION;
             $modifier = 1.5;
             break;
     }
     foreach ($this->getArmorContents() as $item) {
         $protection += $item->getProtection();
         if ($protectionEnch != null && ($ench = $item->getEnchantment($protectionEnch)) != null) {
             $protection += floor((6 + $ench->getLevel() ^ 2) * $modifier / 3);
         }
     }
     return $protection;
 }
Пример #21
0
 public function onHurtf(EntityDamageEvent $event)
 {
     //$cause = $event->getCause();
     //arrow check for the catchy phrase thing :PPP
     $causet = $event->getCause();
     if ($causet === 2) {
         $arrowed = true;
     } else {
         $arrowed = false;
     }
     $pr = $event->getEntity();
     $cause = $pr->getLastDamageCause();
     if ($cause instanceof EntityDamageByEntityEvent) {
         $dam = $event->getDamager()->getName();
         $ent = $event->getEntity()->getPlayer()->getName();
         if ($arrowed) {
             if (!is_file($this->getDataFolder() . $dam . ".json")) {
                 return true;
             }
             $file = file_get_contents($this->getDataFolder() . $dam . ".json");
             $decode = json_decode($file, true);
             if (isset($decode["annihilator"]) and $decode["annihilator"] === "yes") {
                 $nt = $event->getEntity()->getPlayer();
                 $event->setDamage(0);
                 $spawn = $nt->getSpawn();
                 $nt->teleport($spawn, $nt->getYaw(), $nt->getPitch());
                 $this->getServer()->getPlayer($ent)->sendMessage("One-shot, one kill! You didn't even see that coming!");
                 return true;
             } else {
                 return true;
             }
         }
         $this->killer[$dam] = strval($ent);
         if ($dam instanceof Player) {
             $ms = $dam;
             if (!\is_file($this->getDataFolder() . $ms . ".json")) {
                 return true;
             }
             $hhd = file_get_contents($this->getDataFolder() . $ms . ".json");
             $dec = json_decode($hhd, true);
             if (isset($dec["annihilator"])) {
                 if ($dec["annihilator"] === "yes") {
                     $event->setDamage(PHP_INT_MAX);
                     return true;
                 }
             }
         }
         if ($dam instanceof Arrow) {
             $this->getLogger()->info("yeah!");
         }
     }
 }
Пример #22
0
 public function damageHandler(EntityDamageEvent $event)
 {
     $entity = $event->getEntity();
     $cause = $event->getCause();
     // $message = "Unknown";
     if ($entity instanceof Player && $this->isPlaying($entity)) {
         if ($cause == EntityDamageEvent::CAUSE_ENTITY_ATTACK) {
             // $this->getServer()->broadcastMessage("cause entity attack");
             if ($event instanceof EntityDamageByEntityEvent) {
                 $killer = $event->getDamager();
                 if ($this->isPlaying($killer)) {
                     if ($killer instanceof Player) {
                         // $message = $killer->getName();
                         // if($event->getDamage() >= $entity->getHealth()){
                         $event->setCancelled(true);
                         // $this->killHandler($entity, $killer);
                         // }
                     }
                 }
                 // $this->getServer()->broadcastMessage($entity->getName() . " was hit by " . $message);
             }
             // else
             // $this->getLogger()->info("not playing, so not handling");
         } elseif ($cause == EntityDamageEvent::CAUSE_VOID) {
             // $this->getServer()->broadcastMessage("cause projectile");
             // if($event instanceof EntityDamageByChildEntityEvent){
             // $killer = $event->getDamager();
             /*
              * if($killer instanceof Arrow){
              * $this->getServer()->broadcastMessage("Is arrow");
              * $killer = $killer->shootingEntity;
              * }
              */
             // if($killer instanceof Player && $this->isPlaying($killer)){
             // $this->getServer()->broadcastMessage($entity->getName() . " was hit by arrow shot by " . $killer->getName());
             $event->setCancelled(true);
             $this->killHandler($entity);
             // }
         }
         // else
         // $this->getLogger()->info("not playing or not player");
     }
     // elseif($this->isPlaying($entity) && $event->getDamage() >= $entity->getHealth() && $entity->getGamemode() === 0){
     // $this->getServer()->broadcastMessage("cause other");
     // $event->setCancelled(true);
     // $this->killHandler($entity);
     // }
     // else{
     // $this->getServer()->broadcastMessage("no critical cause or not gm0, maybe spectator in block?");
     // }
     // }
 }
Пример #23
0
 public function cancelFallDamage(EntityDamageEvent $e)
 {
     if ($this->isInArena($e->getPlayer())) {
         $causeID = $e->getCause();
         if ($causeID === 4) {
             $e->setCancelled();
         }
     }
 }
Пример #24
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($source->isCancelled()) {
         return;
     }
     if ($source->getCause() == EntityDamageEvent::CAUSE_FALL) {
         $source->setCancelled();
         return;
     }
     parent::attack($damage, $source);
 }
Пример #25
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if (!$this->isAlive()) {
         return;
     }
     if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE and $source->getCause() !== EntityDamageEvent::CAUSE_VOID) {
         $source->setCancelled();
     } elseif ($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL) {
         $source->setCancelled();
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     } elseif ($this->getLastDamageCause() === $source and $this->spawned) {
         $pk = new EntityEventPacket();
         $pk->eid = 0;
         $pk->event = EntityEventPacket::HURT_ANIMATION;
         $this->dataPacket($pk);
     }
 }
Пример #26
0
 public function onEntityDamage(EntityDamageEvent $event)
 {
     $e = $event->getEntity();
     if ($event->getCause() == 3) {
         for ($x = -1; $x < 2; $x++) {
             for ($z = -1; $z < 2; $z++) {
                 if ($e->getLevel()->getBlockIdAt(round($e->getX()) + $x, round($e->getY() + 1), round($e->getZ() + $z)) == 127) {
                     $event->setCancelled();
                     break;
                 }
             }
         }
     }
 }
Пример #27
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($source->getCause() === EntityDamageEvent::CAUSE_VOID or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or $source->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION or $source->getCause() === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION) {
         parent::attack($damage, $source);
     }
 }
Пример #28
0
 /**
  * Get default death message related to the specified cause
  *
  * @param Player $player
  * @param EntityDamageEvent $cause Get message related to the specified cause
  *
  * @return string The default death message related to the specified cause
  */
 public function getDefaultDeathMessage(Player $player, $cause = null)
 {
     $cfg = $this->getConfig()->getAll();
     if ($cause instanceof EntityDamageEvent) {
         if ($cause->getCause() == EntityDamageEvent::CAUSE_CONTACT) {
             $message = $cfg["Death"]["death-contact-message"]["message"];
             if ($cause instanceof EntityDamageByBlockEvent) {
                 $message = str_replace("{BLOCK}", $cause->getDamager()->getName(), $message);
             } else {
                 $message = str_replace("{BLOCK}", "Unknown", $message);
             }
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_ENTITY_ATTACK) {
             $message = $cfg["Death"]["kill-message"]["message"];
             $killer = $cause->getDamager();
             if ($killer instanceof Living) {
                 $message = str_replace("{KILLER}", $killer->getName(), $message);
             } else {
                 $message = str_replace("{KILLER}", "Unknown", $message);
             }
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_PROJECTILE) {
             $message = $cfg["Death"]["death-projectile-message"]["message"];
             $killer = $cause->getDamager();
             if ($killer instanceof Living) {
                 $message = str_replace("{KILLER}", $killer->getName(), $message);
             } else {
                 $message = str_replace("{KILLER}", "Unknown", $message);
             }
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_SUFFOCATION) {
             $message = $cfg["Death"]["death-suffocation-message"]["message"];
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_FALL) {
             $message = $cfg["Death"]["death-fall-message"]["message"];
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_FIRE) {
             $message = $cfg["Death"]["death-fire-message"]["message"];
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_FIRE_TICK) {
             $message = $cfg["Death"]["death-on-fire-message"]["message"];
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_LAVA) {
             $message = $cfg["Death"]["death-lava-message"]["message"];
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_DROWNING) {
             $message = $cfg["Death"]["death-drowning-message"]["message"];
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_ENTITY_EXPLOSION || $cause->getCause() == EntityDamageEvent::CAUSE_BLOCK_EXPLOSION) {
             $message = $cfg["Death"]["death-explosion-message"]["message"];
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_VOID) {
             $message = $cfg["Death"]["death-void-message"]["message"];
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_SUICIDE) {
             $message = $cfg["Death"]["death-suicide-message"]["message"];
         } elseif ($cause->getCause() == EntityDamageEvent::CAUSE_MAGIC) {
             $message = $cfg["Death"]["death-magic-message"]["message"];
         } else {
             $message = $cfg["Death"]["message"];
         }
     } else {
         $message = $cfg["Death"]["message"];
     }
     $message = str_replace("{PLAYER}", $player->getName(), $message);
     $message = str_replace("{MAXPLAYERS}", $this->getServer()->getMaxPlayers(), $message);
     $message = str_replace("{TOTALPLAYERS}", count($this->getServer()->getOnlinePlayers()), $message);
     $message = str_replace("{TIME}", date($cfg["datetime-format"]), $message);
     return $this->translateColors("&", $message);
 }
Пример #29
0
 /**
  * @param float             $damage
  * @param EntityDamageEvent $source
  *
  */
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->hasEffect(Effect::FIRE_RESISTANCE) and $source->getCause() === EntityDamageEvent::CAUSE_FIRE and $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK and $source->getCause() === EntityDamageEvent::CAUSE_LAVA) {
         $source->setCancelled();
     }
     $this->server->getPluginManager()->callEvent($source);
     if ($source->isCancelled()) {
         return;
     }
     $this->setLastDamageCause($source);
     $this->setHealth($this->getHealth() - $source->getFinalDamage());
 }
Пример #30
0
 public function preventFallenDamage(EntityDamageEvent $event)
 {
     if ($event->getCause() == EntityDamageEvent::CAUSE_FALL) {
         if (!$event->getEntity() instanceof Player) {
             return;
         }
         if (isset($this->elevateQueue[$event->getEntity()->getName()])) {
             $this->log("preventFallenDamage run");
             $event->setCancelled();
         }
     }
 }