Force-close the inventory window when crafting fails to avoid desync issues

mojang, why does this have to be hard work
This commit is contained in:
Dylan K. Taylor
2017-10-03 11:04:21 +01:00
parent 76117e7fa0
commit 9bbebaa071
3 changed files with 31 additions and 17 deletions

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine\inventory;
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
use pocketmine\network\mcpe\protocol\types\ContainerIds;
use pocketmine\Player;
class CraftingGrid extends BaseInventory{
@ -48,6 +50,20 @@ class CraftingGrid extends BaseInventory{
}
public function sendContents($target) : void{
//we can't send the contents of a client-sided inventory window
if(!is_array($target)){
$target = [$target];
}
/*
* TODO: HACK!
* we can't resend the contents of this window, so we force the client to close it instead.
* So people don't whine about messy desync issues when someone cancels CraftItemEvent, or when a crafting
* transaction goes wrong.
*/
$pk = new ContainerClosePacket();
$pk->windowId = ContainerIds::NONE;
foreach($target as $player){
$player->dataPacket($pk);
}
}
}