isApplicable() public method

public isApplicable ( integer $type ) : boolean
$type integer
return boolean
Exemplo n.º 1
0
 /**
  * @param EntityDamageEvent $event
  * @priority LOWEST
  */
 public function onDamage(EntityDamageEvent $event)
 {
     if ($event->isApplicable(EntityDamageEvent::MODIFIER_ARMOR) and ($damage = $event->getDamage(EntityDamageEvent::MODIFIER_ARMOR)) > 0) {
         $event->setDamage(-floor($event->getDamage() * 0.04 * $damage), EntityDamageEvent::MODIFIER_ARMOR);
     }
 }
Exemplo n.º 2
0
 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 *?
                 }
             }
         }
     }
 }