From af4294295ba091204fa872b5f10a1d3f7220621d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 10:19:24 +0000 Subject: [PATCH 01/28] Bump symfony/filesystem from 6.4.7 to 6.4.9 Bumps [symfony/filesystem](https://github.com/symfony/filesystem) from 6.4.7 to 6.4.9. - [Release notes](https://github.com/symfony/filesystem/releases) - [Changelog](https://github.com/symfony/filesystem/blob/7.1/CHANGELOG.md) - [Commits](https://github.com/symfony/filesystem/compare/v6.4.7...v6.4.9) --- updated-dependencies: - dependency-name: symfony/filesystem dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 103 +++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 81 deletions(-) diff --git a/composer.lock b/composer.lock index b2f82093b96..9b9c517569d 100644 --- a/composer.lock +++ b/composer.lock @@ -926,23 +926,25 @@ }, { "name": "symfony/filesystem", - "version": "v6.4.7", + "version": "v6.4.9", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "78dde75f8f6dbbca4ec436a4b0087f7af02076d4" + "reference": "b51ef8059159330b74a4d52f68e671033c0fe463" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/78dde75f8f6dbbca4ec436a4b0087f7af02076d4", - "reference": "78dde75f8f6dbbca4ec436a4b0087f7af02076d4", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/b51ef8059159330b74a4d52f68e671033c0fe463", + "reference": "b51ef8059159330b74a4d52f68e671033c0fe463", "shasum": "" }, "require": { "php": ">=8.1", "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.8", - "symfony/process": "^5.4|^6.4" + "symfony/polyfill-mbstring": "~1.8" + }, + "require-dev": { + "symfony/process": "^5.4|^6.4|^7.0" }, "type": "library", "autoload": { @@ -970,7 +972,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v6.4.7" + "source": "https://github.com/symfony/filesystem/tree/v6.4.9" }, "funding": [ { @@ -986,20 +988,20 @@ "type": "tidelift" } ], - "time": "2024-04-18T09:22:46+00:00" + "time": "2024-06-28T09:49:33+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4" + "reference": "0424dff1c58f028c451efff2045f5d92410bd540" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4", - "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/0424dff1c58f028c451efff2045f5d92410bd540", + "reference": "0424dff1c58f028c451efff2045f5d92410bd540", "shasum": "" }, "require": { @@ -1049,7 +1051,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.30.0" }, "funding": [ { @@ -1065,20 +1067,20 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-05-31T15:07:36+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec" + "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec", - "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c", + "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c", "shasum": "" }, "require": { @@ -1129,68 +1131,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-01-29T20:11:03+00:00" - }, - { - "name": "symfony/process", - "version": "v6.4.7", - "source": { - "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "cdb1c81c145fd5aa9b0038bab694035020943381" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/cdb1c81c145fd5aa9b0038bab694035020943381", - "reference": "cdb1c81c145fd5aa9b0038bab694035020943381", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Process\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Executes commands in sub-processes", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/process/tree/v6.4.7" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0" }, "funding": [ { @@ -1206,7 +1147,7 @@ "type": "tidelift" } ], - "time": "2024-04-18T09:22:46+00:00" + "time": "2024-06-19T12:30:46+00:00" } ], "packages-dev": [ From 279f9bae1683548716df8d3d28907dd55ca38d17 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jul 2024 04:48:07 +0000 Subject: [PATCH 02/28] If player is more then 12 blocks from container close container window --- src/player/Player.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/player/Player.php b/src/player/Player.php index 0cefbe71f22..fc1b04974f8 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -28,6 +28,7 @@ use pocketmine\block\BlockTypeTags; use pocketmine\block\UnknownBlock; use pocketmine\block\VanillaBlocks; +use pocketmine\block\inventory\BlockInventory; use pocketmine\command\CommandSender; use pocketmine\crafting\CraftingGrid; use pocketmine\data\java\GameModeIdMap; @@ -182,6 +183,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ private const MAX_REACH_DISTANCE_CREATIVE = 13; private const MAX_REACH_DISTANCE_SURVIVAL = 7; private const MAX_REACH_DISTANCE_ENTITY_INTERACTION = 8; + private const MAX_DISTANCE_FROM_CONTAINER = 12; public const TAG_FIRST_PLAYED = "firstPlayed"; //TAG_Long public const TAG_LAST_PLAYED = "lastPlayed"; //TAG_Long @@ -296,6 +298,8 @@ public static function isValidUserName(?string $name) : bool{ protected ?SurvivalBlockBreakHandler $blockBreakHandler = null; + protected ?Vector3 $openContainerPosition = null; + public function __construct(Server $server, NetworkSession $session, PlayerInfo $playerInfo, bool $authenticated, Location $spawnLocation, ?CompoundTag $namedtag){ $username = TextFormat::clean($playerInfo->getUsername()); $this->logger = new \PrefixedLogger($server->getLogger(), "Player: $username"); @@ -1374,6 +1378,14 @@ protected function processMostRecentMovements() : void{ $this->logger->debug("Exceeded movement rate limit, forcing to last accepted position"); $this->sendPosition($this->location, $this->location->getYaw(), $this->location->getPitch(), MovePlayerPacket::MODE_RESET); } + + if ($this->openContainerPosition !== null) { + $distance = $this->location->distance($this->openContainerPosition); + + if ($distance > self::MAX_DISTANCE_FROM_CONTAINER) { + $this->removeCurrentWindow(); + } + } } protected function revertMovement(Location $from) : void{ @@ -2646,6 +2658,12 @@ public function setCurrentWindow(Inventory $inventory) : bool{ $inventoryManager->onCurrentWindowChange($inventory); $inventory->onOpen($this); $this->currentWindow = $inventory; + + if ($inventory instanceof BlockInventory) { + $block = $inventory->getHolder(); + $this->openContainerPosition = $block->asPosition(); + } + return true; } @@ -2661,6 +2679,8 @@ public function removeCurrentWindow() : void{ $this->currentWindow = null; (new InventoryCloseEvent($currentWindow, $this))->call(); } + + $this->openContainerPosition = null; } protected function addPermanentInventories(Inventory ...$inventories) : void{ From f24b96453e181f1b4671bac4fefb381860d8c596 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jul 2024 04:56:38 +0000 Subject: [PATCH 03/28] fix code style issues --- src/player/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/player/Player.php b/src/player/Player.php index fc1b04974f8..96a14a868f0 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -26,9 +26,9 @@ use pocketmine\block\BaseSign; use pocketmine\block\Bed; use pocketmine\block\BlockTypeTags; +use pocketmine\block\inventory\BlockInventory; use pocketmine\block\UnknownBlock; use pocketmine\block\VanillaBlocks; -use pocketmine\block\inventory\BlockInventory; use pocketmine\command\CommandSender; use pocketmine\crafting\CraftingGrid; use pocketmine\data\java\GameModeIdMap; From c58073cbc56a7494edeb3637e3e4e9775820e204 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jul 2024 15:11:28 +0000 Subject: [PATCH 04/28] hopefully fixes issue with composer.lock file being changed --- composer.lock | 105 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 82 insertions(+), 23 deletions(-) diff --git a/composer.lock b/composer.lock index 9b9c517569d..6a15c374cbd 100644 --- a/composer.lock +++ b/composer.lock @@ -926,25 +926,23 @@ }, { "name": "symfony/filesystem", - "version": "v6.4.9", + "version": "v6.4.7", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "b51ef8059159330b74a4d52f68e671033c0fe463" + "reference": "78dde75f8f6dbbca4ec436a4b0087f7af02076d4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/b51ef8059159330b74a4d52f68e671033c0fe463", - "reference": "b51ef8059159330b74a4d52f68e671033c0fe463", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/78dde75f8f6dbbca4ec436a4b0087f7af02076d4", + "reference": "78dde75f8f6dbbca4ec436a4b0087f7af02076d4", "shasum": "" }, "require": { "php": ">=8.1", "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.8" - }, - "require-dev": { - "symfony/process": "^5.4|^6.4|^7.0" + "symfony/polyfill-mbstring": "~1.8", + "symfony/process": "^5.4|^6.4" }, "type": "library", "autoload": { @@ -972,7 +970,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v6.4.9" + "source": "https://github.com/symfony/filesystem/tree/v6.4.7" }, "funding": [ { @@ -988,20 +986,20 @@ "type": "tidelift" } ], - "time": "2024-06-28T09:49:33+00:00" + "time": "2024-04-18T09:22:46+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.30.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "0424dff1c58f028c451efff2045f5d92410bd540" + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/0424dff1c58f028c451efff2045f5d92410bd540", - "reference": "0424dff1c58f028c451efff2045f5d92410bd540", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4", + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4", "shasum": "" }, "require": { @@ -1051,7 +1049,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0" }, "funding": [ { @@ -1067,20 +1065,20 @@ "type": "tidelift" } ], - "time": "2024-05-31T15:07:36+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.30.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c" + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c", - "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec", + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec", "shasum": "" }, "require": { @@ -1131,7 +1129,68 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-01-29T20:11:03+00:00" + }, + { + "name": "symfony/process", + "version": "v6.4.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "cdb1c81c145fd5aa9b0038bab694035020943381" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/cdb1c81c145fd5aa9b0038bab694035020943381", + "reference": "cdb1c81c145fd5aa9b0038bab694035020943381", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Executes commands in sub-processes", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/process/tree/v6.4.7" }, "funding": [ { @@ -1147,7 +1206,7 @@ "type": "tidelift" } ], - "time": "2024-06-19T12:30:46+00:00" + "time": "2024-04-18T09:22:46+00:00" } ], "packages-dev": [ @@ -2972,4 +3031,4 @@ "php": "8.1.0" }, "plugin-api-version": "2.6.0" -} +} \ No newline at end of file From 1a543723bdaaa0e7692578ace7c842ba41e35df9 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jul 2024 15:13:39 +0000 Subject: [PATCH 05/28] fixes changes to composer.lock --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index 6a15c374cbd..b2f82093b96 100644 --- a/composer.lock +++ b/composer.lock @@ -3031,4 +3031,4 @@ "php": "8.1.0" }, "plugin-api-version": "2.6.0" -} \ No newline at end of file +} From 3db436320d96f00d6ef2443ba5e5a27c4fddf45d Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jul 2024 15:18:54 +0000 Subject: [PATCH 06/28] change variable name to holder for consistency --- src/player/Player.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index 96a14a868f0..aa26c852c20 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -2660,8 +2660,8 @@ public function setCurrentWindow(Inventory $inventory) : bool{ $this->currentWindow = $inventory; if ($inventory instanceof BlockInventory) { - $block = $inventory->getHolder(); - $this->openContainerPosition = $block->asPosition(); + $holder = $inventory->getHolder(); + $this->openContainerPosition = $holder->asPosition(); } return true; From d28eb74166cad06c81681ae93b08489bd4cae26c Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jul 2024 19:11:38 +0000 Subject: [PATCH 07/28] add max distance to inventory interface --- src/inventory/Inventory.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/inventory/Inventory.php b/src/inventory/Inventory.php index 5c81d7d9c86..e5461f6a408 100644 --- a/src/inventory/Inventory.php +++ b/src/inventory/Inventory.php @@ -33,6 +33,8 @@ interface Inventory{ public const MAX_STACK = 64; + public const MAX_DISTANCE_FROM_CONTAINER = 6; + /** * Returns the number of slots in the inventory. */ From ca7c424a342b220e5e923109f6a00396f0524b70 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jul 2024 19:11:58 +0000 Subject: [PATCH 08/28] add properties and methods to override interface max distance --- src/inventory/BaseInventory.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/inventory/BaseInventory.php b/src/inventory/BaseInventory.php index 254e44b1ea0..99ccdd4f548 100644 --- a/src/inventory/BaseInventory.php +++ b/src/inventory/BaseInventory.php @@ -39,6 +39,9 @@ */ abstract class BaseInventory implements Inventory{ protected int $maxStackSize = Inventory::MAX_STACK; + + protected int $maxDistanceFromContainer = Inventory::MAX_DISTANCE_FROM_CONTAINER; + /** @var Player[] */ protected array $viewers = []; /** @@ -59,6 +62,14 @@ public function setMaxStackSize(int $size) : void{ $this->maxStackSize = $size; } + public function getMaxDistanceFromContainer(): int { + return $this->maxDistanceFromContainer; + } + + public function setMaxDistanceFromContainer(int $maxDistance): void { + $this->maxDistanceFromContainer = $maxDistance; + } + abstract protected function internalSetItem(int $index, Item $item) : void; public function setItem(int $index, Item $item) : void{ From cd9cc82775e8ecfa7ec987f057fb763480c4c8fc Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jul 2024 19:12:42 +0000 Subject: [PATCH 09/28] use max distance modifier from inventory class --- src/player/Player.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index aa26c852c20..725269d6e2c 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -83,9 +83,11 @@ use pocketmine\form\FormValidationException; use pocketmine\inventory\CallbackInventoryListener; use pocketmine\inventory\CreativeInventory; +use pocketmine\inventory\BaseInventory; use pocketmine\inventory\Inventory; use pocketmine\inventory\PlayerCraftingInventory; use pocketmine\inventory\PlayerCursorInventory; +use pocketmine\inventory\SimpleInventory; use pocketmine\inventory\TemporaryInventory; use pocketmine\inventory\transaction\action\DropItemAction; use pocketmine\inventory\transaction\InventoryTransaction; @@ -183,7 +185,6 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ private const MAX_REACH_DISTANCE_CREATIVE = 13; private const MAX_REACH_DISTANCE_SURVIVAL = 7; private const MAX_REACH_DISTANCE_ENTITY_INTERACTION = 8; - private const MAX_DISTANCE_FROM_CONTAINER = 12; public const TAG_FIRST_PLAYED = "firstPlayed"; //TAG_Long public const TAG_LAST_PLAYED = "lastPlayed"; //TAG_Long @@ -298,6 +299,7 @@ public static function isValidUserName(?string $name) : bool{ protected ?SurvivalBlockBreakHandler $blockBreakHandler = null; + protected ?SimpleInventory $openContainerInventory = null; protected ?Vector3 $openContainerPosition = null; public function __construct(Server $server, NetworkSession $session, PlayerInfo $playerInfo, bool $authenticated, Location $spawnLocation, ?CompoundTag $namedtag){ @@ -1379,10 +1381,10 @@ protected function processMostRecentMovements() : void{ $this->sendPosition($this->location, $this->location->getYaw(), $this->location->getPitch(), MovePlayerPacket::MODE_RESET); } - if ($this->openContainerPosition !== null) { + if ($this->openContainerPosition !== null && $this->openContainerInventory !== null) { $distance = $this->location->distance($this->openContainerPosition); - if ($distance > self::MAX_DISTANCE_FROM_CONTAINER) { + if ($distance > $this->openContainerInventory->getMaxDistanceFromContainer()) { $this->removeCurrentWindow(); } } @@ -2659,9 +2661,14 @@ public function setCurrentWindow(Inventory $inventory) : bool{ $inventory->onOpen($this); $this->currentWindow = $inventory; - if ($inventory instanceof BlockInventory) { - $holder = $inventory->getHolder(); - $this->openContainerPosition = $holder->asPosition(); + if ($inventory instanceof BaseInventory) { + if ($inventory->getMaxDistanceFromContainer() > 0) { + if ($inventory instanceof BlockInventory) { + $this->openContainerInventory = $inventory; + $holder = $inventory->getHolder(); + $this->openContainerPosition = $holder->asPosition(); + } + } } return true; @@ -2681,6 +2688,7 @@ public function removeCurrentWindow() : void{ } $this->openContainerPosition = null; + $this->openContainerInventory = null; } protected function addPermanentInventories(Inventory ...$inventories) : void{ From 25dee1018a41c450d500d034e987fd5c759d33c5 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jul 2024 19:17:23 +0000 Subject: [PATCH 10/28] Fix incorrect class check --- src/player/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/player/Player.php b/src/player/Player.php index 725269d6e2c..95e5ddd446b 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -2661,7 +2661,7 @@ public function setCurrentWindow(Inventory $inventory) : bool{ $inventory->onOpen($this); $this->currentWindow = $inventory; - if ($inventory instanceof BaseInventory) { + if ($inventory instanceof SimpleInventory) { if ($inventory->getMaxDistanceFromContainer() > 0) { if ($inventory instanceof BlockInventory) { $this->openContainerInventory = $inventory; From 841cc216f0641adb8a520474c164d4dbf0e3bbda Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jul 2024 19:20:19 +0000 Subject: [PATCH 11/28] code style fixes --- src/inventory/BaseInventory.php | 4 ++-- src/player/Player.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/inventory/BaseInventory.php b/src/inventory/BaseInventory.php index 99ccdd4f548..dad5b4bdd49 100644 --- a/src/inventory/BaseInventory.php +++ b/src/inventory/BaseInventory.php @@ -62,11 +62,11 @@ public function setMaxStackSize(int $size) : void{ $this->maxStackSize = $size; } - public function getMaxDistanceFromContainer(): int { + public function getMaxDistanceFromContainer() : int { return $this->maxDistanceFromContainer; } - public function setMaxDistanceFromContainer(int $maxDistance): void { + public function setMaxDistanceFromContainer(int $maxDistance) : void { $this->maxDistanceFromContainer = $maxDistance; } diff --git a/src/player/Player.php b/src/player/Player.php index 95e5ddd446b..1e5da1a3ceb 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -83,7 +83,6 @@ use pocketmine\form\FormValidationException; use pocketmine\inventory\CallbackInventoryListener; use pocketmine\inventory\CreativeInventory; -use pocketmine\inventory\BaseInventory; use pocketmine\inventory\Inventory; use pocketmine\inventory\PlayerCraftingInventory; use pocketmine\inventory\PlayerCursorInventory; From 42dc7da2b18f9286e4d0c4c337a7dc4a11e40805 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 5 Jul 2024 02:19:18 +0000 Subject: [PATCH 12/28] Create new interface for proximity restrictions --- src/block/ProximityRestricted.php | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/block/ProximityRestricted.php diff --git a/src/block/ProximityRestricted.php b/src/block/ProximityRestricted.php new file mode 100644 index 00000000000..d69d7c8bf52 --- /dev/null +++ b/src/block/ProximityRestricted.php @@ -0,0 +1,39 @@ + Date: Fri, 5 Jul 2024 02:19:47 +0000 Subject: [PATCH 13/28] update code to use ProximityRestricted interface --- src/inventory/BaseInventory.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/inventory/BaseInventory.php b/src/inventory/BaseInventory.php index dad5b4bdd49..573ea962efb 100644 --- a/src/inventory/BaseInventory.php +++ b/src/inventory/BaseInventory.php @@ -23,6 +23,7 @@ namespace pocketmine\inventory; +use pocketmine\block\ProximityRestricted; use pocketmine\item\Item; use pocketmine\item\VanillaItems; use pocketmine\player\Player; @@ -37,10 +38,10 @@ /** * This class provides everything needed to implement an inventory, minus the underlying storage system. */ -abstract class BaseInventory implements Inventory{ +abstract class BaseInventory implements Inventory, ProximityRestricted{ protected int $maxStackSize = Inventory::MAX_STACK; - protected int $maxDistanceFromContainer = Inventory::MAX_DISTANCE_FROM_CONTAINER; + protected int $maxDistanceFromContainer = ProximityRestricted::MAX_DISTANCE; /** @var Player[] */ protected array $viewers = []; @@ -62,11 +63,11 @@ public function setMaxStackSize(int $size) : void{ $this->maxStackSize = $size; } - public function getMaxDistanceFromContainer() : int { + public function getMaxDistance() : int { return $this->maxDistanceFromContainer; } - public function setMaxDistanceFromContainer(int $maxDistance) : void { + public function setMaxDistance(int $maxDistance) : void { $this->maxDistanceFromContainer = $maxDistance; } From cd9c7da7d02d40a33d878522baff531e5d2d97b2 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 5 Jul 2024 02:19:56 +0000 Subject: [PATCH 14/28] remove old code --- src/inventory/Inventory.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/inventory/Inventory.php b/src/inventory/Inventory.php index e5461f6a408..5c81d7d9c86 100644 --- a/src/inventory/Inventory.php +++ b/src/inventory/Inventory.php @@ -33,8 +33,6 @@ interface Inventory{ public const MAX_STACK = 64; - public const MAX_DISTANCE_FROM_CONTAINER = 6; - /** * Returns the number of slots in the inventory. */ From de1b7c38858e9ea9c00bdbf3ca50f6385c7c5f38 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 5 Jul 2024 02:20:19 +0000 Subject: [PATCH 15/28] updated based on new interface --- src/player/Player.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index 1e5da1a3ceb..e2eae863c16 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -27,6 +27,7 @@ use pocketmine\block\Bed; use pocketmine\block\BlockTypeTags; use pocketmine\block\inventory\BlockInventory; +use pocketmine\block\ProximityRestricted; use pocketmine\block\UnknownBlock; use pocketmine\block\VanillaBlocks; use pocketmine\command\CommandSender; @@ -298,7 +299,6 @@ public static function isValidUserName(?string $name) : bool{ protected ?SurvivalBlockBreakHandler $blockBreakHandler = null; - protected ?SimpleInventory $openContainerInventory = null; protected ?Vector3 $openContainerPosition = null; public function __construct(Server $server, NetworkSession $session, PlayerInfo $playerInfo, bool $authenticated, Location $spawnLocation, ?CompoundTag $namedtag){ @@ -1380,10 +1380,10 @@ protected function processMostRecentMovements() : void{ $this->sendPosition($this->location, $this->location->getYaw(), $this->location->getPitch(), MovePlayerPacket::MODE_RESET); } - if ($this->openContainerPosition !== null && $this->openContainerInventory !== null) { + if ($this->openContainerPosition !== null && $this->currentWindow !== null) { $distance = $this->location->distance($this->openContainerPosition); - if ($distance > $this->openContainerInventory->getMaxDistanceFromContainer()) { + if ($distance > $this->currentWindow->getMaxDistanceFromContainer()) { $this->removeCurrentWindow(); } } @@ -2660,10 +2660,9 @@ public function setCurrentWindow(Inventory $inventory) : bool{ $inventory->onOpen($this); $this->currentWindow = $inventory; - if ($inventory instanceof SimpleInventory) { - if ($inventory->getMaxDistanceFromContainer() > 0) { + if ($inventory instanceof ProximityResticted) { + if ($inventory->getMaxDistance() > 0) { if ($inventory instanceof BlockInventory) { - $this->openContainerInventory = $inventory; $holder = $inventory->getHolder(); $this->openContainerPosition = $holder->asPosition(); } @@ -2687,7 +2686,6 @@ public function removeCurrentWindow() : void{ } $this->openContainerPosition = null; - $this->openContainerInventory = null; } protected function addPermanentInventories(Inventory ...$inventories) : void{ From fccdb19c3d59432c60ccd0a9e15a213598ba8772 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 5 Jul 2024 02:22:13 +0000 Subject: [PATCH 16/28] remove unused code --- src/player/Player.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index e2eae863c16..692096b38db 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -27,7 +27,6 @@ use pocketmine\block\Bed; use pocketmine\block\BlockTypeTags; use pocketmine\block\inventory\BlockInventory; -use pocketmine\block\ProximityRestricted; use pocketmine\block\UnknownBlock; use pocketmine\block\VanillaBlocks; use pocketmine\command\CommandSender; @@ -87,7 +86,6 @@ use pocketmine\inventory\Inventory; use pocketmine\inventory\PlayerCraftingInventory; use pocketmine\inventory\PlayerCursorInventory; -use pocketmine\inventory\SimpleInventory; use pocketmine\inventory\TemporaryInventory; use pocketmine\inventory\transaction\action\DropItemAction; use pocketmine\inventory\transaction\InventoryTransaction; From 5e33cad3bc4564031fddd468314e7c6bfbd9eadc Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 5 Jul 2024 03:29:49 +0000 Subject: [PATCH 17/28] correct function name --- src/player/Player.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/player/Player.php b/src/player/Player.php index 692096b38db..a180b0119ef 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -27,6 +27,7 @@ use pocketmine\block\Bed; use pocketmine\block\BlockTypeTags; use pocketmine\block\inventory\BlockInventory; +use pocketmine\block\ProximityRestricted; use pocketmine\block\UnknownBlock; use pocketmine\block\VanillaBlocks; use pocketmine\command\CommandSender; @@ -1381,7 +1382,7 @@ protected function processMostRecentMovements() : void{ if ($this->openContainerPosition !== null && $this->currentWindow !== null) { $distance = $this->location->distance($this->openContainerPosition); - if ($distance > $this->currentWindow->getMaxDistanceFromContainer()) { + if ($distance > $this->currentWindow->getMaxDistance()) { $this->removeCurrentWindow(); } } From 06ca641fee1eef3de7adfeea63a040d7fa7c028b Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 5 Jul 2024 03:35:28 +0000 Subject: [PATCH 18/28] fix typo --- src/player/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/player/Player.php b/src/player/Player.php index a180b0119ef..e69a13a15b4 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -2659,7 +2659,7 @@ public function setCurrentWindow(Inventory $inventory) : bool{ $inventory->onOpen($this); $this->currentWindow = $inventory; - if ($inventory instanceof ProximityResticted) { + if ($inventory instanceof ProximityRestricted) { if ($inventory->getMaxDistance() > 0) { if ($inventory instanceof BlockInventory) { $holder = $inventory->getHolder(); From 77e8560df7499a49a720794074b82af29d4ed310 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 5 Jul 2024 04:00:56 +0000 Subject: [PATCH 19/28] correct errors --- src/player/Player.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index e69a13a15b4..f9e93c02314 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -1378,12 +1378,13 @@ protected function processMostRecentMovements() : void{ $this->logger->debug("Exceeded movement rate limit, forcing to last accepted position"); $this->sendPosition($this->location, $this->location->getYaw(), $this->location->getPitch(), MovePlayerPacket::MODE_RESET); } - if ($this->openContainerPosition !== null && $this->currentWindow !== null) { - $distance = $this->location->distance($this->openContainerPosition); + if ($this->currentWindow instanceof ProximityRestricted) { + $distance = $this->location->distance($this->openContainerPosition); - if ($distance > $this->currentWindow->getMaxDistance()) { - $this->removeCurrentWindow(); + if ($distance > $this->currentWindow->getMaxDistance()) { + $this->removeCurrentWindow(); + } } } } From 741f4bf12396bf8d4d64a2609636c97ed68b872b Mon Sep 17 00:00:00 2001 From: ShockedPlot7560 Date: Mon, 18 Nov 2024 11:19:19 +0100 Subject: [PATCH 20/28] moove ProximityRestricted into block/inventory --- src/block/{ => inventory}/ProximityRestricted.php | 2 +- src/inventory/BaseInventory.php | 2 +- src/player/Player.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/block/{ => inventory}/ProximityRestricted.php (96%) diff --git a/src/block/ProximityRestricted.php b/src/block/inventory/ProximityRestricted.php similarity index 96% rename from src/block/ProximityRestricted.php rename to src/block/inventory/ProximityRestricted.php index d69d7c8bf52..a14d53c148c 100644 --- a/src/block/ProximityRestricted.php +++ b/src/block/inventory/ProximityRestricted.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\block; +namespace pocketmine\block\inventory; interface ProximityRestricted { diff --git a/src/inventory/BaseInventory.php b/src/inventory/BaseInventory.php index 573ea962efb..ae6b49b1b85 100644 --- a/src/inventory/BaseInventory.php +++ b/src/inventory/BaseInventory.php @@ -23,7 +23,7 @@ namespace pocketmine\inventory; -use pocketmine\block\ProximityRestricted; +use pocketmine\block\inventory\ProximityRestricted; use pocketmine\item\Item; use pocketmine\item\VanillaItems; use pocketmine\player\Player; diff --git a/src/player/Player.php b/src/player/Player.php index f9e93c02314..f31b59f1756 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -27,7 +27,7 @@ use pocketmine\block\Bed; use pocketmine\block\BlockTypeTags; use pocketmine\block\inventory\BlockInventory; -use pocketmine\block\ProximityRestricted; +use pocketmine\block\inventory\ProximityRestricted; use pocketmine\block\UnknownBlock; use pocketmine\block\VanillaBlocks; use pocketmine\command\CommandSender; From 271541c23303ddfedea9b9028d60f9a415eb58c6 Mon Sep 17 00:00:00 2001 From: ShockedPlot7560 Date: Mon, 18 Nov 2024 11:20:32 +0100 Subject: [PATCH 21/28] make ProximityRestricted inventory immutable --- src/block/inventory/ProximityRestricted.php | 5 ----- src/inventory/BaseInventory.php | 4 ---- 2 files changed, 9 deletions(-) diff --git a/src/block/inventory/ProximityRestricted.php b/src/block/inventory/ProximityRestricted.php index a14d53c148c..ca435a1e53d 100644 --- a/src/block/inventory/ProximityRestricted.php +++ b/src/block/inventory/ProximityRestricted.php @@ -31,9 +31,4 @@ interface ProximityRestricted { * Returns the max distance the player can be away */ public function getMaxDistance() : int; - - /** - * Returns the max distance the player can be away - */ - public function setMaxDistance(int $maxDistance) : void; } diff --git a/src/inventory/BaseInventory.php b/src/inventory/BaseInventory.php index ae6b49b1b85..e7fdc09f812 100644 --- a/src/inventory/BaseInventory.php +++ b/src/inventory/BaseInventory.php @@ -67,10 +67,6 @@ public function getMaxDistance() : int { return $this->maxDistanceFromContainer; } - public function setMaxDistance(int $maxDistance) : void { - $this->maxDistanceFromContainer = $maxDistance; - } - abstract protected function internalSetItem(int $index, Item $item) : void; public function setItem(int $index, Item $item) : void{ From 38c99a9bf81f7070ddf2a69070eec34445a4f4b5 Mon Sep 17 00:00:00 2001 From: ShockedPlot7560 Date: Mon, 18 Nov 2024 11:32:33 +0100 Subject: [PATCH 22/28] make code more clear --- src/block/inventory/ProximityRestricted.php | 2 ++ src/inventory/BaseInventory.php | 2 +- src/player/Player.php | 29 +++++++++------------ 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/block/inventory/ProximityRestricted.php b/src/block/inventory/ProximityRestricted.php index ca435a1e53d..cacf1b1e466 100644 --- a/src/block/inventory/ProximityRestricted.php +++ b/src/block/inventory/ProximityRestricted.php @@ -29,6 +29,8 @@ interface ProximityRestricted { /** * Returns the max distance the player can be away + * + * @phpstan-return positive-int */ public function getMaxDistance() : int; } diff --git a/src/inventory/BaseInventory.php b/src/inventory/BaseInventory.php index e7fdc09f812..b475f2bf643 100644 --- a/src/inventory/BaseInventory.php +++ b/src/inventory/BaseInventory.php @@ -40,7 +40,7 @@ */ abstract class BaseInventory implements Inventory, ProximityRestricted{ protected int $maxStackSize = Inventory::MAX_STACK; - + /** @phpstan-var positive-int */ protected int $maxDistanceFromContainer = ProximityRestricted::MAX_DISTANCE; /** @var Player[] */ diff --git a/src/player/Player.php b/src/player/Player.php index f31b59f1756..037affae875 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -298,7 +298,7 @@ public static function isValidUserName(?string $name) : bool{ protected ?SurvivalBlockBreakHandler $blockBreakHandler = null; - protected ?Vector3 $openContainerPosition = null; + protected ?Vector3 $containerOpenPosition = null; public function __construct(Server $server, NetworkSession $session, PlayerInfo $playerInfo, bool $authenticated, Location $spawnLocation, ?CompoundTag $namedtag){ $username = TextFormat::clean($playerInfo->getUsername()); @@ -1378,14 +1378,11 @@ protected function processMostRecentMovements() : void{ $this->logger->debug("Exceeded movement rate limit, forcing to last accepted position"); $this->sendPosition($this->location, $this->location->getYaw(), $this->location->getPitch(), MovePlayerPacket::MODE_RESET); } - if ($this->openContainerPosition !== null && $this->currentWindow !== null) { - if ($this->currentWindow instanceof ProximityRestricted) { - $distance = $this->location->distance($this->openContainerPosition); - - if ($distance > $this->currentWindow->getMaxDistance()) { - $this->removeCurrentWindow(); - } - } + if($this->containerOpenPosition !== null && + $this->currentWindow instanceof ProximityRestricted && + $this->location->distance($this->containerOpenPosition) > $this->currentWindow->getMaxDistance() + ){ + $this->removeCurrentWindow(); } } @@ -2660,13 +2657,11 @@ public function setCurrentWindow(Inventory $inventory) : bool{ $inventory->onOpen($this); $this->currentWindow = $inventory; - if ($inventory instanceof ProximityRestricted) { - if ($inventory->getMaxDistance() > 0) { - if ($inventory instanceof BlockInventory) { - $holder = $inventory->getHolder(); - $this->openContainerPosition = $holder->asPosition(); - } - } + if($inventory instanceof ProximityRestricted && + $inventory->getMaxDistance() > 0 && + $inventory instanceof BlockInventory + ){ + $this->containerOpenPosition = $inventory->getHolder()->asPosition(); } return true; @@ -2685,7 +2680,7 @@ public function removeCurrentWindow() : void{ (new InventoryCloseEvent($currentWindow, $this))->call(); } - $this->openContainerPosition = null; + $this->containerOpenPosition = null; } protected function addPermanentInventories(Inventory ...$inventories) : void{ From f4c020ddac314405af2d2b144ff66690e63b0f9e Mon Sep 17 00:00:00 2001 From: ShockedPlot7560 Date: Mon, 18 Nov 2024 11:36:54 +0100 Subject: [PATCH 23/28] improve documentation --- src/block/inventory/ProximityRestricted.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/block/inventory/ProximityRestricted.php b/src/block/inventory/ProximityRestricted.php index cacf1b1e466..2a4ad149a2a 100644 --- a/src/block/inventory/ProximityRestricted.php +++ b/src/block/inventory/ProximityRestricted.php @@ -23,12 +23,17 @@ namespace pocketmine\block\inventory; +/** + * Represents a block that has a maximum distance the player can be away from it. + * + * This need to be combined with the BlockInventory interface to be useful. + */ interface ProximityRestricted { public const MAX_DISTANCE = 6; /** - * Returns the max distance the player can be away + * Returns the max distance the player can be away from the holder * * @phpstan-return positive-int */ From 48e3a8d2abd7a4f2d7393b10c3989bb7b49aa6df Mon Sep 17 00:00:00 2001 From: ShockedPlot7560 Date: Mon, 18 Nov 2024 11:37:51 +0100 Subject: [PATCH 24/28] remove ProximityRestricted from BaseInventory --- src/inventory/BaseInventory.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/inventory/BaseInventory.php b/src/inventory/BaseInventory.php index b475f2bf643..e0b49a5d69f 100644 --- a/src/inventory/BaseInventory.php +++ b/src/inventory/BaseInventory.php @@ -23,7 +23,6 @@ namespace pocketmine\inventory; -use pocketmine\block\inventory\ProximityRestricted; use pocketmine\item\Item; use pocketmine\item\VanillaItems; use pocketmine\player\Player; @@ -38,10 +37,8 @@ /** * This class provides everything needed to implement an inventory, minus the underlying storage system. */ -abstract class BaseInventory implements Inventory, ProximityRestricted{ +abstract class BaseInventory implements Inventory{ protected int $maxStackSize = Inventory::MAX_STACK; - /** @phpstan-var positive-int */ - protected int $maxDistanceFromContainer = ProximityRestricted::MAX_DISTANCE; /** @var Player[] */ protected array $viewers = []; @@ -63,10 +60,6 @@ public function setMaxStackSize(int $size) : void{ $this->maxStackSize = $size; } - public function getMaxDistance() : int { - return $this->maxDistanceFromContainer; - } - abstract protected function internalSetItem(int $index, Item $item) : void; public function setItem(int $index, Item $item) : void{ From f6864c23e3c3462dadcb6bf888b15d30ffb2b2f1 Mon Sep 17 00:00:00 2001 From: ShockedPlot7560 Date: Mon, 18 Nov 2024 11:42:54 +0100 Subject: [PATCH 25/28] remove unrelated changes --- src/inventory/BaseInventory.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/inventory/BaseInventory.php b/src/inventory/BaseInventory.php index e0b49a5d69f..254e44b1ea0 100644 --- a/src/inventory/BaseInventory.php +++ b/src/inventory/BaseInventory.php @@ -39,7 +39,6 @@ */ abstract class BaseInventory implements Inventory{ protected int $maxStackSize = Inventory::MAX_STACK; - /** @var Player[] */ protected array $viewers = []; /** From 3996449c3628078ca2ea97ec0e1597d0854e12a1 Mon Sep 17 00:00:00 2001 From: ShockedPlot7560 Date: Mon, 18 Nov 2024 11:48:04 +0100 Subject: [PATCH 26/28] create ProximityRestrictedTrait and implement it in the block inventories --- src/block/inventory/AnvilInventory.php | 3 +- src/block/inventory/BarrelInventory.php | 3 +- src/block/inventory/BrewingStandInventory.php | 3 +- .../inventory/CartographyTableInventory.php | 3 +- src/block/inventory/ChestInventory.php | 3 +- .../inventory/CraftingTableInventory.php | 3 +- src/block/inventory/DoubleChestInventory.php | 3 +- src/block/inventory/EnchantInventory.php | 3 +- src/block/inventory/EnderChestInventory.php | 3 +- src/block/inventory/FurnaceInventory.php | 3 +- src/block/inventory/HopperInventory.php | 3 +- src/block/inventory/LoomInventory.php | 3 +- .../inventory/ProximityRestrictedTrait.php | 32 +++++++++++++++++++ src/block/inventory/ShulkerBoxInventory.php | 3 +- .../inventory/SmithingTableInventory.php | 3 +- src/block/inventory/StonecutterInventory.php | 3 +- 16 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 src/block/inventory/ProximityRestrictedTrait.php diff --git a/src/block/inventory/AnvilInventory.php b/src/block/inventory/AnvilInventory.php index 7d906a6326e..d874032eb26 100644 --- a/src/block/inventory/AnvilInventory.php +++ b/src/block/inventory/AnvilInventory.php @@ -27,8 +27,9 @@ use pocketmine\inventory\TemporaryInventory; use pocketmine\world\Position; -class AnvilInventory extends SimpleInventory implements BlockInventory, TemporaryInventory{ +class AnvilInventory extends SimpleInventory implements BlockInventory, TemporaryInventory, ProximityRestricted{ use BlockInventoryTrait; + use ProximityRestrictedTrait; public const SLOT_INPUT = 0; public const SLOT_MATERIAL = 1; diff --git a/src/block/inventory/BarrelInventory.php b/src/block/inventory/BarrelInventory.php index 0d17d2a3e5b..aa3c184c345 100644 --- a/src/block/inventory/BarrelInventory.php +++ b/src/block/inventory/BarrelInventory.php @@ -30,8 +30,9 @@ use pocketmine\world\sound\BarrelOpenSound; use pocketmine\world\sound\Sound; -class BarrelInventory extends SimpleInventory implements BlockInventory{ +class BarrelInventory extends SimpleInventory implements BlockInventory, ProximityRestricted{ use AnimatedBlockInventoryTrait; + use ProximityRestrictedTrait; public function __construct(Position $holder){ $this->holder = $holder; diff --git a/src/block/inventory/BrewingStandInventory.php b/src/block/inventory/BrewingStandInventory.php index 8bab4ba97b0..b71ae300060 100644 --- a/src/block/inventory/BrewingStandInventory.php +++ b/src/block/inventory/BrewingStandInventory.php @@ -26,8 +26,9 @@ use pocketmine\inventory\SimpleInventory; use pocketmine\world\Position; -class BrewingStandInventory extends SimpleInventory implements BlockInventory{ +class BrewingStandInventory extends SimpleInventory implements BlockInventory, ProximityRestricted{ use BlockInventoryTrait; + use ProximityRestrictedTrait; public const SLOT_INGREDIENT = 0; public const SLOT_BOTTLE_LEFT = 1; diff --git a/src/block/inventory/CartographyTableInventory.php b/src/block/inventory/CartographyTableInventory.php index 7bd9146ac6f..0e3ce7fc6a9 100644 --- a/src/block/inventory/CartographyTableInventory.php +++ b/src/block/inventory/CartographyTableInventory.php @@ -27,8 +27,9 @@ use pocketmine\inventory\TemporaryInventory; use pocketmine\world\Position; -final class CartographyTableInventory extends SimpleInventory implements BlockInventory, TemporaryInventory{ +final class CartographyTableInventory extends SimpleInventory implements BlockInventory, TemporaryInventory, ProximityRestricted{ use BlockInventoryTrait; + use ProximityRestrictedTrait; public function __construct(Position $holder){ $this->holder = $holder; diff --git a/src/block/inventory/ChestInventory.php b/src/block/inventory/ChestInventory.php index b61fab57c35..7bf0961245c 100644 --- a/src/block/inventory/ChestInventory.php +++ b/src/block/inventory/ChestInventory.php @@ -31,8 +31,9 @@ use pocketmine\world\sound\ChestOpenSound; use pocketmine\world\sound\Sound; -class ChestInventory extends SimpleInventory implements BlockInventory{ +class ChestInventory extends SimpleInventory implements BlockInventory, ProximityRestricted{ use AnimatedBlockInventoryTrait; + use ProximityRestrictedTrait; public function __construct(Position $holder){ $this->holder = $holder; diff --git a/src/block/inventory/CraftingTableInventory.php b/src/block/inventory/CraftingTableInventory.php index 767e8a5f49c..124cf1c635b 100644 --- a/src/block/inventory/CraftingTableInventory.php +++ b/src/block/inventory/CraftingTableInventory.php @@ -27,8 +27,9 @@ use pocketmine\inventory\TemporaryInventory; use pocketmine\world\Position; -final class CraftingTableInventory extends CraftingGrid implements BlockInventory, TemporaryInventory{ +final class CraftingTableInventory extends CraftingGrid implements BlockInventory, TemporaryInventory, ProximityRestricted{ use BlockInventoryTrait; + use ProximityRestrictedTrait; public function __construct(Position $holder){ $this->holder = $holder; diff --git a/src/block/inventory/DoubleChestInventory.php b/src/block/inventory/DoubleChestInventory.php index a7eb4a4398c..a666ea6f16c 100644 --- a/src/block/inventory/DoubleChestInventory.php +++ b/src/block/inventory/DoubleChestInventory.php @@ -30,8 +30,9 @@ use pocketmine\world\sound\ChestOpenSound; use pocketmine\world\sound\Sound; -class DoubleChestInventory extends BaseInventory implements BlockInventory, InventoryHolder{ +class DoubleChestInventory extends BaseInventory implements BlockInventory, InventoryHolder, ProximityRestricted{ use AnimatedBlockInventoryTrait; + use ProximityRestrictedTrait; public function __construct( private ChestInventory $left, diff --git a/src/block/inventory/EnchantInventory.php b/src/block/inventory/EnchantInventory.php index b726dbedf32..0c34650b077 100644 --- a/src/block/inventory/EnchantInventory.php +++ b/src/block/inventory/EnchantInventory.php @@ -33,8 +33,9 @@ use function array_values; use function count; -class EnchantInventory extends SimpleInventory implements BlockInventory, TemporaryInventory{ +class EnchantInventory extends SimpleInventory implements BlockInventory, TemporaryInventory, ProximityRestricted{ use BlockInventoryTrait; + use ProximityRestrictedTrait; public const SLOT_INPUT = 0; public const SLOT_LAPIS = 1; diff --git a/src/block/inventory/EnderChestInventory.php b/src/block/inventory/EnderChestInventory.php index c1d7c5401d3..693cc8ba836 100644 --- a/src/block/inventory/EnderChestInventory.php +++ b/src/block/inventory/EnderChestInventory.php @@ -38,10 +38,11 @@ /** * EnderChestInventory is not a real inventory; it's just a gateway to the player's ender inventory. */ -class EnderChestInventory extends DelegateInventory implements BlockInventory{ +class EnderChestInventory extends DelegateInventory implements BlockInventory, ProximityRestricted{ use AnimatedBlockInventoryTrait { onClose as animatedBlockInventoryTrait_onClose; } + use ProximityRestrictedTrait; public function __construct( Position $holder, diff --git a/src/block/inventory/FurnaceInventory.php b/src/block/inventory/FurnaceInventory.php index ff44d6b7063..13d38bd05fc 100644 --- a/src/block/inventory/FurnaceInventory.php +++ b/src/block/inventory/FurnaceInventory.php @@ -28,8 +28,9 @@ use pocketmine\item\Item; use pocketmine\world\Position; -class FurnaceInventory extends SimpleInventory implements BlockInventory{ +class FurnaceInventory extends SimpleInventory implements BlockInventory, ProximityRestricted{ use BlockInventoryTrait; + use ProximityRestrictedTrait; public const SLOT_INPUT = 0; public const SLOT_FUEL = 1; diff --git a/src/block/inventory/HopperInventory.php b/src/block/inventory/HopperInventory.php index a20e9ae1a18..c7e2250d63f 100644 --- a/src/block/inventory/HopperInventory.php +++ b/src/block/inventory/HopperInventory.php @@ -26,8 +26,9 @@ use pocketmine\inventory\SimpleInventory; use pocketmine\world\Position; -class HopperInventory extends SimpleInventory implements BlockInventory{ +class HopperInventory extends SimpleInventory implements BlockInventory, ProximityRestricted{ use BlockInventoryTrait; + use ProximityRestrictedTrait; public function __construct(Position $holder, int $size = 5){ $this->holder = $holder; diff --git a/src/block/inventory/LoomInventory.php b/src/block/inventory/LoomInventory.php index fd34620a05f..a234307faa3 100644 --- a/src/block/inventory/LoomInventory.php +++ b/src/block/inventory/LoomInventory.php @@ -27,8 +27,9 @@ use pocketmine\inventory\TemporaryInventory; use pocketmine\world\Position; -final class LoomInventory extends SimpleInventory implements BlockInventory, TemporaryInventory{ +final class LoomInventory extends SimpleInventory implements BlockInventory, TemporaryInventory, ProximityRestricted{ use BlockInventoryTrait; + use ProximityRestrictedTrait; public const SLOT_BANNER = 0; public const SLOT_DYE = 1; diff --git a/src/block/inventory/ProximityRestrictedTrait.php b/src/block/inventory/ProximityRestrictedTrait.php new file mode 100644 index 00000000000..5000babecaf --- /dev/null +++ b/src/block/inventory/ProximityRestrictedTrait.php @@ -0,0 +1,32 @@ +maxDistance; + } +} diff --git a/src/block/inventory/ShulkerBoxInventory.php b/src/block/inventory/ShulkerBoxInventory.php index d915a995182..677ff1fc508 100644 --- a/src/block/inventory/ShulkerBoxInventory.php +++ b/src/block/inventory/ShulkerBoxInventory.php @@ -34,8 +34,9 @@ use pocketmine\world\sound\ShulkerBoxOpenSound; use pocketmine\world\sound\Sound; -class ShulkerBoxInventory extends SimpleInventory implements BlockInventory{ +class ShulkerBoxInventory extends SimpleInventory implements BlockInventory, ProximityRestricted{ use AnimatedBlockInventoryTrait; + use ProximityRestrictedTrait; public function __construct(Position $holder){ $this->holder = $holder; diff --git a/src/block/inventory/SmithingTableInventory.php b/src/block/inventory/SmithingTableInventory.php index 2f67ac9d2dd..110481b4a68 100644 --- a/src/block/inventory/SmithingTableInventory.php +++ b/src/block/inventory/SmithingTableInventory.php @@ -27,8 +27,9 @@ use pocketmine\inventory\TemporaryInventory; use pocketmine\world\Position; -final class SmithingTableInventory extends SimpleInventory implements BlockInventory, TemporaryInventory{ +final class SmithingTableInventory extends SimpleInventory implements BlockInventory, TemporaryInventory, ProximityRestricted{ use BlockInventoryTrait; + use ProximityRestrictedTrait; public function __construct(Position $holder){ $this->holder = $holder; diff --git a/src/block/inventory/StonecutterInventory.php b/src/block/inventory/StonecutterInventory.php index 4ed644ff2c3..2b20a7538ac 100644 --- a/src/block/inventory/StonecutterInventory.php +++ b/src/block/inventory/StonecutterInventory.php @@ -27,8 +27,9 @@ use pocketmine\inventory\TemporaryInventory; use pocketmine\world\Position; -class StonecutterInventory extends SimpleInventory implements BlockInventory, TemporaryInventory{ +class StonecutterInventory extends SimpleInventory implements BlockInventory, TemporaryInventory, ProximityRestricted{ use BlockInventoryTrait; + use ProximityRestrictedTrait; public const SLOT_INPUT = 0; From 91da21f1b7aff0e8f6dc9d7e1d7ff2db1f952228 Mon Sep 17 00:00:00 2001 From: ShockedPlot7560 Date: Mon, 18 Nov 2024 11:52:28 +0100 Subject: [PATCH 27/28] change conditions --- src/player/Player.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index 037affae875..0465744dda3 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -2658,8 +2658,8 @@ public function setCurrentWindow(Inventory $inventory) : bool{ $this->currentWindow = $inventory; if($inventory instanceof ProximityRestricted && - $inventory->getMaxDistance() > 0 && - $inventory instanceof BlockInventory + $inventory instanceof BlockInventory && + $inventory->getMaxDistance() > 0 ){ $this->containerOpenPosition = $inventory->getHolder()->asPosition(); } From caeeddc3c0265e36c1a48d4efceb034bba949d3d Mon Sep 17 00:00:00 2001 From: ShockedPlot7560 Date: Mon, 18 Nov 2024 11:55:54 +0100 Subject: [PATCH 28/28] fix PHPstan --- src/block/inventory/ProximityRestrictedTrait.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/block/inventory/ProximityRestrictedTrait.php b/src/block/inventory/ProximityRestrictedTrait.php index 5000babecaf..b180c180224 100644 --- a/src/block/inventory/ProximityRestrictedTrait.php +++ b/src/block/inventory/ProximityRestrictedTrait.php @@ -24,6 +24,7 @@ namespace pocketmine\block\inventory; trait ProximityRestrictedTrait{ + /** @phpstan-var positive-int */ protected int $maxDistance = ProximityRestricted::MAX_DISTANCE; public function getMaxDistance() : int{