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


PHP entity\EntityDamageEvent类代码示例

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


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

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

示例2: onDeath

 public function onDeath(EntityDamageEvent $event)
 {
     $damage = $event->getDamage();
     $health = $event->getDamager()->getHealth();
     if ($health <= $damage) {
         $player = $event->getDamager();
         $money = $this->getConfig()->get("money");
         $player->sendMessage("You've Earned 8 Coins");
         $this->addMoney($player->getName(), $money);
     }
 }
开发者ID:RedEnder,项目名称:KillMoney,代码行数:11,代码来源:Main.php

示例3: execute

 /**
  * @param CommandSender $sender
  * @param string $alias
  * @param array $args
  * @return bool
  */
 public function execute(CommandSender $sender, $alias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return false;
     }
     if (!$sender instanceof Player && count($args) !== 1) {
         $this->sendUsage($sender, $alias);
         return false;
     }
     $player = $sender;
     if (isset($args[0])) {
         if (!$sender->hasPermission("essentials.kill.other")) {
             $sender->sendMessage(TextFormat::RED . $this->getPermissionMessage());
             return false;
         }
         if (!($player = $this->getAPI()->getPlayer($args[0])) instanceof Player) {
             $sender->sendMessage(TextFormat::RED . "[Error] Player not found");
             return false;
         }
     }
     if ($this->getAPI()->isGod($player)) {
         $sender->sendMessage(TextFormat::RED . $args[0] . " can't be killed!");
         return false;
     }
     $sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($player, EntityDamageEvent::CAUSE_SUICIDE, $player->getHealth()));
     if ($ev->isCancelled()) {
         return true;
     }
     $player->setLastDamageCause($ev);
     $player->setHealth(0);
     $player->sendMessage("Ouch. That look like it hurt.");
     return true;
 }
开发者ID:TBNRFrags2468,项目名称:EssentialsPE,代码行数:39,代码来源:Kill.php

示例4: execute

 /**
  * @param CommandSender $sender
  * @param string $alias
  * @param array $args
  * @return bool
  */
 public function execute(CommandSender $sender, $alias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return false;
     }
     if (count($args) !== 1) {
         $sender->sendMessage($sender instanceof Player ? $this->getUsage() : $this->getConsoleUsage());
         return false;
     }
     $player = $this->getPlugin()->getPlayer($args[0]);
     if (!$player instanceof Player) {
         $sender->sendMessage(TextFormat::RED . "[Error] Player not found");
         return false;
     }
     if ($this->getPlugin()->isGod($player)) {
         $sender->sendMessage(TextFormat::RED . "You can't kill " . $args[0]);
         return false;
     }
     $sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($player, EntityDamageEvent::CAUSE_SUICIDE, $player->getHealth()));
     if ($ev->isCancelled()) {
         return true;
     }
     $player->setLastDamageCause($ev);
     $player->setHealth(0);
     $player->sendMessage("Ouch. That look like it hurt.");
     return true;
 }
开发者ID:ZencraftYouTube,项目名称:EssentialsPE,代码行数:33,代码来源:Kill.php

示例5: attack

 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->attackTime > 0 or $this->noDamageTicks > 0) {
         $lastCause = $this->getLastDamageCause();
         if ($lastCause !== null and $lastCause->getDamage() >= $damage) {
             $source->setCancelled();
         }
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     }
     if ($source instanceof EntityDamageByEntityEvent) {
         $e = $source->getDamager();
         $deltaX = $this->x - $e->x;
         $deltaZ = $this->z - $e->z;
         $yaw = atan2($deltaX, $deltaZ);
         $this->knockBack($e, $damage, sin($yaw), cos($yaw), $source->getKnockBack());
     }
     $pk = new EntityEventPacket();
     $pk->eid = $this->getId();
     $pk->event = $this->getHealth() <= 0 ? 3 : 2;
     //Ouch!
     Server::broadcastPacket($this->hasSpawned, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     $this->attackTime = 10;
     //0.5 seconds cooldown
 }
开发者ID:TylerGames,项目名称:PocketMine-MP,代码行数:27,代码来源:Living.php

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

示例7: attack

 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->attackTime > 0 or $this->noDamageTicks > 0) {
         $lastCause = $this->getLastDamageCause();
         if ($lastCause !== null and $lastCause->getDamage() >= $damage) {
             $source->setCancelled();
         }
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     }
     if ($source instanceof EntityDamageByEntityEvent) {
         $e = $source->getDamager();
         if ($source instanceof EntityDamageByChildEntityEvent) {
             $e = $source->getChild();
         }
         if ($e->isOnFire() > 0) {
             $this->setOnFire(2 * $this->server->getDifficulty());
         }
         $deltaX = $this->x - $e->x;
         $deltaZ = $this->z - $e->z;
         $this->knockBack($e, $damage, $deltaX, $deltaZ, $source->getKnockBack());
     }
     $pk = new EntityEventPacket();
     $pk->eid = $this->getId();
     $pk->event = $this->getHealth() <= 0 ? EntityEventPacket::DEATH_ANIMATION : EntityEventPacket::HURT_ANIMATION;
     // Ouch!
     Server::broadcastPacket($this->hasSpawned, $pk);
     $this->attackTime = 10;
     //0.5 seconds cooldown
 }
开发者ID:vellrya,项目名称:ClearSky,代码行数:32,代码来源:Living.php

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

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

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

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

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

示例13: onEntityDamage

 public function onEntityDamage(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByEntityEvent) {
         $damager = $event->getDamager();
         if ($damager instanceof Player && $this->isPlayer($damager)) {
             $damager->sendTip(TextFormat::RED . "You cannot damage players while in fly mode!");
             $event->setCancelled(true);
         }
     }
 }
开发者ID:Ad5001,项目名称:SafeFly,代码行数:10,代码来源:Main.php

示例14: EntityDamageEvent

 /**
  * @param EnityDamageEvent $event
  *
  * @priority LOW
  * @ignoreCancelled true
  */
 public function EntityDamageEvent(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByEntityEvent) {
         if ($event->getDamager() instanceof Player) {
             foreach (array($event->getDamager(), $event->getEntity()) as $players) {
                 $this->setTime($players);
             }
         }
     }
 }
开发者ID:kdani1,项目名称:CombatLogger,代码行数:16,代码来源:Main.php

示例15: onHurt

 public function onHurt(EntityDamageEvent $event)
 {
     $player = $event->getEntity();
     if ($player instanceof Player) {
         if (!$player->haspermission("worldprotetor.player.hurt")) {
             $event->setCancelled(true);
         } else {
             $event->setCancelled(false);
         }
     }
 }
开发者ID:HeroGamingZ,项目名称:PocketMine-MP-Plugins,代码行数:11,代码来源:Main.php


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