From e4000f8f03684527d65a903dacd5620a695847a1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 9 Oct 2017 09:35:31 +0100 Subject: [PATCH] Reorganise some packet methods in Player --- src/pocketmine/Player.php | 166 +++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 9f7125951..1bedce0ab 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1092,89 +1092,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } - /** - * Batch a Data packet into the channel list to send at the end of the tick - * - * @param DataPacket $packet - * - * @return bool - */ - public function batchDataPacket(DataPacket $packet) : bool{ - if(!$this->isConnected()){ - return false; - } - - $timings = Timings::getSendDataPacketTimings($packet); - $timings->startTiming(); - $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet)); - if($ev->isCancelled()){ - $timings->stopTiming(); - return false; - } - - $this->batchedPackets[] = clone $packet; - $timings->stopTiming(); - return true; - } - - /** - * @param DataPacket $packet - * @param bool $needACK - * - * @return bool|int - */ - public function dataPacket(DataPacket $packet, bool $needACK = false){ - return $this->sendDataPacket($packet, $needACK, false); - } - - /** - * @param DataPacket $packet - * @param bool $needACK - * - * @return bool|int - */ - public function directDataPacket(DataPacket $packet, bool $needACK = false){ - return $this->sendDataPacket($packet, $needACK, true); - } - - /** - * @param DataPacket $packet - * @param bool $needACK - * @param bool $immediate - * - * @return bool|int - */ - public function sendDataPacket(DataPacket $packet, bool $needACK = false, bool $immediate = false){ - if(!$this->isConnected()){ - return false; - } - - //Basic safety restriction. TODO: improve this - if(!$this->loggedIn and !$packet->canBeSentBeforeLogin()){ - throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getName() . " too early"); - } - - $timings = Timings::getSendDataPacketTimings($packet); - $timings->startTiming(); - try{ - $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet)); - if($ev->isCancelled()){ - return false; - } - - $identifier = $this->interface->putPacket($this, $packet, $needACK, $immediate); - - if($needACK and $identifier !== null){ - $this->needACK[$identifier] = false; - return $identifier; - } - - return true; - }finally{ - $timings->stopTiming(); - } - } - /** * @param Vector3 $pos * @@ -3118,6 +3035,89 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } + /** + * Batch a Data packet into the channel list to send at the end of the tick + * + * @param DataPacket $packet + * + * @return bool + */ + public function batchDataPacket(DataPacket $packet) : bool{ + if(!$this->isConnected()){ + return false; + } + + $timings = Timings::getSendDataPacketTimings($packet); + $timings->startTiming(); + $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet)); + if($ev->isCancelled()){ + $timings->stopTiming(); + return false; + } + + $this->batchedPackets[] = clone $packet; + $timings->stopTiming(); + return true; + } + + /** + * @param DataPacket $packet + * @param bool $needACK + * @param bool $immediate + * + * @return bool|int + */ + public function sendDataPacket(DataPacket $packet, bool $needACK = false, bool $immediate = false){ + if(!$this->isConnected()){ + return false; + } + + //Basic safety restriction. TODO: improve this + if(!$this->loggedIn and !$packet->canBeSentBeforeLogin()){ + throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getName() . " too early"); + } + + $timings = Timings::getSendDataPacketTimings($packet); + $timings->startTiming(); + try{ + $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet)); + if($ev->isCancelled()){ + return false; + } + + $identifier = $this->interface->putPacket($this, $packet, $needACK, $immediate); + + if($needACK and $identifier !== null){ + $this->needACK[$identifier] = false; + return $identifier; + } + + return true; + }finally{ + $timings->stopTiming(); + } + } + + /** + * @param DataPacket $packet + * @param bool $needACK + * + * @return bool|int + */ + public function dataPacket(DataPacket $packet, bool $needACK = false){ + return $this->sendDataPacket($packet, $needACK, false); + } + + /** + * @param DataPacket $packet + * @param bool $needACK + * + * @return bool|int + */ + public function directDataPacket(DataPacket $packet, bool $needACK = false){ + return $this->sendDataPacket($packet, $needACK, true); + } + /** * Transfers a player to another server. *