Merge remote-tracking branch 'origin/stable'

This commit is contained in:
Dylan K. Taylor 2021-05-05 11:14:01 +01:00
commit 4ca5558ec1
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
10 changed files with 113 additions and 15 deletions

8
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
time: "10:00"
open-pull-requests-limit: 10

View File

@ -13,7 +13,7 @@ jobs:
strategy: strategy:
matrix: matrix:
image: [ubuntu-20.04] image: [ubuntu-20.04]
php: [7.4.16] php: [7.4.18]
steps: steps:
- uses: actions/checkout@v2 #needed for build.sh - uses: actions/checkout@v2 #needed for build.sh
@ -37,7 +37,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
image: [ubuntu-20.04] image: [ubuntu-20.04]
php: [7.4.16] php: [7.4.18]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -87,7 +87,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
image: [ubuntu-20.04] image: [ubuntu-20.04]
php: [7.4.16] php: [7.4.18]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -139,7 +139,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
image: [ubuntu-20.04] image: [ubuntu-20.04]
php: [7.4.16] php: [7.4.18]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -191,7 +191,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
image: [ubuntu-20.04] image: [ubuntu-20.04]
php: [7.4.16] php: [7.4.18]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -280,4 +280,4 @@ jobs:
tools: php-cs-fixer tools: php-cs-fixer
- name: Run PHP-CS-Fixer - name: Run PHP-CS-Fixer
run: php-cs-fixer fix --dry-run --diff --diff-format=udiff run: php-cs-fixer fix --dry-run --diff

View File

@ -0,0 +1,51 @@
<?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);
const VERSIONS = [
"7.3",
"7.4",
"8.0"
];
$workflowFile = file_get_contents(__DIR__ . '/main.yml');
$newWorkflowFile = $workflowFile;
foreach(VERSIONS as $v){
$releaseInfo = file_get_contents("https://secure.php.net/releases?json&version=$v");
if($releaseInfo === false){
throw new \RuntimeException("Failed to contact php.net API");
}
$data = json_decode($releaseInfo, true);
if(!is_array($data) || !isset($data["version"]) || !is_string($data["version"]) || preg_match('/^\d+\.\d+\.\d+(-[A-Za-z\d]+)?$/', $data["version"]) === 0){
throw new \RuntimeException("Invalid data returned by API");
}
$updated = preg_replace("/$v\.\d+/", $data["version"], $newWorkflowFile);
if($updated !== $newWorkflowFile){
echo "Updated $v revision to " . $data["version"] . "\n";
}
$newWorkflowFile = $updated;
}
if($workflowFile !== $newWorkflowFile){
echo "Writing modified workflow file\n";
file_put_contents(__DIR__ . '/main.yml', $newWorkflowFile);
}

1
.gitignore vendored
View File

@ -50,3 +50,4 @@ Documentation/*
# php-cs-fixer # php-cs-fixer
/.php_cs.cache /.php_cs.cache
/.php-cs-fixer.cache

View File

@ -9,7 +9,7 @@ $finder = PhpCsFixer\Finder::create()
->notContains('#ifndef COMPILE') //preprocessor will break if these are changed ->notContains('#ifndef COMPILE') //preprocessor will break if these are changed
->notName('PocketMine.php'); ->notName('PocketMine.php');
return PhpCsFixer\Config::create() return (new PhpCsFixer\Config)
->setRiskyAllowed(true) ->setRiskyAllowed(true)
->setRules([ ->setRules([
'align_multiline_comment' => [ 'align_multiline_comment' => [

View File

@ -50,7 +50,7 @@
"respect/validation": "^2.0" "respect/validation": "^2.0"
}, },
"require-dev": { "require-dev": {
"phpstan/phpstan": "0.12.84", "phpstan/phpstan": "0.12.85",
"phpstan/phpstan-phpunit": "^0.12.6", "phpstan/phpstan-phpunit": "^0.12.6",
"phpstan/phpstan-strict-rules": "^0.12.2", "phpstan/phpstan-strict-rules": "^0.12.2",
"phpunit/phpunit": "^9.2" "phpunit/phpunit": "^9.2"

14
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "74d082e62d264fb0579bf4da87ab6eaf", "content-hash": "6bd8f2ec899a5899fb8196fbd0fff82f",
"packages": [ "packages": [
{ {
"name": "adhocore/json-comment", "name": "adhocore/json-comment",
@ -1793,16 +1793,16 @@
}, },
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "0.12.84", "version": "0.12.85",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "9c43f15da8798c8f30a4b099e6a94530a558cfd5" "reference": "20e6333c0067875ad7697cd8acdf245c6ef69d03"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/9c43f15da8798c8f30a4b099e6a94530a558cfd5", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/20e6333c0067875ad7697cd8acdf245c6ef69d03",
"reference": "9c43f15da8798c8f30a4b099e6a94530a558cfd5", "reference": "20e6333c0067875ad7697cd8acdf245c6ef69d03",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1833,7 +1833,7 @@
"description": "PHPStan - PHP Static Analysis Tool", "description": "PHPStan - PHP Static Analysis Tool",
"support": { "support": {
"issues": "https://github.com/phpstan/phpstan/issues", "issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/0.12.84" "source": "https://github.com/phpstan/phpstan/tree/0.12.85"
}, },
"funding": [ "funding": [
{ {
@ -1849,7 +1849,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-04-19T17:10:54+00:00" "time": "2021-04-27T14:13:16+00:00"
}, },
{ {
"name": "phpstan/phpstan-phpunit", "name": "phpstan/phpstan-phpunit",

View File

@ -26,9 +26,12 @@ namespace pocketmine\block;
use pocketmine\block\tile\Sign as TileSign; use pocketmine\block\tile\Sign as TileSign;
use pocketmine\block\utils\SignText; use pocketmine\block\utils\SignText;
use pocketmine\event\block\SignChangeEvent; use pocketmine\event\block\SignChangeEvent;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
use pocketmine\world\BlockTransaction;
use function array_map; use function array_map;
use function assert; use function assert;
use function strlen; use function strlen;
@ -39,6 +42,9 @@ abstract class BaseSign extends Transparent{
/** @var SignText */ /** @var SignText */
protected $text; protected $text;
/** @var int|null */
protected $editorEntityRuntimeId = null;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){ public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.0, BlockToolType::AXE)); parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.0, BlockToolType::AXE));
$this->text = new SignText(); $this->text = new SignText();
@ -49,6 +55,7 @@ abstract class BaseSign extends Transparent{
$tile = $this->pos->getWorld()->getTile($this->pos); $tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileSign){ if($tile instanceof TileSign){
$this->text = $tile->getText(); $this->text = $tile->getText();
$this->editorEntityRuntimeId = $tile->getEditorEntityRuntimeId();
} }
} }
@ -57,6 +64,7 @@ abstract class BaseSign extends Transparent{
$tile = $this->pos->getWorld()->getTile($this->pos); $tile = $this->pos->getWorld()->getTile($this->pos);
assert($tile instanceof TileSign); assert($tile instanceof TileSign);
$tile->setText($this->text); $tile->setText($this->text);
$tile->setEditorEntityRuntimeId($this->editorEntityRuntimeId);
} }
public function isSolid() : bool{ public function isSolid() : bool{
@ -78,6 +86,13 @@ abstract class BaseSign extends Transparent{
} }
} }
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$this->editorEntityRuntimeId = $player->getId();
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
/** /**
* Returns an object containing information about the sign text. * Returns an object containing information about the sign text.
*/ */
@ -108,6 +123,9 @@ abstract class BaseSign extends Transparent{
$ev = new SignChangeEvent($this, $author, new SignText(array_map(function(string $line) : string{ $ev = new SignChangeEvent($this, $author, new SignText(array_map(function(string $line) : string{
return TextFormat::clean($line, false); return TextFormat::clean($line, false);
}, $text->getLines()))); }, $text->getLines())));
if($this->editorEntityRuntimeId === null || $this->editorEntityRuntimeId !== $author->getId()){
$ev->cancel();
}
$ev->call(); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->setText($ev->getNewText()); $this->setText($ev->getNewText());

View File

@ -53,6 +53,9 @@ class Sign extends Spawnable{
/** @var SignText */ /** @var SignText */
protected $text; protected $text;
/** @var int|null */
protected $editorEntityRuntimeId = null;
public function __construct(World $world, Vector3 $pos){ public function __construct(World $world, Vector3 $pos){
$this->text = new SignText(); $this->text = new SignText();
parent::__construct($world, $pos); parent::__construct($world, $pos);
@ -90,6 +93,22 @@ class Sign extends Spawnable{
$this->text = $text; $this->text = $text;
} }
/**
* Returns the entity runtime ID of the player who placed this sign. Only the player whose entity ID matches this
* one may edit the sign text.
* This is needed because as of 1.16.220, there is still no reliable way to detect when the MCPE client closed the
* sign edit GUI, so we have no way to know when the text is finalized. This limits editing of the text to only the
* player who placed it, and only while that player is online.
* We can say for sure that the sign is finalized if either of the following occurs:
* - The player quits (after rejoin, the player's entity runtimeID will be different).
* - The chunk is unloaded (on next load, the entity runtimeID will be null, because it's not saved).
*/
public function getEditorEntityRuntimeId() : ?int{ return $this->editorEntityRuntimeId; }
public function setEditorEntityRuntimeId(?int $editorEntityRuntimeId) : void{
$this->editorEntityRuntimeId = $editorEntityRuntimeId;
}
protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
$nbt->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text->getLines())); $nbt->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text->getLines()));
} }

View File

@ -30,6 +30,7 @@ use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
class UseItemOnEntityTransactionData extends TransactionData{ class UseItemOnEntityTransactionData extends TransactionData{
public const ACTION_INTERACT = 0; public const ACTION_INTERACT = 0;
public const ACTION_ATTACK = 1; public const ACTION_ATTACK = 1;
public const ACTION_ITEM_INTERACT = 2;
/** @var int */ /** @var int */
private $entityRuntimeId; private $entityRuntimeId;