__construct() public method

public __construct ( pocketmine\level\format\FullChunk $chunk, CompoundTag $nbt )
$chunk pocketmine\level\format\FullChunk
$nbt pocketmine\nbt\tag\CompoundTag
Example #1
0
 public function __construct(FullChunk $chunk, Compound $nbt, Entity $shootingEntity = null)
 {
     $this->shootingEntity = $shootingEntity;
     if ($shootingEntity !== null) {
         $this->setDataProperty(self::DATA_SHOOTER_ID, self::DATA_TYPE_LONG, $shootingEntity->getId());
     }
     parent::__construct($chunk, $nbt);
 }
Example #2
0
 public function __construct(Entity $target, $distance = 0, $tailCount = 0, $tailDistance = null)
 {
     parent::__construct($target->getLevel()->getChunk($target->x >> 4, $target->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $target->x), new Double("", $target->y + 0.5), new Double("", $target->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)]), "TileID" => new Int("TileID", 1), "Data" => new Byte("Data", 0)]));
     $this->target = $target;
     $this->player = $target instanceof Player ? $target : ($target instanceof MobPetEntity && $target->player instanceof Player ? $target->player : null);
     $this->distance = $target instanceof Player || $tailDistance == null ? $distance : $tailDistance;
     if ($tailCount > 0) {
         new MobPetEntity($this, $distance, $tailCount - 1, $tailDistance);
     }
     $this->isHead = $target instanceof Player;
     parent::spawnToAll();
 }
Example #3
0
 public function __construct(FullChunk $chunk, $nbt)
 {
     parent::__construct($chunk, $nbt);
 }
Example #4
0
 protected function processLogin()
 {
     if ($this->isFirstTimeLogin) {
         parent::processLogin();
     } else {
         if (!$this->server->isWhitelisted(strtolower($this->getName()))) {
             $this->close($this->getLeaveMessage(), "Server is white-listed");
             return;
         } elseif ($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress()) or $this->server->getCIDBans()->isBanned($this->randomClientId)) {
             $this->close($this->getLeaveMessage(), TextFormat::RED . "You are banned");
             return;
         }
         if ($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)) {
             $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this);
         }
         if ($this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)) {
             $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
         }
         foreach ($this->server->getOnlinePlayers() as $p) {
             if ($p !== $this and strtolower($p->getName()) === strtolower($this->getName())) {
                 if ($p->kick("logged in from another location") === false) {
                     $this->close($this->getLeaveMessage(), "Logged in from another location");
                     return;
                 }
             } elseif ($p->loggedIn and $this->getUniqueId()->equals($p->getUniqueId())) {
                 if ($p->kick("logged in from another location") === false) {
                     $this->close($this->getLeaveMessage(), "Logged in from another location");
                     return;
                 }
             }
         }
         $nbt = $this->server->getOfflinePlayerData($this->username);
         $this->playedBefore = $nbt["lastPlayed"] - $nbt["firstPlayed"] > 1;
         if (!isset($nbt->NameTag)) {
             $nbt->NameTag = new StringTag("NameTag", $this->username);
         } else {
             $nbt["NameTag"] = $this->username;
         }
         if (!isset($nbt->Hunger) or !isset($nbt->Health) or !isset($nbt->MaxHealth)) {
             $nbt->Hunger = new ShortTag("Hunger", 20);
             $nbt->Health = new ShortTag("Health", 20);
             $nbt->MaxHealth = new ShortTag("MaxHealth", 20);
         }
         $this->food = $nbt["Hunger"];
         $this->setMaxHealth($nbt["MaxHealth"]);
         Entity::setHealth($nbt["Health"] <= 0 ? 20 : $nbt["Health"]);
         $this->gamemode = $nbt["playerGameType"] & 0x3;
         if ($this->server->getForceGamemode()) {
             $this->gamemode = $this->server->getGamemode();
             $nbt->playerGameType = new IntTag("playerGameType", $this->gamemode);
         }
         $this->allowFlight = $this->isCreative();
         if (($level = $this->server->getLevelByName($nbt["Level"])) === null) {
             $this->setLevel($this->server->getDefaultLevel());
             $nbt["Level"] = $this->level->getName();
             $nbt["Pos"][0] = $this->level->getSpawnLocation()->x;
             $nbt["Pos"][1] = $this->level->getSpawnLocation()->y;
             $nbt["Pos"][2] = $this->level->getSpawnLocation()->z;
         } else {
             $this->setLevel($level);
         }
         if (!$nbt instanceof CompoundTag) {
             $this->close($this->getLeaveMessage(), "Invalid data");
             return;
         }
         $this->achievements = [];
         /** @var ByteTag $achievement */
         foreach ($nbt->Achievements as $achievement) {
             $this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false;
         }
         $nbt->lastPlayed = new LongTag("lastPlayed", floor(microtime(true) * 1000));
         if ($this->server->getAutoSave()) {
             $this->server->saveOfflinePlayerData($this->username, $nbt, true);
         }
         Entity::__construct($this->level->getChunk($nbt["Pos"][0] >> 4, $nbt["Pos"][2] >> 4, true), $nbt);
         $this->loggedIn = true;
         $this->server->addOnlinePlayer($this);
         $this->server->getPluginManager()->callEvent($ev = new PlayerLoginEvent($this, "Plugin reason"));
         if ($ev->isCancelled()) {
             $this->close($this->getLeaveMessage(), $ev->getKickMessage());
             return;
         }
         if ($this->isCreative()) {
             $this->inventory->setHeldItemSlot(0);
         } else {
             $this->inventory->setHeldItemSlot($this->inventory->getHotbarSlotIndex(0));
         }
         if ($this->spawnPosition === null and isset($this->namedtag->SpawnLevel) and ($level = $this->server->getLevelByName($this->namedtag["SpawnLevel"])) instanceof Level) {
             $this->spawnPosition = new Position($this->namedtag["SpawnX"], $this->namedtag["SpawnY"], $this->namedtag["SpawnZ"], $level);
         }
         $spawnPosition = $this->getSpawn();
         $pk = new SetTimePacket();
         $pk->time = $this->level->getTime();
         $pk->started = $this->level->stopTime == false;
         $this->dataPacket($pk);
         $pk = new SetSpawnPositionPacket();
         $pk->x = (int) $spawnPosition->x;
         $pk->y = (int) $spawnPosition->y;
         $pk->z = (int) $spawnPosition->z;
         $this->dataPacket($pk);
         $this->sendAttributes();
         $pk = new SetDifficultyPacket();
         $pk->difficulty = $this->server->getDifficulty();
         $this->dataPacket($pk);
         $pk = new SetPlayerGameTypePacket();
         $pk->gamemode = $this->gamemode & 0x1;
         $this->dataPacket($pk);
         $this->sendSettings();
         $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logIn", [TextFormat::AQUA . $this->username . TextFormat::WHITE, $this->ip, $this->port, TextFormat::GREEN . $this->randomClientId . TextFormat::WHITE, $this->id, $this->level->getName(), round($this->x, 4), round($this->y, 4), round($this->z, 4)]));
         if ($this->gamemode === Player::SPECTATOR) {
             $pk = new ContainerSetContentPacket();
             $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
             $this->dataPacket($pk);
         } else {
             $pk = new ContainerSetContentPacket();
             $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
             $pk->slots = array_merge(Item::getCreativeItems(), $this->personalCreativeItems);
             $this->dataPacket($pk);
         }
         $pk = new SetEntityDataPacket();
         $pk->eid = 0;
         $pk->metadata = [self::DATA_LEAD_HOLDER => [self::DATA_TYPE_LONG, -1]];
         $this->dataPacket($pk);
         $this->forceMovement = $this->teleportPosition = $this->getPosition();
     }
 }
Example #5
0
 public function __construct(Player $player, Vector3 $bait, Item $item)
 {
     parent::__construct($player->getLevel()->getChunk($player->x >> 4, $player->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $bait->x), new Double("", $bait->y), new Double("", $bait->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
     $this->item = $item->getID() == 0 ? Item::get(1000, 0, 0) : $item;
     $this->player = $player;
     parent::spawnToAll();
 }
Example #6
0
 public function __construct(Entity $target)
 {
     parent::__construct($target->getLevel()->getChunk($target->x >> 4, $target->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $target->x), new Double("", $target->y + 0.5), new Double("", $target->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)]), "TileID" => new Int("TileID", 1), "Data" => new Byte("Data", 0)]));
     $this->item = Item::get(1, 0, 1);
     $this->block = $target;
     parent::spawnToAll();
 }
Example #7
0
 public function __construct(FullChunk $chunk, CompoundTag $nbt, bool $dropItem = true)
 {
     parent::__construct($chunk, $nbt);
     $this->dropItem = $dropItem;
 }