SetDifficultyPacket: added create()

This commit is contained in:
Dylan K. Taylor 2019-06-25 18:34:12 +01:00
parent ec25a71396
commit 6bbae4b2df
2 changed files with 7 additions and 2 deletions

View File

@ -34,6 +34,12 @@ class SetDifficultyPacket extends DataPacket implements ClientboundPacket, Serve
/** @var int */
public $difficulty;
public static function create(int $difficulty) : self{
$result = new self;
$result->difficulty = $difficulty;
return $result;
}
protected function decodePayload() : void{
$this->difficulty = $this->getUnsignedVarInt();
}

View File

@ -2772,8 +2772,7 @@ class World implements ChunkManager, Metadatable{
* @param Player ...$targets
*/
public function sendDifficulty(Player ...$targets){
$pk = new SetDifficultyPacket();
$pk->difficulty = $this->getDifficulty();
$pk = SetDifficultyPacket::create($this->getDifficulty());
if(empty($targets)){
$this->broadcastGlobalPacket($pk);
}else{