pocketmine\Player::directDataPacket PHP Method

directDataPacket() public method

public directDataPacket ( DataPacket $packet, boolean $needACK = false ) : boolean | integer
$packet pocketmine\network\protocol\DataPacket
$needACK boolean
return boolean | integer
    public function directDataPacket(DataPacket $packet, $needACK = false)
    {
        if ($this->connected === false) {
            return false;
        }
        $timings = Timings::getSendDataPacketTimings($packet);
        $timings->startTiming();
        $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
        if ($ev->isCancelled()) {
            $timings->stopTiming();
            return false;
        }
        $identifier = $this->interface->putPacket($this, $packet, $needACK, true);
        if ($needACK and $identifier !== null) {
            $this->needACK[$identifier] = false;
            $timings->stopTiming();
            return $identifier;
        }
        $timings->stopTiming();
        return true;
    }

Usage Example

Exemplo n.º 1
0
 public static function openChest(Block $chest, Player $player)
 {
     if ($chest->getId() === Item::CHEST) {
         if ($player->gamemode === Player::CREATIVE) {
             $player->sendMessage("[HG] You are in creative Mode");
             return;
         }
         if (!$player->isOp()) {
             $pk = new ContainerOpenPacket();
             $pk->windowid = $player->getWindowId($player->getInventory());
             $pk->type = InventoryType::CHEST;
             $pk->slots = $player->getInventory()->getSize();
             $pk->x = $chest->x;
             $pk->y = $chest->y;
             $pk->z = $chest->z;
             $pk->encode();
             $player->directDataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
             if ($player->getInventory() != null) {
                 $player->getInventory()->sendContents($player);
             }
             $player->sendTip("chest open!");
         }
     }
 }
All Usage Examples Of pocketmine\Player::directDataPacket
Player