public function onDamage(EntityDamageEvent $event) { $damaged = $event->getEntity(); if (!$damaged instanceof Player or !($session = $this->getMain()->getSessions()->getSession($damaged)) instanceof Session or !$session->inSession($this)) { return; } if ($event instanceof EntityDamageByChildEntityEvent) { $entity = $event->getDamager(); if ($entity instanceof Player) { $ses = $this->main->getSessions()->getSession($entity); if ($ses instanceof Session and $ses->inSession($this)) { $data = $this->getPlayerData($ses); if ($data->isPlaying() and $data->getArena()->isPlaying()) { $projectile = $event->getChild(); if ($projectile instanceof Snowball) { $event->setCancelled(false); $event->setKnockBack($event->getKnockBack() * 2); } } } } } }
/** * @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()); }
public function i_onDamage(EntityDamageEvent $event, &$victimSession) { $victim = $event->getEntity(); if (!$victim instanceof Player) { return; } $victimSession = $this->getMain()->getSessions()->getSession($victim); if (!$victimSession->inSession($this)) { return; } $origCancelled = $event->isCancelled(); $event->setCancelled(false); if (!$event instanceof EntityDamageByEntityEvent) { if ($event->getCause() === EntityDamageEvent::CAUSE_SUFFOCATION) { $event->setCancelled(); $victimSession->teleport(Settings::kitpvp_spawn($this->getMain()->getServer())); return; } if ($event->getCause() === EntityDamageEvent::CAUSE_FALL) { $fallCause = $victim->getLastDamageCause(); if ($fallCause instanceof EntityDamageByEntityEvent) { if (isset($fallCause->_legionpeEta_timestamp) and microtime(true) - $fallCause->_legionpeEta_timestamp < 2) { /** @noinspection PhpUndefinedFieldInspection */ $event->_legionpeEta_fallCause = $fallCause; } } } return; } $victim = $event->getEntity(); $damager = $event->getDamager(); if (!$victim instanceof Player or !$damager instanceof Player) { return; } $attackerSession = $this->main->getSessions()->getSession($damager); if (!$attackerSession->inSession($this)) { $event->setCancelled($origCancelled); return; } $hitterData = $this->playerData[$attackerSession->getUID()]; $victimData = $this->playerData[$victimSession->getUID()]; if ($hitterData->invulnerable) { $attackerSession->tell("You are in invulnerability mode!"); $event->setCancelled(); return; } if ($victimData->invulnerable) { $attackerSession->tell("The vicitm is in invulnerability mode!"); $event->setCancelled(); return; } if (Settings::kitpvp_isSafeArea($victim) or Settings::kitpvp_isSafeArea($damager)) { $event->setCancelled(); $attackerSession->tell("You may not attack players at/from spawn!"); } elseif ($hitterData->areFriends($victimSession->getUID())) { $event->setCancelled(); } else { /** @noinspection PhpUndefinedFieldInspection */ $event->_legionpeEta_timestamp = microtime(true); /** @noinspection PhpUndefinedFieldInspection */ $event->_legionpeEta_isLadder = $victim->getLevel()->getBlockIdAt($victim->getFloorX(), $victim->getFloorY(), $victim->getFloorZ()) === Block::LADDER; if ($event instanceof EntityDamageByChildEntityEvent) { $child = $event->getChild(); if ($child instanceof Snowball) { $event->setKnockBack($event->getKnockBack() * 2.5); } elseif ($child instanceof Arrow) { $points = 0; if (!$event->isApplicable(EntityDamageEvent::MODIFIER_ARMOR)) { $armorValues = [Item::LEATHER_CAP => 1, Item::LEATHER_TUNIC => 3, Item::LEATHER_PANTS => 2, Item::LEATHER_BOOTS => 1, Item::CHAIN_HELMET => 1, Item::CHAIN_CHESTPLATE => 5, Item::CHAIN_LEGGINGS => 4, Item::CHAIN_BOOTS => 1, Item::GOLD_HELMET => 1, Item::GOLD_CHESTPLATE => 5, Item::GOLD_LEGGINGS => 3, Item::GOLD_BOOTS => 1, Item::IRON_HELMET => 2, Item::IRON_CHESTPLATE => 6, Item::IRON_LEGGINGS => 5, Item::IRON_BOOTS => 2, Item::DIAMOND_HELMET => 3, Item::DIAMOND_CHESTPLATE => 8, Item::DIAMOND_LEGGINGS => 6, Item::DIAMOND_BOOTS => 3]; foreach ($attackerSession->getPlayer()->getInventory()->getArmorContents() as $armor) { if (isset($armorValues[$armor->getId()])) { $points += $armorValues[$armor->getId()]; } } } list(, , , $damage, $fire, $knockPct) = Settings::kitpvp_getBowInfo($hitterData->getBowLevel()); $event->setDamage(max($damage - $points, 0)); if ($fire > 0) { $victim->setOnFire($fire / 20); $this->getMain()->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this->getMain(), function () use($victim) { $victim->setOnFire(0); }), $fire); } if ($knockPct > 0) { $event->setKnockBack($event->getKnockBack() * (1 + $knockPct / 100)); // what the, I put / as *? } } } } }