dataPacket() public method

Sends an ordered DataPacket to the send buffer
public dataPacket ( DataPacket $packet, boolean $needACK = false ) : integer | boolean
$packet pocketmine\network\protocol\DataPacket
$needACK boolean
return integer | boolean
Ejemplo n.º 1
0
 public function spawnDiscourager()
 {
     $dir = $this->player->getDirectionVector();
     if ($this->player->pitch > 45 or $this->player->pitch < -45) {
         $face = 0;
         // y
     } else {
         $face = self::$conversionTable[$this->player->getDirection()];
     }
     $center = $this->player->subtract($dir->multiply($this->main->getDistance()))->add(0, $this->player->eyeHeight)->floor();
     $l = $this->player->getLevel();
     if ($face === self::Y) {
         $this->overridenBlocks = [$l->getBlock($center->add(1, 0, 1)), $l->getBlock($center->add(1, 0, 0)), $l->getBlock($center->add(1, 0, -1)), $l->getBlock($center->add(0, 0, 1)), $l->getBlock($center), $l->getBlock($center->add(0, 0, -1)), $l->getBlock($center->add(-1, 0, 1)), $l->getBlock($center->add(-1, 0, 0)), $l->getBlock($center->add(-1, 0, -1))];
     } elseif ($face === self::X) {
         $this->overridenBlocks = [$l->getBlock($center->add(0, 1, 1)), $l->getBlock($center->add(0, 1, 0)), $l->getBlock($center->add(0, 1, -1)), $l->getBlock($center->add(0, 0, 1)), $l->getBlock($center), $l->getBlock($center->add(0, 0, -1)), $l->getBlock($center->add(0, -1, 1)), $l->getBlock($center->add(0, -1, 0)), $l->getBlock($center->add(0, -1, -1))];
     } elseif ($face === self::Z) {
         $this->overridenBlocks = [$l->getBlock($center->add(1, 1, 0)), $l->getBlock($center->add(1, 0, 0)), $l->getBlock($center->add(1, -1, 0)), $l->getBlock($center->add(0, 1, 0)), $l->getBlock($center), $l->getBlock($center->add(0, -1, 0)), $l->getBlock($center->add(-1, 1, 0)), $l->getBlock($center->add(-1, 0, 0)), $l->getBlock($center->add(-1, -1, 0))];
     }
     foreach ($this->overridenBlocks as $b) {
         $pk = new UpdateBlockPacket();
         $pk->x = $b->x;
         $pk->y = $b->y;
         $pk->z = $b->z;
         $pk->block = $this->main->getBlockType()->getId();
         $pk->meta = $this->main->getBlockType()->getDamage();
         $this->player->dataPacket($pk);
     }
 }
Ejemplo n.º 2
0
 public function sendWeather(Player $p)
 {
     $pk1 = new LevelEventPacket();
     $pk1->evid = LevelEventPacket::EVENT_STOP_RAIN;
     $pk1->data = $this->strength1;
     $pk2 = new LevelEventPacket();
     $pk2->evid = LevelEventPacket::EVENT_STOP_THUNDER;
     $pk2->data = $this->strength2;
     if ($p->weatherData[0] != $this->weatherNow) {
         $p->dataPacket($pk1);
         $p->dataPacket($pk2);
         if ($this->weatherNow == 1) {
             $pk = new LevelEventPacket();
             $pk->evid = LevelEventPacket::EVENT_START_RAIN;
             $pk->data = $this->strength1;
             $p->dataPacket($pk);
         } elseif ($this->weatherNow == 2) {
             $pk = new LevelEventPacket();
             $pk->evid = LevelEventPacket::EVENT_START_RAIN;
             $pk->data = $this->strength1;
             $p->dataPacket($pk);
             $pk = new LevelEventPacket();
             $pk->evid = LevelEventPacket::EVENT_START_THUNDER;
             $pk->data = $this->strength2;
             $p->dataPacket($pk);
         } elseif ($this->weatherNow == 3) {
             $pk = new LevelEventPacket();
             $pk->evid = LevelEventPacket::EVENT_START_THUNDER;
             $pk->data = $this->strength2;
             $p->dataPacket($pk);
         }
         $p->weatherData = [$this->weatherNow, $this->strength1, $this->strength2];
     }
 }
 private function invis()
 {
     $pk = new SetEntityDataPacket();
     $pk->eid = $this->eid;
     $flags = 1 << Entity::DATA_FLAG_INVISIBLE;
     $pk->data = [Entity::DATA_FLAGS => [Entity::DATA_TYPE_INT, $flags]];
     $this->player->dataPacket($pk);
     $pk = new SetEntityDataPacket();
     $pk->eid = $this->eid;
     $pk->data = [Entity::DATA_SHOW_NAMETAG => [Entity::DATA_TYPE_BYTE, 0]];
     $this->player->dataPacket($pk);
 }
Ejemplo n.º 4
0
 public function illuminate(Player $player)
 {
     if ($player == null) {
         return;
     }
     if ($player->getLevel()->getBlockIdAt($player->x, $player->y + 1, $player->z) == Block::AIR) {
         $this->pk->x = $player->x;
         $this->pk->y = $player->y + 1;
         $this->pk->z = $player->z;
         $this->pk->block = Item::TORCH;
         $this->pk->meta = 0;
         $player->dataPacket($this->pk);
         $this->pk->block = Item::AIR;
         $player->dataPacket($this->pk);
     }
 }
 public function onClose(Player $who)
 {
     $pk = new ContainerClosePacket();
     $pk->windowid = $who->getWindowId($this);
     $who->dataPacket($pk);
     parent::onClose($who);
 }
Ejemplo n.º 6
0
 public function spawnTo(Player $player)
 {
     if ($player !== $this and !isset($this->hasSpawned[$player->getLoaderId()])) {
         $this->hasSpawned[$player->getLoaderId()] = $player;
         $uuid = $this->getUniqueId();
         $entityId = $this->getId();
         $pk = new AddPlayerPacket();
         $pk->uuid = $uuid;
         $pk->username = "";
         $pk->eid = $entityId;
         $pk->x = $this->x;
         $pk->y = $this->y;
         $pk->z = $this->z;
         $pk->yaw = $this->yaw;
         $pk->pitch = $this->pitch;
         $pk->item = $this->getInventory()->getItemInHand();
         $pk->metadata = [2 => [4, str_ireplace("{name}", $player->getName(), str_ireplace("{display_name}", $player->getDisplayName(), $player->hasPermission("slapper.seeId") ? $this->getDataProperty(2) . "\n" . \pocketmine\utils\TextFormat::GREEN . "Entity ID: " . $entityId : $this->getDataProperty(2)))], 3 => [0, $this->getDataProperty(3)], 15 => [0, 1]];
         $player->dataPacket($pk);
         $this->inventory->sendArmorContents($player);
         $add = new PlayerListPacket();
         $add->type = 0;
         $add->entries[] = [$uuid, $entityId, isset($this->namedtag->MenuName) ? $this->namedtag["MenuName"] : "", $this->skinName, $this->skin];
         $player->dataPacket($add);
         if ($this->namedtag["MenuName"] === "") {
             $remove = new PlayerListPacket();
             $remove->type = 1;
             $remove->entries[] = [$uuid];
             $player->dataPacket($remove);
         }
     }
 }
Ejemplo n.º 7
0
 public function sendAll()
 {
     $pk = new UpdateAttributesPacket();
     $pk->entityId = 0;
     $pk->entries = $this->attributes;
     $this->player->dataPacket($pk);
 }
 public function onClose(Player $who)
 {
     $pk = new ContainerClosePacket();
     $pk->windowid = $who->getWindowId($this);
     $who->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     parent::onClose($who);
 }
 private function sendData($data)
 {
     $pk = new SetEntityDataPacket();
     $pk->eid = $this->eid();
     $pk->metadata = $data === null ? $this->metadata : $data;
     $this->player->dataPacket($pk);
 }
Ejemplo n.º 10
0
 public function spawnTo(Player $player)
 {
     if ($player !== $this and !isset($this->hasSpawned[$player->getLoaderId()])) {
         $this->hasSpawned[$player->getLoaderId()] = $player;
         $pk = new AddPlayerPacket();
         $pk->uuid = $this->getUniqueId();
         $pk->username = $this->getName();
         $pk->eid = $this->getId();
         $pk->x = $this->x;
         $pk->y = $this->y;
         $pk->z = $this->z;
         $pk->speedX = 0;
         $pk->speedY = 0;
         $pk->speedZ = 0;
         $pk->yaw = $this->yaw;
         $pk->pitch = $this->pitch;
         $item = $this->getInventory()->getItemInHand();
         $pk->item = $item;
         if ($player->hasPermission("slapper.seeownskin")) {
             $pk->skin = $player->getSkinData();
             $pk->slim = $player->isSkinSlim();
         } else {
             $pk->skin = $this->skin;
             $pk->slim = $this->isSlim;
         }
         $pk->metadata = [2 => [4, $this->getDataProperty(2)], 3 => [0, $this->getDataProperty(3)], 15 => [0, 1]];
         $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
         $this->inventory->sendArmorContents($player);
     }
 }
Ejemplo n.º 11
0
 public function spawnTo(Player $player)
 {
     $pk = new AddMobPacket();
     $pk->eid = $this->getID();
     $pk->type = Villager::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->yaw = $this->yaw;
     $pk->pitch = $this->pitch;
     $pk->metadata = $this->getData();
     $player->dataPacket($pk);
     $pk = new SetEntityMotionPacket();
     $pk->entities = [[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]];
     $player->dataPacket($pk);
     parent::spawnTo($player);
 }
Ejemplo n.º 12
0
 public function onActivate(Item $item, Player $player = null)
 {
     $time = $this->getLevel()->getTime() % Level::TIME_FULL;
     $isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE);
     if ($player instanceof Player and !$isNight) {
         $pk = new ChatPacket();
         $pk->message = "You can only sleep at night";
         $player->dataPacket($pk);
         return true;
     }
     $blockNorth = $this->getSide(2);
     //Gets the blocks around them
     $blockSouth = $this->getSide(3);
     $blockEast = $this->getSide(5);
     $blockWest = $this->getSide(4);
     if (($this->meta & 0x8) === 0x8) {
         //This is the Top part of bed
         $b = $this;
     } else {
         //Bottom Part of Bed
         if ($blockNorth->getId() === $this->id and ($blockNorth->meta & 0x8) === 0x8) {
             $b = $blockNorth;
         } elseif ($blockSouth->getId() === $this->id and ($blockSouth->meta & 0x8) === 0x8) {
             $b = $blockSouth;
         } elseif ($blockEast->getId() === $this->id and ($blockEast->meta & 0x8) === 0x8) {
             $b = $blockEast;
         } elseif ($blockWest->getId() === $this->id and ($blockWest->meta & 0x8) === 0x8) {
             $b = $blockWest;
         } else {
             if ($player instanceof Player) {
                 $pk = new ChatPacket();
                 $pk->message = "This bed is incomplete";
                 $player->dataPacket($pk);
             }
             return true;
         }
     }
     if ($player instanceof Player and $player->sleepOn($b) === false) {
         $pk = new ChatPacket();
         $pk->message = "This bed is occupied";
         $player->dataPacket($pk);
     }
     return true;
 }
Ejemplo n.º 13
0
 public function spawnTo(Player $player)
 {
     $pk = new SpawnExperienceOrbPacket();
     $pk->eid = $this->getId();
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->count = $this->getAmount();
     $player->dataPacket($pk);
     parent::spawnTo($player);
 }
Ejemplo n.º 14
0
 public function send()
 {
     $pk = new UpdateAttributesPacket();
     $pk->maxValue = $this->getMaxValue();
     $pk->minValue = $this->getMinValue();
     $pk->value = $this->currentValue;
     $pk->name = $this->getName();
     $pk->entityId = 0;
     $pk->encode();
     $this->player->dataPacket($pk);
 }
Ejemplo n.º 15
0
 public function spawnTo(Player $player)
 {
     $pk = new AddPaintingPacket();
     $pk->eid = $this->getId();
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->direction = $this->getDirection();
     $pk->title = $this->motive;
     $player->dataPacket($pk);
     parent::spawnTo($player);
 }
Ejemplo n.º 16
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = 40;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->yaw = $this->yaw;
     $pk->pitch = $this->pitch;
     $pk->metadata = [2 => [4, str_ireplace("{name}", $player->getName(), str_ireplace("{display_name}", $player->getDisplayName(), $player->hasPermission("slapper.seeId") ? $this->getDataProperty(2) . "\n" . \pocketmine\utils\TextFormat::GREEN . "Entity ID: " . $this->getId() : $this->getDataProperty(2)))], 3 => [0, $this->getDataProperty(3)], 15 => [0, 1]];
     $player->dataPacket($pk);
     parent::spawnTo($player);
 }
Ejemplo n.º 17
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->type = Arrow::NETWORK_ID;
     $pk->eid = $this->getId();
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->did = 0;
     //TODO: send motion here
     $player->dataPacket($pk);
     $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
     parent::spawnTo($player);
 }
Ejemplo n.º 18
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->type = Arrow::NETWORK_ID;
     $pk->eid = $this->getId();
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->speedX = $this->motionX;
     $pk->speedY = $this->motionY;
     $pk->speedZ = $this->motionZ;
     $pk->metadata = $this->dataProperties;
     $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
     parent::spawnTo($player);
 }
Ejemplo n.º 19
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->type = ZombieVillager::NETWORK_ID;
     $pk->eid = $this->getId();
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->speedX = $this->motionX;
     $pk->speedY = $this->motionY;
     $pk->speedZ = $this->motionZ;
     $pk->metadata = $this->dataProperties;
     $player->dataPacket($pk);
     parent::spawnTo($player);
 }
Ejemplo n.º 20
0
 public function spawnTo(Player $player)
 {
     if ($this->closed) {
         return false;
     }
     $nbt = new NBT(NBT::LITTLE_ENDIAN);
     $nbt->setData($this->getSpawnCompound());
     $pk = new TileEntityDataPacket();
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->namedtag = $nbt->write();
     $player->dataPacket($pk);
     return true;
 }
Ejemplo n.º 21
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = Skeleton::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->yaw = $this->yaw;
     $pk->pitch = $this->pitch;
     $pk->metadata = $this->dataProperties;
     $player->dataPacket($pk);
     $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
     parent::spawnTo($player);
 }
Ejemplo n.º 22
0
 public function spawnTo(Player $player)
 {
     if ($this->closed) {
         return \false;
     }
     $nbt = new NBT(NBT::LITTLE_ENDIAN);
     $nbt->setData($this->getSpawnCompound());
     $pk = new TileEntityDataPacket();
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->namedtag = $nbt->write();
     $player->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     return \true;
 }
Ejemplo n.º 23
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = self::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->speedX = $this->motionX;
     $pk->speedY = $this->motionY;
     $pk->speedZ = $this->motionZ;
     $pk->yaw = $this->yaw;
     $pk->pitch = $this->pitch;
     $pk->metadata = $this->dataProperties;
     $player->dataPacket($pk);
     $pk = new ExplodePacket();
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->radius = 10;
     $pk->records = [];
     $player->dataPacket($pk);
     parent::spawnTo($player);
 }
Ejemplo n.º 24
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = Boat::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->speedX = 0;
     $pk->speedY = 0;
     $pk->speedZ = 0;
     $pk->yaw = 0;
     $pk->pitch = 0;
     $pk->metadata = $this->dataProperties;
     $player->dataPacket($pk);
     parent::spawnTo($player);
 }
Ejemplo n.º 25
0
 public function spawnTo(Player $player)
 {
     echo __METHOD__ . __LINE__ . "\n";
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = Minecart::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->did = 0;
     //$pk->speedX = $this->motionX;
     //$pk->speedY = $this->motionY;
     //$pk->speedZ = $this->motionZ;
     $player->dataPacket($pk);
     $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
     parent::spawnTo($player);
 }
Ejemplo n.º 26
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = Husk::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->speedX = $this->motionX;
     $pk->speedY = $this->motionY;
     $pk->speedZ = $this->motionZ;
     $pk->yaw = $this->yaw;
     $pk->pitch = $this->pitch;
     $pk->metadata = $this->dataProperties;
     $player->dataPacket($pk);
     Entity::spawnTo($player);
 }
Ejemplo n.º 27
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = self::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->speedX = $this->motionX;
     $pk->speedY = 1.5;
     $pk->speedZ = $this->motionZ;
     $pk->yaw = $this->yaw;
     $pk->pitch = $this->pitch;
     $pk->metadata = [Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $this->getDataProperty(2)], Entity::DATA_SHOW_NAMETAG => [Entity::DATA_TYPE_BYTE, 1], Entity::DATA_NO_AI => [Entity::DATA_TYPE_BYTE, 1]];
     $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
     parent::spawnTo($player);
 }
Ejemplo n.º 28
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = self::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->speedX = 0;
     $pk->speedY = 0;
     $pk->speedZ = 0;
     $pk->yaw = $this->yaw;
     $pk->pitch = $this->pitch;
     $pk->metadata = [2 => [4, $this->getDataProperty(2)], 3 => [0, $this->getDataProperty(3)], 15 => [0, 1]];
     $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
     parent::spawnTo($player);
 }
Ejemplo n.º 29
0
 public function spawnTo(Player $player)
 {
     $pk = new AddEntityPacket();
     $pk->eid = $this->getId();
     $pk->type = Mooshroom::NETWORK_ID;
     $pk->x = $this->x;
     $pk->y = $this->y + 2;
     $pk->z = $this->z;
     $pk->speedX = $this->motionX;
     $pk->speedY = $this->motionY;
     $pk->speedZ = $this->motionZ;
     $pk->yaw = $this->yaw;
     $pk->pitch = $this->pitch;
     $pk->metadata = $this->dataProperties;
     $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
     $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
     parent::spawnTo($player);
 }
 /**
  * Will transfer a connected player to another server.
  * This will trigger PlayerTransferEvent
  *
  * Player transfer might not be instant if you use a DNS address instead of an IP address
  *
  * @param Player $player
  * @param string $address
  * @param int    $port
  * @param string $message If null, ignore message
  *
  * @return bool
  */
 public function transferPlayer(Player $player, $address, $port = 19132, $message = "You are being transferred")
 {
     $ev = new PlayerTransferEvent($player, $address, $port, $message);
     $this->getServer()->getPluginManager()->callEvent($ev);
     if ($ev->isCancelled()) {
         return false;
     }
     $ip = $this->lookupAddress($ev->getAddress());
     if ($ip === null) {
         return false;
     }
     if ($message !== null and $message !== "") {
         $player->sendMessage($message);
     }
     $packet = new StrangePacket();
     $packet->address = $ip;
     $packet->port = $ev->getPort();
     $player->dataPacket($packet->setChannel(Network::CHANNEL_PRIORITY));
     return true;
 }