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


PHP EntityDamageEvent::getCause方法代码示例

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


在下文中一共展示了EntityDamageEvent::getCause方法的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)
 {
     $cause = $event->getCause();
     if ($cause === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION || $cause === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION) {
         $event->setCancelled();
     }
 }
开发者ID:somenabzofturtles,项目名称:Small-PM-Plugins,代码行数:7,代码来源:Main.php

示例3: 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

示例4: 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

示例5: onFall

 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();
     }
 }
开发者ID:DWWf,项目名称:pocketmine-plugins,代码行数:16,代码来源:Trampoline.php

示例6: onDamageByPlayer

 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;
     }
 }
开发者ID:TheGoldenPickle,项目名称:Friends,代码行数:16,代码来源:main.php

示例7: onDamageByPlayer

 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;
 }
开发者ID:TheGoldenPickle,项目名称:PartyPlugin,代码行数:17,代码来源:Main.php

示例8: onEntityDamage

 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 권한이 없습니다.");
                 }
             }
         }
     }
 }
开发者ID:Skull3x,项目名称:MineBlock,代码行数:19,代码来源:WorldManager.php

示例9: attack

 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));
     }
 }
开发者ID:TylerGames,项目名称:PocketMine-MP,代码行数:18,代码来源:Player.php

示例10: attack

 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;
 }
开发者ID:robske110,项目名称:ClearSky,代码行数:40,代码来源:Player.php

示例11: onDamage

 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;
 }
开发者ID:The-Epic-Miner,项目名称:MinigameBase,代码行数:13,代码来源:Main.php

示例12: attack

 /**
  * @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;
 }
开发者ID:kniffo80,项目名称:Genisys,代码行数:30,代码来源:Entity.php

示例13: h_onDamage

 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!");
     			}
     		}*/
 }
开发者ID:LegionPE,项目名称:LegionPE-Eta,代码行数:40,代码来源:Session.php

示例14: attack

 public function attack($damage, EntityDamageEvent $source)
 {
     if ($source->getCause() === EntityDamageEvent::CAUSE_VOID) {
         parent::attack($damage, $source);
     }
 }
开发者ID:sfpboomz,项目名称:ImagicalMine,代码行数:6,代码来源:FallingSand.php

示例15: attack

 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);
     }
 }
开发者ID:robske110,项目名称:ClearSky,代码行数:6,代码来源:Item.php


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