本文整理汇总了PHP中pocketmine\event\entity\EntityDamageEvent::getEntity方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityDamageEvent::getEntity方法的具体用法?PHP EntityDamageEvent::getEntity怎么用?PHP EntityDamageEvent::getEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\event\entity\EntityDamageEvent
的用法示例。
在下文中一共展示了EntityDamageEvent::getEntity方法的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();
}
}
}
}
示例2: 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();
}
}
示例3: 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();
}
}
}
示例4: onDamage
public function onDamage(EntityDamageEvent $event)
{
if (!$event->getEntity() instanceof Entity) {
return;
}
if ($event->getDamage() < 3) {
$color = TextFormat::GREEN;
} else {
if ($event->getDamage() < 6) {
$color = TextFormat::YELLOW;
} else {
$color = TextFormat::RED;
}
}
$pos = $event->getEntity()->add(0.1 * mt_rand(1, 9) * mt_rand(-1, 1), 0.1 * mt_rand(5, 9), 0.1 * mt_rand(1, 9) * mt_rand(-1, 1));
$damageParticle = new FloatingTextParticle($pos, "", $color . "-" . $event->getDamage());
if ($event->getEntity()->getHealth() < 7) {
$color = TextFormat::RED;
} else {
if ($event->getEntity()->getHealth() < 14) {
$color = TextFormat::YELLOW;
} else {
$color = TextFormat::GREEN;
}
}
$pos = $event->getEntity()->add(0, 2.5, 0);
$healthParticle = new FloatingTextParticle($pos, "", $color . ($event->getEntity()->getHealth() - $event->getDamage()) . " / " . $event->getEntity()->getMaxHealth());
$this->getServer()->getScheduler()->scheduleDelayedTask(new EventCheckTask($this, $damageParticle, $event->getEntity()->getLevel(), $event), 1);
$this->getServer()->getScheduler()->scheduleDelayedTask(new EventCheckTask($this, $healthParticle, $event->getEntity()->getLevel(), $event), 1);
}
示例5: 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();
}
}
}
示例6: 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();
}
}
}
示例7: onDamage
public function onDamage(EntityDamageEvent $event)
{
$player = $event->getEntity();
$entity = $event->getEntity();
if ($player instanceof Player && $event->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION) {
switch (mt_rand(1, 2)) {
case 1:
$event->setDamage(10);
break;
case 2:
$event->setDamage(8);
break;
}
}
}
示例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();
}
示例9: 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);
}
}
示例10: 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();
}
示例11: onEntityDamage
public function onEntityDamage(EntityDamageEvent $event)
{
$entity = $event->getEntity();
if ($entity instanceof Player) {
$player = $entity->getPlayer();
$this->renderNameTag($player);
}
}
示例12: 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));
}
}
}
示例13: factionPVP
public function factionPVP(EntityDamageEvent $factionDamage)
{
if ($factionDamage instanceof EntityDamageByEntityEvent) {
if (!$factionDamage->getEntity() instanceof Player or !$factionDamage->getDamager() instanceof Player) {
return true;
}
if (!$this->plugin->getSession($factionDamage->getEntity()->getPlayer())->inFaction() or !$this->plugin->getSession($factionDamage->getDamager()->getPlayer())) {
return true;
}
if ($factionDamage->getEntity() instanceof Player and $factionDamage->getDamager() instanceof Player) {
$player1 = $factionDamage->getEntity()->getPlayer()->getName();
$player2 = $factionDamage->getDamager()->getPlayer()->getName();
if ($this->plugin->sameFaction($player1, $player2) == true) {
$factionDamage->setCancelled(true);
}
}
}
}
示例14: onEntityDamageByEntity
public function onEntityDamageByEntity(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByEntityEvent) {
$victim = $event->getEntity();
$attacker = $event->getDamager();
$this->debug->onDebug('Damage denied');
$event->setCancelled(true);
}
}
示例15: 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]);
}
}