本文整理汇总了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();
}
}
}
}
示例2: onDamage
public function onDamage(EntityDamageEvent $event)
{
$cause = $event->getCause();
if ($cause === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION || $cause === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION) {
$event->setCancelled();
}
}
示例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();
}
}
示例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);
}
}
}
示例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
}
示例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
}
示例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 권한이 없습니다.");
}
}
}
}
示例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!");
}
}
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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;
}
}
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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();
}
}
}