當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityDamageEvent::isCancelled方法代碼示例

本文整理匯總了PHP中pocketmine\event\entity\EntityDamageEvent::isCancelled方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityDamageEvent::isCancelled方法的具體用法?PHP EntityDamageEvent::isCancelled怎麽用?PHP EntityDamageEvent::isCancelled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pocketmine\event\entity\EntityDamageEvent的用法示例。


在下文中一共展示了EntityDamageEvent::isCancelled方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

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

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

示例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 (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

示例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 (!$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

示例5: onDamage

 public function onDamage(EntityDamageEvent $event)
 {
     $victim = $event->getEntity();
     if ($victim instanceof Player) {
         if (!$event->isCancelled()) {
             if ($this->plugin->getFlyingSession($victim)->getFlying()) {
                 $this->plugin->getFlyingSession($victim)->setFlying(false);
                 $victim->sendMessage(TF::GOLD . "You are no longer in fly mode!");
             }
         }
     }
 }
開發者ID:Pocket-GAD,項目名稱:PocketMine-MP-Plugins,代碼行數:12,代碼來源:EventListener.php

示例6: onDamage

 /**
  * @priority MONITOR
  */
 public function onDamage(EntityDamageEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     $damage = $ev->getDamage();
     $player = $ev->getEntity();
     if (!$player instanceof Player) {
         return;
     }
     for ($i = 0; $i < $damage; $i++) {
         $player->getLevel()->addParticle(new RedstoneParticle(self::randVector($player), mt_rand() / mt_getrandmax() * 2));
     }
 }
開發者ID:DWWf,項目名稱:pocketmine-plugins,代碼行數:17,代碼來源:BloodMgr.php

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

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

 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) >= 2) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return false;
     }
     if (count($args) === 1) {
         if (!$sender->hasPermission("pocketmine.kill.other")) {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
             return true;
         }
         $player = $sender->getServer()->getPlayer($args[0]);
         if ($player instanceof Player) {
             $sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($player, EntityDamageEvent::CAUSE_SUICIDE, 1000));
             if ($ev->isCancelled()) {
                 return true;
             }
             $player->setLastDamageCause($ev);
             $player->setHealth(0);
             Command::broadcastCommandMessage($sender, new TranslationContainer("commands.kill.successful", [$player->getName()]));
         } else {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound"));
         }
         return true;
     }
     if ($sender instanceof Player) {
         if (!$sender->hasPermission("pocketmine.kill.self")) {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
             return true;
         }
         $sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($sender, EntityDamageEvent::CAUSE_SUICIDE, 1000));
         if ($ev->isCancelled()) {
             return true;
         }
         $sender->setLastDamageCause($ev);
         $sender->setHealth(0);
         $sender->sendMessage(new TranslationContainer("commands.kill.successful", [$sender->getName()]));
     } else {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return false;
     }
     return true;
 }
開發者ID:TylerGames,項目名稱:PocketMine-MP,代碼行數:46,代碼來源:KillCommand.php

示例10: 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) !== 0) {
         $this->sendUsage($sender, $alias);
         return false;
     }
     $sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($sender, EntityDamageEvent::CAUSE_SUICIDE, $sender->getHealth()));
     if ($ev->isCancelled()) {
         return true;
     }
     $sender->setLastDamageCause($ev);
     $sender->setHealth(0);
     $sender->sendMessage("Ouch. That look like it hurt.");
     return true;
 }
開發者ID:TBNRFrags2468,項目名稱:EssentialsPE,代碼行數:24,代碼來源:Suicide.php

示例11: execute

 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return \true;
     }
     if ($sender instanceof Player) {
         $sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($sender, EntityDamageEvent::CAUSE_SUICIDE, 1000));
         if ($ev->isCancelled()) {
             return \true;
         }
         $sender->setLastDamageCause($ev);
         $sender->setHealth(0);
         $sender->sendMessage("Ouch. That look like it hurt.");
     } else {
         $sender->sendMessage(TextFormat::RED . "You can only perform this command as a player");
     }
     return \true;
 }
開發者ID:Edwardthedog2,項目名稱:Steadfast2,代碼行數:18,代碼來源:KillCommand.php

示例12: onPvP

 public function onPvP(EntityDamageEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     if (!$ev instanceof EntityDamageByEntityEvent) {
         return;
     }
     $et = $ev->getEntity();
     if (!$et instanceof Player) {
         return;
     }
     $sp = $et->getLevel()->getSpawnLocation();
     $dist = $sp->distance($et);
     if ($dist > $this->owner->getServer()->getSpawnRadius()) {
         return;
     }
     $ev->setCancelled();
 }
開發者ID:AvivShopen,項目名稱:bad-plugins,代碼行數:19,代碼來源:PvpListener.php

示例13: onAttack

 /**
  * @priority HIGH
  */
 public function onAttack(EntityDamageEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     if (!$ev instanceof EntityDamageByEntityEvent) {
         return;
     }
     $pl = $ev->getDamager();
     if (!$pl instanceof Player) {
         return;
     }
     $n = $pl->getName();
     if (!isset($this->players[$n])) {
         return;
     }
     // Burn baby burn!!!
     $ev->getEntity()->setOnFire($this->cf["effect"]);
 }
開發者ID:HeechFive,項目名稱:pocketmine-plugins,代碼行數:22,代碼來源:FireBlade.php

示例14: onDamage

 public function onDamage(EntityDamageEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     if ($ev->getEntity() instanceof Player) {
         if (isset($this->watchers[strtolower($ev->getEntity()->getName())])) {
             $ev->setCancelled();
             return;
         }
     }
     if ($ev instanceof EntityDamageByEntityEvent) {
         if ($ev->getDamager() instanceof Player) {
             if (isset($this->watchers[strtolower($ev->getDamager()->getName())])) {
                 $ev->setCancelled();
                 return;
             }
         }
     }
 }
開發者ID:DWWf,項目名稱:pocketmine-plugins,代碼行數:20,代碼來源:CmdSpectator.php

示例15: onEntityInteract

 /**
  * @priority LOWEST
  */
 public function onEntityInteract(EntityDamageEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     if (!$ev instanceof EntityDamageByEntityEvent) {
         return;
     }
     $giver = $ev->getDamager();
     if (!$giver instanceof Player) {
         return;
     }
     $taker = $ev->getEntity();
     if (!$taker instanceof TraderNpc) {
         return;
     }
     $ev->setCancelled();
     // OK, now what...
     if ($giver->isCreative() || $giver->isSpectator()) {
         $giver->sendMessage(mc::_("No purchases while in %1% mode.", MPMU::gamemodeStr($giver->getGamemode())));
         return;
     }
     $shop = $taker->namedtag->shop->getValue();
     if (!isset($this->keepers[$shop])) {
         $this->owner->getLogger()->error(mc::_("Invalid shop %5% for NPC at %1%,%2%,%3% (%4%)", $taker->floorX(), $taker->floorY(), $taker->floorZ(), $taker->getLevel()->getName(), $shop));
         $giver->sendMessage(mc::_("Sorry, shop is closed!"));
         return;
     }
     $hand = $giver->getInventory()->getItemInHand();
     if ($this->owner->getCurrency() !== false ? $hand->getId() == $this->owner->getCurrency() : $hand->getId() == Item::GOLD_INGOT) {
         // OK, we want to buy stuff...
         $this->owner->getServer()->getScheduler()->scheduleDelayedTask(new PluginCallbackTask($this->owner, [$this, "startTrade"], [$giver, $taker, $shop]), 10);
     } else {
         if ($this->owner->isWeapon($hand)) {
             $this->shopMsg($giver, $shop, "under-attack");
             $giver->attack($this->keepers[$shop]["attack"], new EntityDamageByEntityEvent($taker, $giver, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $this->keepers[$shop]["attack"], 1.0));
         } else {
             $this->shopMsg($giver, $shop, "help-info");
         }
     }
 }
開發者ID:Gabriel865,項目名稱:pocketmine-plugins,代碼行數:44,代碼來源:ShopKeep.php


注:本文中的pocketmine\event\entity\EntityDamageEvent::isCancelled方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。