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


PHP EntityDamageEvent::setCancelled方法代碼示例

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


在下文中一共展示了EntityDamageEvent::setCancelled方法的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: 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

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

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

示例7: onEntityDamage

 public function onEntityDamage(EntityDamageEvent $event)
 {
     if ($this->pvp["DMG"] === false) {
         $event->setCancelled();
     }
     if ($event->getEntity() instanceof Player && $this->pvp["PVP"] !== true && $event instanceof EntityDamageByEntityEvent) {
         $dmg = $event->getDamager();
         if ($dmg instanceof Player) {
             if ($dmg->hasPermission("debe.pvpmanager.pvp.attack")) {
                 $event->setCancelled(false);
             } else {
                 $event->setCancelled();
                 $dmg->sendMessage("[PVP Manager] PVP 권한이 없습니다.");
             }
         }
     }
 }
開發者ID:stoastye85,項目名稱:Plugins,代碼行數:17,代碼來源:PVPManager.php

示例8: onEntityDamageByEntity

 public function onEntityDamageByEntity(EntityDamageEvent $event)
 {
     $entity = $event->getEntity();
     if ($event instanceof EntityDamageByEntityEvent) {
         $damager = $event->getDamager();
         if ($entity instanceof Player && $damager instanceof Player) {
             if (!$this->getConfig()->get(strtolower($damager->getName()))) {
                 $event->setCancelled(true);
                 $damager->sendMessage("You disabled PvP mode!\nUse '/pvppon' for enable!");
             }
             if (!$this->getConfig()->get(strtolower($entity->getName()))) {
                 $event->setCancelled(true);
                 $damager->sendMessage("Your target disabled PvP mode!");
             }
         }
     }
 }
開發者ID:alex2534alex,項目名稱:PocketMinePlugins,代碼行數:17,代碼來源:pvpplayer.php

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

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

示例11: onDamage

 public function onDamage(EntityDamageEvent $event)
 {
     $victim = $event->getEntity();
     if ($victim instanceof Player) {
         if ($victim->hasPermission("worldprotector.player.damage")) {
             $event->setCancelled(false);
         } elseif ($victim->getLastDamageCause() instanceof EntityDamageByEntityEvent) {
             $attacker = $victim->getLastDamageCause()->getDamager();
             if ($attacker instanceof Player) {
                 if ($attacker->hasPermission("worldprotector.player.attack")) {
                     $event->setCancelled(false);
                 } else {
                     $event->setCancelled(true);
                 }
             }
         } else {
             $event->setCancelled(true);
         }
     }
 }
開發者ID:Pocket-GAD,項目名稱:PocketMine-MP-Plugins,代碼行數:20,代碼來源:EventListener.php

示例12: onEntityDamage

 /** 
  * @param EntityDamageEvent $event 
  * @priority MONITOR
  * @ignoreCancelled true
  */
 public function onEntityDamage(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByEntityEvent) {
         if (($damager = $event->getDamager()) instanceof Player and ($entity = $event->getEntity()) instanceof Player) {
             switch ($this->plugin->getTouchMode($damager)) {
                 case SkinTools::GIVE:
                     $event->setCancelled(true);
                     $this->plugin->setStolenSkin($entity, $damager);
                     $entity->sendMessage(TextFormat::GREEN . $damager->getName() . " gave you their skin!");
                     $damager->sendMessage(TextFormat::GREEN . $entity->getName() . " has your skin now!");
                     break;
                 case SkinTools::STEAL:
                     $event->setCancelled(true);
                     $this->plugin->setStolenSkin($damager, $entity);
                     $event->getDamager()->sendMessage(TextFormat::GREEN . "You got " . $entity->getName() . "'s skin.");
                     break;
             }
         }
     }
 }
開發者ID:NameNoOne100,項目名稱:PocketMine-Plugins,代碼行數:25,代碼來源:SkinToolsListener.php

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

示例14: onEntityDamageByEntity

 public function onEntityDamageByEntity(ede $e)
 {
     if ($e instanceof edbee) {
         $p = $e->getEntity();
         $d = $e->getDamager();
         if ($this->isOni($d) and $this->isHuman($p)) {
             $this->Tatch($p, $d);
         } else {
             $e->setCancelled();
         }
     }
 }
開發者ID:moinngmg,項目名稱:Onigo,代碼行數:12,代碼來源:Main.php

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


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