當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。