Merge branch 'master' into mcpe-1.2

This commit is contained in:
Dylan K. Taylor 2017-08-18 08:29:40 +01:00
commit 09c53552c1
4 changed files with 23 additions and 42 deletions

View File

@ -1051,43 +1051,13 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
/** /**
* Sends an ordered DataPacket to the send buffer
*
* @param DataPacket $packet * @param DataPacket $packet
* @param bool $needACK * @param bool $needACK
* *
* @return bool|int * @return bool|int
*/ */
public function dataPacket(DataPacket $packet, bool $needACK = false){ public function dataPacket(DataPacket $packet, bool $needACK = false){
if(!$this->connected){ return $this->sendDataPacket($packet, $needACK, false);
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;
} }
/** /**
@ -1097,6 +1067,17 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* @return bool|int * @return bool|int
*/ */
public function directDataPacket(DataPacket $packet, bool $needACK = false){ 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){ if($this->connected === false){
return false; return false;
} }
@ -1114,7 +1095,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return false; return false;
} }
$identifier = $this->interface->putPacket($this, $packet, $needACK, true); $identifier = $this->interface->putPacket($this, $packet, $needACK, $immediate);
if($needACK and $identifier !== null){ if($needACK and $identifier !== null){
$this->needACK[$identifier] = false; $this->needACK[$identifier] = false;

View File

@ -119,9 +119,9 @@ interface ChunkManager{
public function getChunk(int $chunkX, int $chunkZ); public function getChunk(int $chunkX, int $chunkZ);
/** /**
* @param int $chunkX * @param int $chunkX
* @param int $chunkZ * @param int $chunkZ
* @param Chunk $chunk * @param Chunk|null $chunk
*/ */
public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk = null); public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk = null);

View File

@ -2263,10 +2263,10 @@ class Level implements ChunkManager, Metadatable{
} }
/** /**
* @param int $chunkX * @param int $chunkX
* @param int $chunkZ * @param int $chunkZ
* @param Chunk $chunk * @param Chunk|null $chunk
* @param bool $unload * @param bool $unload
*/ */
public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk = null, bool $unload = true){ public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk = null, bool $unload = true){
if($chunk === null){ if($chunk === null){

View File

@ -143,9 +143,9 @@ class SimpleChunkManager implements ChunkManager{
} }
/** /**
* @param int $chunkX * @param int $chunkX
* @param int $chunkZ * @param int $chunkZ
* @param Chunk $chunk * @param Chunk|null $chunk
*/ */
public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk = null){ public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk = null){
if($chunk === null){ if($chunk === null){