diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index f46cbd74b9..ec520ad1c0 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1047,43 +1047,13 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } /** - * Sends an ordered DataPacket to the send buffer - * * @param DataPacket $packet * @param bool $needACK * * @return bool|int */ public function dataPacket(DataPacket $packet, bool $needACK = false){ - if(!$this->connected){ - 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(); - - $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet)); - if($ev->isCancelled()){ - $timings->stopTiming(); - return false; - } - - $identifier = $this->interface->putPacket($this, $packet, $needACK, false); - - if($needACK and $identifier !== null){ - $this->needACK[$identifier] = false; - - $timings->stopTiming(); - return $identifier; - } - - $timings->stopTiming(); - return true; + return $this->sendDataPacket($packet, $needACK, false); } /** @@ -1093,6 +1063,17 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @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->connected === false){ return false; } @@ -1110,7 +1091,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return false; } - $identifier = $this->interface->putPacket($this, $packet, $needACK, true); + $identifier = $this->interface->putPacket($this, $packet, $needACK, $immediate); if($needACK and $identifier !== null){ $this->needACK[$identifier] = false;