当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityDamageEvent::getEntity方法代码示例

本文整理汇总了PHP中pocketmine\event\entity\EntityDamageEvent::getEntity方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityDamageEvent::getEntity方法的具体用法?PHP EntityDamageEvent::getEntity怎么用?PHP EntityDamageEvent::getEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\event\entity\EntityDamageEvent的用法示例。


在下文中一共展示了EntityDamageEvent::getEntity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onDamage

 /**
  * @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();
             }
         }
     }
 }
开发者ID:barnseyminesuk,项目名称:Small-ZC-Plugins,代码行数:63,代码来源:EventListener.php

示例2: onDamage

 public function onDamage(EntityDamageEvent $event)
 {
     $event_is = false;
     $c = $event->getEntity()->getLastDamageCause();
     //sheep's last dmg cause
     $sheep = $event->getEntity();
     if ($this->isSheepInCooldown($sheep)) {
         $p = $event->getEntity()->getLastDamageCause()->getDamager();
         //player
         $p->sendPopup(TextFormat::YELLOW . "Sheep is in cooldown!");
         $event->setCancelled();
         return true;
     }
     if ($event->getEntity() instanceof Sheep) {
         if ($c instanceof EntityDamageByEntityEvent) {
             $d = $c->getDamager();
             //player..
             if ($d instanceof Player) {
                 $itemf = $d->getInventory()->getItemInHand()->getId();
                 if ($itemf === Item::SHEARS) {
                     $event_is = true;
                     $amount = rand(1, 3);
                     $d->getInventory()->addItem(new ItemBlock(new Wool(), 0, $amount));
                     array_push($this->cooldown, new CooldownClass($sheep, $this->getConfig()->get("cooldown")));
                     $d->sendPopup(TextFormat::GREEN . "Sheared and got " . $amount . " wool!");
                 }
             }
         }
     }
     if ($event_is) {
         $event->setCancelled();
     }
 }
开发者ID:HotFireyDeath,项目名称:PM-Plugins,代码行数:33,代码来源:SheepFix.php

示例3: onAttack

 public function onAttack(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByEntityEvent or $event instanceof EntityDamageByChildEntityEvent) {
         if ($event->getDamager() instanceof Player and $event->getEntity() instanceof Player) {
             $this->attackQueue[$event->getEntity()->getName()] = $event->getDamager()->getName();
         }
     }
 }
开发者ID:nesgohood,项目名称:PMMP-Plugins,代码行数:8,代码来源:PVPMoney.php

示例4: onDamage

 public function onDamage(EntityDamageEvent $event)
 {
     if (!$event->getEntity() instanceof Entity) {
         return;
     }
     if ($event->getDamage() < 3) {
         $color = TextFormat::GREEN;
     } else {
         if ($event->getDamage() < 6) {
             $color = TextFormat::YELLOW;
         } else {
             $color = TextFormat::RED;
         }
     }
     $pos = $event->getEntity()->add(0.1 * mt_rand(1, 9) * mt_rand(-1, 1), 0.1 * mt_rand(5, 9), 0.1 * mt_rand(1, 9) * mt_rand(-1, 1));
     $damageParticle = new FloatingTextParticle($pos, "", $color . "-" . $event->getDamage());
     if ($event->getEntity()->getHealth() < 7) {
         $color = TextFormat::RED;
     } else {
         if ($event->getEntity()->getHealth() < 14) {
             $color = TextFormat::YELLOW;
         } else {
             $color = TextFormat::GREEN;
         }
     }
     $pos = $event->getEntity()->add(0, 2.5, 0);
     $healthParticle = new FloatingTextParticle($pos, "", $color . ($event->getEntity()->getHealth() - $event->getDamage()) . " / " . $event->getEntity()->getMaxHealth());
     $this->getServer()->getScheduler()->scheduleDelayedTask(new EventCheckTask($this, $damageParticle, $event->getEntity()->getLevel(), $event), 1);
     $this->getServer()->getScheduler()->scheduleDelayedTask(new EventCheckTask($this, $healthParticle, $event->getEntity()->getLevel(), $event), 1);
 }
开发者ID:nesgohood,项目名称:PMMP-Plugins,代码行数:30,代码来源:DamageEffect.php

示例5: onAttack

 public function onAttack(EntityDamageEvent $event)
 {
     if (!$event instanceof EntityDamageByEntityEvent) {
         return;
     }
     if ($event->getEntity() instanceof Player and $event->getDamager() instanceof Player) {
         if ($event->getEntity()->distance($event->getDamager()) > 7) {
             $event->setCancelled();
         }
     }
 }
开发者ID:EmreTr1,项目名称:rtr,代码行数:11,代码来源:placebo.php

示例6: fallenDamagePrevent

 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();
         }
     }
 }
开发者ID:EmreTr1,项目名称:rtr,代码行数:12,代码来源:StartDASH.php

示例7: onDamage

 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;
         }
     }
 }
开发者ID:XxmellonxX,项目名称:MTNT1B,代码行数:15,代码来源:Tnt.php

示例8: onDamage

 public function onDamage(EntityDamageEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     if (!$ev instanceof EntityDamageByEntityEvent) {
         return;
     }
     if (!$ev->getEntity() instanceof Player) {
         return;
     }
     if (!$this->getState("shield", $ev->getEntity(), false)) {
         return;
     }
     $ev->setCancelled();
 }
开发者ID:DWWf,项目名称:pocketmine-plugins,代码行数:16,代码来源:ShieldSession.php

示例9: onEntityDamage

 public function onEntityDamage(EntityDamageEvent $event)
 {
     if (!$event->isCancelled() && $event instanceof EntityDamageByEntityEvent) {
         $e = $event->getEntity();
         $arrow = $event->getDamager();
         $damage = round($event->getDamage() / 2);
         if ($arrow instanceof AbilityArrow) {
             $shoter = $arrow->shootingEntity;
             if ($shoter instanceof Player) {
                 if ($arrow instanceof FireArrow) {
                     $e->setOnFire(rand(3, 10));
                 } elseif ($arrow instanceof TeleportArrow) {
                     $shoter->teleport($e);
                 } elseif ($arrow instanceof SpiderArrow) {
                     $e->getLevel()->setBlock($e, Block::get(30));
                 } elseif ($arrow instanceof HealArrow) {
                     $damage = -$damage;
                 } elseif ($arrow instanceof PowerArrow) {
                     $damage = round($damage * rand(2, 3) / 2);
                 } else {
                     return;
                 }
                 $arrow->kill();
             }
         }
         $event->setDamage($damage);
     }
 }
开发者ID:stoastye85,项目名称:Plugins,代码行数:28,代码来源:ArrowAbility.php

示例10: onPvP

 public function onPvP(EntityDamageEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     if (!$ev instanceof EntityDamageByEntityEvent) {
         return;
     }
     if (!(($pl = $ev->getEntity()) instanceof Player && $ev->getDamager() instanceof Player)) {
         return;
     }
     $world = $pl->getLevel()->getName();
     if (!isset($this->wcfg[$world])) {
         return;
     }
     if ($this->wcfg[$world] !== false) {
         $sp = $pl->getLevel()->getSpawnLocation();
         $dist = $sp->distance($pl);
         if ($dist > $this->owner->getServer()->getSpawnRadius()) {
             return;
         }
     }
     $this->owner->msg($ev->getDamager(), mc::_("You are not allowed to do that here"));
     $ev->setCancelled();
 }
开发者ID:DWWf,项目名称:pocketmine-plugins,代码行数:25,代码来源:WpPvpMgr.php

示例11: onEntityDamage

 public function onEntityDamage(EntityDamageEvent $event)
 {
     $entity = $event->getEntity();
     if ($entity instanceof Player) {
         $player = $entity->getPlayer();
         $this->renderNameTag($player);
     }
 }
开发者ID:EnderKenji,项目名称:HealthTag,代码行数:8,代码来源:HealthTag.php

示例12: onHurt

 public function onHurt(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByEntityEvent) {
         if ($event->getDamager()->getInventory()->getItemInHand()->getId() === 276) {
             $event->getEntity()->addEffect(Effect::getEffect($this->getConfig()->get("DiamondSwordEffect"))->setAmplifier($this->getConfig()->get("DiamondSwordAmp"))->setDuration($this->getConfig()->get("DiamondSwordTime"))->setVisible(false));
         }
     }
 }
开发者ID:xHFx,项目名称:SwordEffects,代码行数:8,代码来源:Main.php

示例13: factionPVP

 public function factionPVP(EntityDamageEvent $factionDamage)
 {
     if ($factionDamage instanceof EntityDamageByEntityEvent) {
         if (!$factionDamage->getEntity() instanceof Player or !$factionDamage->getDamager() instanceof Player) {
             return true;
         }
         if (!$this->plugin->getSession($factionDamage->getEntity()->getPlayer())->inFaction() or !$this->plugin->getSession($factionDamage->getDamager()->getPlayer())) {
             return true;
         }
         if ($factionDamage->getEntity() instanceof Player and $factionDamage->getDamager() instanceof Player) {
             $player1 = $factionDamage->getEntity()->getPlayer()->getName();
             $player2 = $factionDamage->getDamager()->getPlayer()->getName();
             if ($this->plugin->sameFaction($player1, $player2) == true) {
                 $factionDamage->setCancelled(true);
             }
         }
     }
 }
开发者ID:JiangsNetworkAlpha,项目名称:zzzzzz-FACTIONS,代码行数:18,代码来源:FactionListener.php

示例14: onEntityDamageByEntity

 public function onEntityDamageByEntity(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByEntityEvent) {
         $victim = $event->getEntity();
         $attacker = $event->getDamager();
         $this->debug->onDebug('Damage denied');
         $event->setCancelled(true);
     }
 }
开发者ID:100henrik100,项目名称:Minecraft-Pocket-Edition,代码行数:9,代码来源:antipvp.php

示例15: onHit

 public function onHit(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByChildEntityEvent) {
         $target = $event->getEntity();
         $player = $event->getDamager();
         $event->getDamager()->sendTip("§aYou hit§c " . $target->getName());
         $player->getLevel()->addSound(new AnvilFallSound($player), [$player]);
     }
 }
开发者ID:CaptainKenji17,项目名称:ArrowHit,代码行数:9,代码来源:Main.php


注:本文中的pocketmine\event\entity\EntityDamageEvent::getEntity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。