/**
  * @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();
             }
         }
     }
 }
Ejemplo n.º 2
2
 public function onDamage(EntityDamageEvent $event)
 {
     $cause = $event->getCause();
     if ($cause === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION || $cause === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION) {
         $event->setCancelled();
     }
 }
Ejemplo n.º 3
1
 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
 }
Ejemplo n.º 4
0
 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();
     }
 }
Ejemplo n.º 5
0
 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);
         }
     }
 }
Ejemplo n.º 6
0
 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
 }
Ejemplo n.º 7
0
 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 권한이 없습니다.");
             }
         }
     }
 }
Ejemplo n.º 8
0
 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!");
             }
         }
     }
 }
 public function onEntityDamageByEntity(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByEntityEvent) {
         $victim = $event->getEntity();
         $attacker = $event->getDamager();
         $this->debug->onDebug('Damage denied');
         $event->setCancelled(true);
     }
 }
Ejemplo n.º 10
0
 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);
         }
     }
 }
 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);
         }
     }
 }
 /** 
  * @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;
             }
         }
     }
 }
Ejemplo n.º 13
0
 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();
         }
     }
 }
Ejemplo n.º 14
0
 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();
         }
     }
 }
Ejemplo n.º 15
0
 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();
         }
     }
 }
Ejemplo n.º 16
0
 public function onDamage(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByEntityEvent) {
         if ($this->purgeStarted) {
             return;
         }
         if ($event->getEntity() instanceof Player and $event->getDamager() instanceof Player) {
             // TODO 제한시간 출력
             $event->setCancelled();
         }
     }
 }
Ejemplo n.º 17
0
 public function onEntityDamage(EntityDamageEvent $event)
 {
     if ($p = $event->getEntity() instanceof Player && $event instanceof EntityDamageByEntityEvent && ($d = $event->getDamager() instanceof Player)) {
         $l = $d->getLocation();
         if (!isset($this->move[$n = $d->getName()])) {
             $this->move[$n] = $l;
         }
         $m = $this->move[$n];
         if ($p->distance($d) > 5 || $m->x == $l->x && $m->y == $l->y && $m->z == $l->z && $m->getYaw() == $l->getYaw() && $m->getPitch() == $l->getPitch()) {
             $event->setCancelled(false);
         }
     }
 }
Ejemplo n.º 18
0
 public function onEntityDamage(EntityDamageEvent $event)
 {
     $entity = $event->getEntity();
     $world = $entity->getLevel();
     $block = $world->getBlock($entity->floor()->subtract(0, 1));
     if ($world->getName() == $this->getHotBlock()->getConfig()->get("world")) {
         switch ($block->getId()) {
             case Block::PLANKS:
                 $event->setCancelled(true);
                 break;
         }
     }
 }
Ejemplo n.º 19
0
 public function onDamage(EntityDamageEvent $event)
 {
     $player = $event->getEntity();
     $level = $player->getLevel();
     $spawn = $level->getSpawnLocation();
     $distance = $spawn->distance($player);
     if ($player instanceof Player) {
         if ($distance <= $this->cfg->get($level->getName())) {
             if (!$player->hasPermission("customradius.pvp")) {
                 $event->setCancelled(true);
             }
         }
     }
 }
 public function onDamage(EntityDamageEvent $event)
 {
     $entity = $event->getEntity();
     if ($entity instanceof Player) {
         $session = $this->main->getSession($entity);
         if (!$session instanceof Session) {
             $event->setCancelled();
             return;
         }
         if ($session->onDamage($event) === false) {
             $event->setCancelled();
         }
     }
 }
Ejemplo n.º 21
0
 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();
     }
 }
Ejemplo n.º 22
0
 public function onDamageByPlayer(EntityDamageEvent $ev)
 {
     $cause = $ev->getCause();
     switch ($cause) {
         case EntityDamageEvent::CAUSE_ENTITY_ATTACK:
             $atkr = $ev->getDamager();
             $player = $ev->getEntity();
             if ($atkr instanceof Player and $player instanceof Player) {
                 if ($this->isFriend($player, $atkr->getName())) {
                     $ev->setCancelled();
                     $atkr->sendMessage("Cannot attack friend :(");
                 }
             }
             break;
     }
 }
Ejemplo n.º 23
0
 public function onAttack(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByEntityEvent) {
         $damager = $event->getDamager();
         $player = $event->getEntity();
         if ($damager instanceof Player and $player instanceof Player) {
             if ($this->plugin->war->getSoldier($player) == null or $this->plugin->war->getSoldier($damager) == null) {
                 return true;
             } else {
                 if ($this->is_sameTeam($this->plugin->war->getSoldier($player), $this->plugin->war->getSoldier($damager))) {
                     $event->setCancelled(true);
                 }
             }
         }
     }
 }
Ejemplo n.º 24
0
 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();
 }
Ejemplo n.º 25
0
 public function onDamageByPlayer(EntityDamageEvent $ev)
 {
     $cause = $ev->getCause();
     switch ($cause) {
         case EntityDamageEvent::CAUSE_ENTITY_ATTACK:
             $atkr = $ev->getDamager();
             $player = $ev->getEntity();
             $pl = $ev->getPlayer();
             if ($atkr instanceof Player and $player instanceof Player) {
                 if ($this->inParty($player, $atkr->getName())) {
                     $ev->setCancelled();
                     $atkr->sendMessage(TextFormat::RED . "{$pl} is in your party!");
                 }
             }
     }
     break;
 }
 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);
             }
         }
     }
 }
Ejemplo n.º 27
0
 /**
  * @priority LOWEST
  */
 public function onDamage(EntityDamageEvent $event)
 {
     // Try keep the player alive while on transit...
     $victim = $event->getEntity();
     if (!$victim instanceof Player) {
         return;
     }
     $vname = $victim->getName();
     if (!isset($this->teleporters[$vname])) {
         return;
     }
     if (time() - $this->teleporters[$vname] > 2) {
         unset($this->teleporters[$vname()]);
         return;
     }
     $victim->heal($event->getDamage());
     $event->setDamage(0);
     $event->setCancelled(true);
 }
Ejemplo n.º 28
0
 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();
 }
Ejemplo n.º 29
0
 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;
             }
         }
     }
 }
Ejemplo n.º 30
0
 public function onEntityDamage(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByEntityEvent && !$event instanceof EntityDamageByChildEntityEvent) {
         if (($Victim = $event->getEntity()) instanceof Player && ($Damager = $event->getDamager()) instanceof Player) {
             if ($this->provider->isPair($Victim->getName(), $Damager->getName())) {
                 if (($Victim->getGamemode() == Player::SURVIVAL || $Victim->getGamemode() == Player::ADVENTURE) && ($Damager->getGamemode() == Player::SURVIVAL || $Damager->getGamemode() == Player::ADVENTURE)) {
                     $DamagerInventory = $Damager->getInventory();
                     $VictimInventory = $Victim->getInventory();
                     $Item = $DamagerInventory->getItemInHand();
                     if ($Item && $Item->getId() !== 0) {
                         $VictimInventory->addItem($VictimInventory->getItemInHand());
                         $VictimInventory->setItemInHand($Item);
                         $DamagerInventory->setItemInHand(Item::get(0));
                     }
                 }
                 $event->setCancelled(true);
             }
         }
     }
 }