当前位置: 首页>>代码示例>>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;未经允许,请勿转载。