diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..993b80367 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: +- package-ecosystem: composer + directory: "/" + schedule: + interval: daily + time: "10:00" + open-pull-requests-limit: 10 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3d0f57287..7e4837157 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: image: [ubuntu-20.04] - php: [7.4.16] + php: [7.4.18] steps: - uses: actions/checkout@v2 #needed for build.sh @@ -37,7 +37,7 @@ jobs: fail-fast: false matrix: image: [ubuntu-20.04] - php: [7.4.16] + php: [7.4.18] steps: - uses: actions/checkout@v2 @@ -87,7 +87,7 @@ jobs: fail-fast: false matrix: image: [ubuntu-20.04] - php: [7.4.16] + php: [7.4.18] steps: - uses: actions/checkout@v2 @@ -139,7 +139,7 @@ jobs: fail-fast: false matrix: image: [ubuntu-20.04] - php: [7.4.16] + php: [7.4.18] steps: - uses: actions/checkout@v2 @@ -191,7 +191,7 @@ jobs: fail-fast: false matrix: image: [ubuntu-20.04] - php: [7.4.16] + php: [7.4.18] steps: - uses: actions/checkout@v2 @@ -280,4 +280,4 @@ jobs: tools: 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 diff --git a/.github/workflows/update-php-versions.php b/.github/workflows/update-php-versions.php new file mode 100644 index 000000000..8b24812c8 --- /dev/null +++ b/.github/workflows/update-php-versions.php @@ -0,0 +1,51 @@ +notContains('#ifndef COMPILE') //preprocessor will break if these are changed ->notName('PocketMine.php'); -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config) ->setRiskyAllowed(true) ->setRules([ 'align_multiline_comment' => [ diff --git a/composer.json b/composer.json index ee45b2a7f..096638c97 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "respect/validation": "^2.0" }, "require-dev": { - "phpstan/phpstan": "0.12.84", + "phpstan/phpstan": "0.12.85", "phpstan/phpstan-phpunit": "^0.12.6", "phpstan/phpstan-strict-rules": "^0.12.2", "phpunit/phpunit": "^9.2" diff --git a/composer.lock b/composer.lock index 018752547..83adc0a69 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "74d082e62d264fb0579bf4da87ab6eaf", + "content-hash": "6bd8f2ec899a5899fb8196fbd0fff82f", "packages": [ { "name": "adhocore/json-comment", @@ -1793,16 +1793,16 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.84", + "version": "0.12.85", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "9c43f15da8798c8f30a4b099e6a94530a558cfd5" + "reference": "20e6333c0067875ad7697cd8acdf245c6ef69d03" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/9c43f15da8798c8f30a4b099e6a94530a558cfd5", - "reference": "9c43f15da8798c8f30a4b099e6a94530a558cfd5", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/20e6333c0067875ad7697cd8acdf245c6ef69d03", + "reference": "20e6333c0067875ad7697cd8acdf245c6ef69d03", "shasum": "" }, "require": { @@ -1833,7 +1833,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "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": [ { @@ -1849,7 +1849,7 @@ "type": "tidelift" } ], - "time": "2021-04-19T17:10:54+00:00" + "time": "2021-04-27T14:13:16+00:00" }, { "name": "phpstan/phpstan-phpunit", diff --git a/src/block/BaseSign.php b/src/block/BaseSign.php index 1709e4a8a..3e047c2bd 100644 --- a/src/block/BaseSign.php +++ b/src/block/BaseSign.php @@ -26,9 +26,12 @@ namespace pocketmine\block; use pocketmine\block\tile\Sign as TileSign; use pocketmine\block\utils\SignText; use pocketmine\event\block\SignChangeEvent; +use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\utils\TextFormat; +use pocketmine\world\BlockTransaction; use function array_map; use function assert; use function strlen; @@ -39,6 +42,9 @@ abstract class BaseSign extends Transparent{ /** @var SignText */ protected $text; + /** @var int|null */ + protected $editorEntityRuntimeId = null; + public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){ parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.0, BlockToolType::AXE)); $this->text = new SignText(); @@ -49,6 +55,7 @@ abstract class BaseSign extends Transparent{ $tile = $this->pos->getWorld()->getTile($this->pos); if($tile instanceof TileSign){ $this->text = $tile->getText(); + $this->editorEntityRuntimeId = $tile->getEditorEntityRuntimeId(); } } @@ -57,6 +64,7 @@ abstract class BaseSign extends Transparent{ $tile = $this->pos->getWorld()->getTile($this->pos); assert($tile instanceof TileSign); $tile->setText($this->text); + $tile->setEditorEntityRuntimeId($this->editorEntityRuntimeId); } 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. */ @@ -108,6 +123,9 @@ abstract class BaseSign extends Transparent{ $ev = new SignChangeEvent($this, $author, new SignText(array_map(function(string $line) : string{ return TextFormat::clean($line, false); }, $text->getLines()))); + if($this->editorEntityRuntimeId === null || $this->editorEntityRuntimeId !== $author->getId()){ + $ev->cancel(); + } $ev->call(); if(!$ev->isCancelled()){ $this->setText($ev->getNewText()); diff --git a/src/block/tile/Sign.php b/src/block/tile/Sign.php index 8701d4a0b..38cad085f 100644 --- a/src/block/tile/Sign.php +++ b/src/block/tile/Sign.php @@ -53,6 +53,9 @@ class Sign extends Spawnable{ /** @var SignText */ protected $text; + /** @var int|null */ + protected $editorEntityRuntimeId = null; + public function __construct(World $world, Vector3 $pos){ $this->text = new SignText(); parent::__construct($world, $pos); @@ -90,6 +93,22 @@ class Sign extends Spawnable{ $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{ $nbt->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text->getLines())); } diff --git a/src/network/mcpe/protocol/types/inventory/UseItemOnEntityTransactionData.php b/src/network/mcpe/protocol/types/inventory/UseItemOnEntityTransactionData.php index 9b9de7c1e..857df5e60 100644 --- a/src/network/mcpe/protocol/types/inventory/UseItemOnEntityTransactionData.php +++ b/src/network/mcpe/protocol/types/inventory/UseItemOnEntityTransactionData.php @@ -30,6 +30,7 @@ use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; class UseItemOnEntityTransactionData extends TransactionData{ public const ACTION_INTERACT = 0; public const ACTION_ATTACK = 1; + public const ACTION_ITEM_INTERACT = 2; /** @var int */ private $entityRuntimeId;