Merge branch 'stable'

This commit is contained in:
Dylan K. Taylor 2021-02-04 15:55:39 +00:00
commit 4b9639f6c9
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
4 changed files with 94 additions and 9 deletions

View File

@ -0,0 +1,59 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types\inventory\stackrequest;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
/**
* Renames an item in an anvil, or map on a cartography table.
*/
final class CraftRecipeOptionalStackRequestAction extends ItemStackRequestAction{
/** @var int */
private $recipeId;
/** @var int */
private $filterStringIndex;
public function __construct(int $type, int $filterStringIndex){
$this->recipeId = $type;
$this->filterStringIndex = $filterStringIndex;
}
public function getRecipeId() : int{ return $this->recipeId; }
public function getFilterStringIndex() : int{ return $this->filterStringIndex; }
public static function getTypeId() : int{ return ItemStackRequestActionType::CRAFTING_RECIPE_OPTIONAL; }
public static function read(PacketSerializer $in) : self{
$recipeId = $in->readGenericTypeNetworkId();
$filterStringIndex = $in->getLInt();
return new self($recipeId, $filterStringIndex);
}
public function write(PacketSerializer $out) : void{
$out->writeGenericTypeNetworkId($this->recipeId);
$out->putLInt($this->filterStringIndex);
}
}

View File

@ -32,13 +32,21 @@ final class ItemStackRequest{
private $requestId;
/** @var ItemStackRequestAction[] */
private $actions;
/**
* @var string[]
* @phpstan-var list<string>
*/
private $filterStrings;
/**
* @param ItemStackRequestAction[] $actions
* @param string[] $filterStrings
* @phpstan-param list<string> $filterStrings
*/
public function __construct(int $requestId, array $actions){
public function __construct(int $requestId, array $actions, array $filterStrings){
$this->requestId = $requestId;
$this->actions = $actions;
$this->filterStrings = $filterStrings;
}
public function getRequestId() : int{ return $this->requestId; }
@ -46,6 +54,11 @@ final class ItemStackRequest{
/** @return ItemStackRequestAction[] */
public function getActions() : array{ return $this->actions; }
/**
* @return string[]
* @phpstan-return list<string>
*/
public function getFilterStrings() : array{ return $this->filterStrings; }
private static function readAction(PacketSerializer $in, int $typeId) : ItemStackRequestAction{
switch($typeId){
case TakeStackRequestAction::getTypeId(): return TakeStackRequestAction::read($in);
@ -60,6 +73,7 @@ final class ItemStackRequest{
case CraftRecipeStackRequestAction::getTypeId(): return CraftRecipeStackRequestAction::read($in);
case CraftRecipeAutoStackRequestAction::getTypeId(): return CraftRecipeAutoStackRequestAction::read($in);
case CreativeCreateStackRequestAction::getTypeId(): return CreativeCreateStackRequestAction::read($in);
case CraftRecipeOptionalStackRequestAction::getTypeId(): return CraftRecipeOptionalStackRequestAction::read($in);
case DeprecatedCraftingNonImplementedStackRequestAction::getTypeId(): return DeprecatedCraftingNonImplementedStackRequestAction::read($in);
case DeprecatedCraftingResultsStackRequestAction::getTypeId(): return DeprecatedCraftingResultsStackRequestAction::read($in);
}
@ -73,7 +87,11 @@ final class ItemStackRequest{
$typeId = $in->getByte();
$actions[] = self::readAction($in, $typeId);
}
return new self($requestId, $actions);
$filterStrings = [];
for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){
$filterStrings[] = $in->getString();
}
return new self($requestId, $actions, $filterStrings);
}
public function write(PacketSerializer $out) : void{
@ -83,5 +101,9 @@ final class ItemStackRequest{
$out->putByte($action::getTypeId());
$action->write($out);
}
$out->putUnsignedVarInt(count($this->filterStrings));
foreach($this->filterStrings as $string){
$out->putString($string);
}
}
}

View File

@ -41,6 +41,7 @@ final class ItemStackRequestActionType{
public const CRAFTING_RECIPE = 9;
public const CRAFTING_RECIPE_AUTO = 10; //recipe book?
public const CREATIVE_CREATE = 11;
public const CRAFTING_NON_IMPLEMENTED_DEPRECATED_ASK_TY_LAING = 12; //anvils aren't fully implemented yet
public const CRAFTING_RESULTS_DEPRECATED_ASK_TY_LAING = 13; //no idea what this is for
public const CRAFTING_RECIPE_OPTIONAL = 12; //anvil/cartography table rename
public const CRAFTING_NON_IMPLEMENTED_DEPRECATED_ASK_TY_LAING = 13;
public const CRAFTING_RESULTS_DEPRECATED_ASK_TY_LAING = 14; //no idea what this is for
}

View File

@ -255,6 +255,7 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{
}
$this->logStream[] = $time->format("Y-m-d") . " " . TextFormat::clean($message) . PHP_EOL;
$this->notify();
});
}
@ -278,10 +279,12 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{
fwrite($logResource, $chunk);
}
if($this->syncFlush){
$this->syncFlush = false;
$this->notify(); //if this was due to a sync flush, tell the caller to stop waiting
}
$this->synchronized(function() : void{
if($this->syncFlush){
$this->syncFlush = false;
$this->notify(); //if this was due to a sync flush, tell the caller to stop waiting
}
});
}
public function run() : void{
@ -293,7 +296,7 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{
while(!$this->shutdown){
$this->writeLogStream($logResource);
$this->synchronized(function() : void{
$this->wait(25000);
$this->wait();
});
}