Beispiel #1
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();
         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
 }
 /**
  * @param Entity    $damager
  * @param Entity    $entity
  * @param int       $cause
  * @param int|int[] $damage
  * @param float     $knockBack
  */
 public function __construct(Entity $damager, Entity $entity, $cause, $damage, $knockBack = 0.4)
 {
     $this->damager = $damager;
     $this->knockBack = $knockBack;
     parent::__construct($entity, $cause, $damage);
     $this->addAttackerModifiers($damager);
 }
Beispiel #3
0
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) >= 2) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return false;
     }
     if (count($args) === 1) {
         if (!$sender->hasPermission("BukkitPE.command.kill.other")) {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
             return true;
         }
         $player = $sender->getServer()->getPlayer($args[0]);
         if ($player instanceof Player) {
             $sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($player, EntityDamageEvent::CAUSE_SUICIDE, 1000));
             if ($ev->isCancelled()) {
                 return true;
             }
             $player->setLastDamageCause($ev);
             $player->setHealth(0);
             Command::broadcastCommandMessage($sender, new TranslationContainer("commands.kill.successful", [$player->getName()]));
         } else {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound"));
         }
         return true;
     }
     if ($sender instanceof Player) {
         if (!$sender->hasPermission("BukkitPE.command.kill.self")) {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
             return true;
         }
         $sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($sender, EntityDamageEvent::CAUSE_SUICIDE, 1000));
         if ($ev->isCancelled()) {
             return true;
         }
         $sender->setLastDamageCause($ev);
         $sender->setHealth(0);
         $sender->sendMessage(new TranslationContainer("commands.kill.successful", [$sender->getName()]));
     } else {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return false;
     }
     return true;
 }
Beispiel #4
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if (!$this->isAlive()) {
         return;
     }
     if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE and $source->getCause() !== EntityDamageEvent::CAUSE_VOID) {
         $source->setCancelled();
     } elseif ($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL) {
         $source->setCancelled();
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     } elseif ($this->getLastDamageCause() === $source and $this->spawned) {
         $pk = new EntityEventPacket();
         $pk->eid = 0;
         $pk->event = EntityEventPacket::HURT_ANIMATION;
         $this->dataPacket($pk);
         if ($this->getHealth() < 0 or $this->getHealth() == 0) {
             $pk = new RespawnPacket();
             $pos = $this->getSpawn();
             $pk->x = $pos->x;
             $pk->y = $pos->y;
             $pk->z = $pos->z;
             $this->dataPacket($pk);
         }
     }
 }
Beispiel #5
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($source->getCause() === EntityDamageEvent::CAUSE_VOID) {
         parent::attack($damage, $source);
     }
 }
Beispiel #6
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($source->getCause() === EntityDamageEvent::CAUSE_VOID or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or $source->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION or $source->getCause() === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION) {
         parent::attack($damage, $source);
     }
 }
 /**
  * @param Block     $damager
  * @param Entity    $entity
  * @param int       $cause
  * @param int|int[] $damage
  */
 public function __construct(Block $damager, Entity $entity, $cause, $damage)
 {
     $this->damager = $damager;
     parent::__construct($entity, $cause, $damage);
 }
Beispiel #8
0
 /**
  * @param float             $damage
  * @param EntityDamageEvent $source
  *
  */
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->hasEffect(Effect::FIRE_RESISTANCE) and ($source->getCause() === EntityDamageEvent::CAUSE_FIRE or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or $source->getCause() === EntityDamageEvent::CAUSE_LAVA)) {
         $source->setCancelled();
     }
     if ($source instanceof EntityDamageByEntityEvent && $source->getCause() === EntityDamageEvent::CAUSE_PROJECTILE) {
         $e = $source->getDamager();
         if ($source instanceof EntityDamageByChildEntityEvent) {
             $e = $source->getChild();
         }
         if ($e instanceof ThrownExpBottle || $e instanceof ThrownPotion) {
             $source->setCancelled();
         }
     }
     $this->server->getPluginManager()->callEvent($source);
     if ($source->isCancelled()) {
         return;
     }
     $this->setLastDamageCause($source);
     $this->getHealth() - $source->getFinalDamage() <= 0 ? $this->setHealth(0) : $this->setHealth($this->getHealth() - $source->getFinalDamage());
 }