示例#1
0
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) !== 1) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return false;
     }
     $difficulty = Server::getDifficultyFromString($args[0]);
     if ($sender->getServer()->isHardcore()) {
         $difficulty = 3;
     }
     if ($difficulty !== -1) {
         $sender->getServer()->setConfigInt("difficulty", $difficulty);
         $pk = new SetDifficultyPacket();
         $pk->difficulty = $sender->getServer()->getDifficulty();
         Server::broadcastPacket($sender->getServer()->getOnlinePlayers(), $pk);
         Command::broadcastCommandMessage($sender, new TranslationContainer("commands.difficulty.success", [$difficulty]));
     } else {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return false;
     }
     return true;
 }
示例#2
0
 public function attack($damage, EntityDamageEvent $source)
 {
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     }
     if ($source instanceof EntityDamageByEntityEvent) {
         $this->swimSpeed = mt_rand(150, 350) / 2000;
         $e = $source->getDamager();
         $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize();
         $pk = new EntityEventPacket();
         $pk->eid = $this->getId();
         $pk->event = EntityEventPacket::SQUID_INK_CLOUD;
         Server::broadcastPacket($this->hasSpawned, $pk);
     }
 }
示例#3
0
 /**
  * @param Player[] $target
  * @param Block[]  $blocks
  * @param int      $flags
  * @param bool     $optimizeRebuilds
  */
 public function sendBlocks(array $target, array $blocks, $flags = UpdateBlockPacket::FLAG_NONE, $optimizeRebuilds = false)
 {
     $pk = new UpdateBlockPacket();
     if ($optimizeRebuilds) {
         $chunks = [];
         foreach ($blocks as $b) {
             if ($b === null) {
                 continue;
             }
             $first = false;
             if (!isset($chunks[$index = Level::chunkHash($b->x >> 4, $b->z >> 4)])) {
                 $chunks[$index] = true;
                 $first = true;
             }
             if ($b instanceof Block) {
                 $pk->records[] = [$b->x, $b->z, $b->y, $b->getId(), $b->getDamage(), $first ? $flags : UpdateBlockPacket::FLAG_NONE];
             } else {
                 $fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
                 $pk->records[] = [$b->x, $b->z, $b->y, $fullBlock >> 4, $fullBlock & 0xf, $first ? $flags : UpdateBlockPacket::FLAG_NONE];
             }
         }
     } else {
         foreach ($blocks as $b) {
             if ($b === null) {
                 continue;
             }
             if ($b instanceof Block) {
                 $pk->records[] = [$b->x, $b->z, $b->y, $b->getId(), $b->getDamage(), $flags];
             } else {
                 $fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
                 $pk->records[] = [$b->x, $b->z, $b->y, $fullBlock >> 4, $fullBlock & 0xf, $flags];
             }
         }
     }
     Server::broadcastPacket($target, $pk);
 }
示例#4
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
 }
示例#5
0
 /**
  * @param Player|Player[] $target
  */
 public function sendHeldItem($target)
 {
     $item = $this->getItemInHand();
     $pk = new MobEquipmentPacket();
     $pk->eid = $target === $this->getHolder() ? 0 : $this->getHolder()->getId();
     $pk->item = $item;
     $pk->slot = $this->getHeldItemSlot();
     $pk->selectedSlot = $this->getHeldItemIndex();
     if (!is_array($target)) {
         $target->dataPacket($pk);
         if ($target === $this->getHolder()) {
             $this->sendSlot($this->getHeldItemSlot(), $target);
         }
     } else {
         Server::broadcastPacket($target, $pk);
         foreach ($target as $player) {
             if ($player === $this->getHolder()) {
                 $this->sendSlot($this->getHeldItemSlot(), $player);
                 break;
             }
         }
     }
 }
示例#6
0
 /**
  * @param Player[]|Player $player
  * @param array $data Properly formatted entity data, defaults to everything
  */
 public function sendData($player, array $data = null)
 {
     $pk = new SetEntityDataPacket();
     $pk->eid = $player === $this ? 0 : $this->getId();
     $pk->metadata = $data === null ? $this->dataProperties : $data;
     if (!is_array($player)) {
         $player->dataPacket($pk);
     } else {
         Server::broadcastPacket($player, $pk);
     }
 }