From a45a96b3ee6baa595d1140a2646d5ef39ccea380 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 15:40:25 +0100 Subject: [PATCH 01/28] ShulkerBoxInventory: fixed inappropriate usage of BlockLegacyIds when comparing item IDS --- src/block/inventory/ShulkerBoxInventory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/block/inventory/ShulkerBoxInventory.php b/src/block/inventory/ShulkerBoxInventory.php index cace49652..648a0b05f 100644 --- a/src/block/inventory/ShulkerBoxInventory.php +++ b/src/block/inventory/ShulkerBoxInventory.php @@ -23,9 +23,9 @@ declare(strict_types=1); namespace pocketmine\block\inventory; -use pocketmine\block\BlockLegacyIds; use pocketmine\inventory\SimpleInventory; use pocketmine\item\Item; +use pocketmine\item\ItemIds; use pocketmine\network\mcpe\protocol\BlockEventPacket; use pocketmine\network\mcpe\protocol\types\BlockPosition; use pocketmine\world\Position; @@ -50,7 +50,7 @@ class ShulkerBoxInventory extends SimpleInventory implements BlockInventory{ } public function canAddItem(Item $item) : bool{ - if($item->getId() === BlockLegacyIds::UNDYED_SHULKER_BOX || $item->getId() === BlockLegacyIds::SHULKER_BOX){ + if($item->getId() === ItemIds::UNDYED_SHULKER_BOX || $item->getId() === ItemIds::SHULKER_BOX){ return false; } return parent::canAddItem($item); From fcb2ccab992ab49e0256be4bca8d8caf4a8988df Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 16:22:35 +0100 Subject: [PATCH 02/28] NetworkSession: Sync all attributes on respawn --- src/network/mcpe/NetworkSession.php | 1 + tests/phpstan/configs/actual-problems.neon | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 711415ecc..7f85d8f99 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -723,6 +723,7 @@ class NetworkSession{ } public function onServerRespawn() : void{ + $this->syncAttributes($this->player, $this->player->getAttributeMap()->getAll()); $this->player->sendData(null); $this->syncAdventureSettings($this->player); diff --git a/tests/phpstan/configs/actual-problems.neon b/tests/phpstan/configs/actual-problems.neon index d3776de3d..5c992ae02 100644 --- a/tests/phpstan/configs/actual-problems.neon +++ b/tests/phpstan/configs/actual-problems.neon @@ -610,6 +610,11 @@ parameters: count: 1 path: ../../../src/network/mcpe/NetworkSession.php + - + message: "#^Cannot call method getAttributeMap\\(\\) on pocketmine\\\\player\\\\Player\\|null\\.$#" + count: 1 + path: ../../../src/network/mcpe/NetworkSession.php + - message: "#^Cannot call method getLanguage\\(\\) on pocketmine\\\\player\\\\Player\\|null\\.$#" count: 1 @@ -665,6 +670,11 @@ parameters: count: 1 path: ../../../src/network/mcpe/NetworkSession.php + - + message: "#^Parameter \\#1 \\$entity of method pocketmine\\\\network\\\\mcpe\\\\NetworkSession\\:\\:syncAttributes\\(\\) expects pocketmine\\\\entity\\\\Living, pocketmine\\\\player\\\\Player\\|null given\\.$#" + count: 1 + path: ../../../src/network/mcpe/NetworkSession.php + - message: "#^Parameter \\#1 \\$for of method pocketmine\\\\network\\\\mcpe\\\\NetworkSession\\:\\:syncAdventureSettings\\(\\) expects pocketmine\\\\player\\\\Player, pocketmine\\\\player\\\\Player\\|null given\\.$#" count: 2 From 01b0742bd44fb3bdcb947daf3eaf7a624853b5a0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 17:07:49 +0100 Subject: [PATCH 03/28] LightUpdate: account for virtual nodes in prepareNodes() fixes #3959 --- src/world/light/LightUpdate.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/world/light/LightUpdate.php b/src/world/light/LightUpdate.php index 45fa19df3..9570b8e03 100644 --- a/src/world/light/LightUpdate.php +++ b/src/world/light/LightUpdate.php @@ -114,6 +114,9 @@ abstract class LightUpdate{ $context->removalQueue->enqueue([$x, $y, $z, $oldLevel]); } } + }elseif($this->getEffectiveLight($x, $y, $z) > 0){ //outside the chunk (e.g. virtual sky light from y=256) + $context->spreadVisited[$blockHash] = true; + $context->spreadQueue->enqueue([$x, $y, $z]); } } return $context; From 0324392cd8861db76462186e8bc0c38635a18299 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 17:12:47 +0100 Subject: [PATCH 04/28] Clean PHPStan baseline --- tests/phpstan/configs/actual-problems.neon | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/phpstan/configs/actual-problems.neon b/tests/phpstan/configs/actual-problems.neon index 5c992ae02..a54a862a5 100644 --- a/tests/phpstan/configs/actual-problems.neon +++ b/tests/phpstan/configs/actual-problems.neon @@ -955,11 +955,6 @@ parameters: count: 1 path: ../../../src/utils/Utils.php - - - message: "#^Parameter \\#2 \\$array of function array_map expects array, mixed given\\.$#" - count: 1 - path: ../../../src/utils/Utils.php - - message: "#^Cannot call method getFullBlock\\(\\) on pocketmine\\\\world\\\\format\\\\SubChunk\\|null\\.$#" count: 1 From 5d92eddc824b5426edf76b0a84b3a8a0349893e2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 17:35:21 +0100 Subject: [PATCH 05/28] InventoryTransaction: provide object ID of failed action for debugging identification closes #3235 --- src/inventory/transaction/InventoryTransaction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inventory/transaction/InventoryTransaction.php b/src/inventory/transaction/InventoryTransaction.php index d79b07cd1..82e206550 100644 --- a/src/inventory/transaction/InventoryTransaction.php +++ b/src/inventory/transaction/InventoryTransaction.php @@ -148,7 +148,7 @@ class InventoryTransaction{ try{ $action->validate($this->source); }catch(TransactionValidationException $e){ - throw new TransactionValidationException(get_class($action) . ": " . $e->getMessage(), 0, $e); + throw new TransactionValidationException(get_class($action) . "#" . spl_object_id($action) . ": " . $e->getMessage(), 0, $e); } if(!$action->getSourceItem()->isNull()){ From 33e6b63fe5c98cadedc552bdfcd11ea27a5f1ec8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 17:39:11 +0100 Subject: [PATCH 06/28] Explosion: remove unused local variable in explodeB() --- src/world/Explosion.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/world/Explosion.php b/src/world/Explosion.php index f67d9034f..4f007deaa 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -156,8 +156,6 @@ class Explosion{ * and creating sounds and particles. */ public function explodeB() : bool{ - $updateBlocks = []; - $source = (new Vector3($this->source->x, $this->source->y, $this->source->z))->floor(); $yield = (1 / $this->size) * 100; From 688be0a404a4640778c01be6c7073d67b03198db Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 18:46:38 +0100 Subject: [PATCH 07/28] Server: apply server.properties difficulty to newly generated worlds see #5057 jury is out on whether or not this should override difficulty on preexisting worlds, but it's non-controversial that it should apply at least to newly generated worlds. --- src/Server.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Server.php b/src/Server.php index 632adf519..8ab1a2408 100644 --- a/src/Server.php +++ b/src/Server.php @@ -1093,6 +1093,7 @@ class Server{ $creationOptions->setGeneratorClass($generatorClass); $creationOptions->setGeneratorOptions($generatorOptions); + $creationOptions->setDifficulty($this->getDifficulty()); if(isset($options["difficulty"]) && is_string($options["difficulty"])){ $creationOptions->setDifficulty(World::getDifficultyFromString($options["difficulty"])); } @@ -1127,6 +1128,7 @@ class Server{ if($convertedSeed !== null){ $creationOptions->setSeed($convertedSeed); } + $creationOptions->setDifficulty($this->getDifficulty()); $this->worldManager->generateWorld($default, $creationOptions); } } From c82dfef9b051843269794637e38699f5f97a3436 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 20:08:12 +0100 Subject: [PATCH 08/28] Player: fix weird behaviour when teleporting sleeping players closes #4672 --- 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 112baf821..7b896ab3a 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -2373,6 +2373,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ if(parent::teleport($pos, $yaw, $pitch)){ $this->removeCurrentWindow(); + $this->stopSleep(); $this->sendPosition($this->location, $this->location->yaw, $this->location->pitch, MovePlayerPacket::MODE_TELEPORT); $this->broadcastMovement(true); @@ -2384,7 +2385,6 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ if($this->spawnChunkLoadCount !== -1){ $this->spawnChunkLoadCount = 0; } - $this->stopSleep(); $this->blockBreakHandler = null; //TODO: workaround for player last pos not getting updated From e9a17374d1e441943cd973a5e23c140ba36a93c1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 20:29:25 +0100 Subject: [PATCH 09/28] Rewrite documentation of CommandEvent no wonder people get the idea to use this shit for banning commands ... --- src/event/server/CommandEvent.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/event/server/CommandEvent.php b/src/event/server/CommandEvent.php index 818a465cb..9a982d230 100644 --- a/src/event/server/CommandEvent.php +++ b/src/event/server/CommandEvent.php @@ -28,12 +28,18 @@ use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; /** - * Called when any CommandSender runs a command, early in the process + * Called when any CommandSender runs a command, before it is parsed. * - * You don't want to use this except for a few cases like logging commands, - * blocking commands on certain places, or applying modifiers. + * This can be used for logging commands, or preprocessing the command string to add custom features (e.g. selectors). * - * The message DOES NOT contain a slash at the start + * WARNING: DO NOT use this to block commands. Many commands have aliases. + * For example, /version can also be invoked using /ver or /about. + * To prevent command senders from using certain commands, deny them permission to use the commands you don't want them + * to have access to. + * + * @see Permissible::addAttachment() + * + * The message DOES NOT begin with a slash. */ class CommandEvent extends ServerEvent implements Cancellable{ use CancellableTrait; From 82104a8251c13a295f3814a9bc084c3490894f15 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 20:32:30 +0100 Subject: [PATCH 10/28] UpdateNotifyEvent: updated documentation --- src/event/server/UpdateNotifyEvent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/event/server/UpdateNotifyEvent.php b/src/event/server/UpdateNotifyEvent.php index 843b2c60e..927a2d608 100644 --- a/src/event/server/UpdateNotifyEvent.php +++ b/src/event/server/UpdateNotifyEvent.php @@ -26,7 +26,7 @@ namespace pocketmine\event\server; use pocketmine\updater\UpdateChecker; /** - * Called when the AutoUpdater receives notification of an available PocketMine-MP update. + * Called when the update checker receives notification of an available PocketMine-MP update. * Plugins may use this event to perform actions when an update notification is received. */ class UpdateNotifyEvent extends ServerEvent{ From 3177d197309905c743d54894b0803e3bfa51c188 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 21:03:56 +0100 Subject: [PATCH 11/28] PlayerKickEvent: improved woefully inadequate documentation --- src/event/player/PlayerKickEvent.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/event/player/PlayerKickEvent.php b/src/event/player/PlayerKickEvent.php index 7c91399d0..92f7c071b 100644 --- a/src/event/player/PlayerKickEvent.php +++ b/src/event/player/PlayerKickEvent.php @@ -29,7 +29,7 @@ use pocketmine\lang\Translatable; use pocketmine\player\Player; /** - * Called when a player leaves the server + * Called when a player is kicked (forcibly disconnected) from the server, e.g. if an operator used /kick. */ class PlayerKickEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; @@ -46,18 +46,33 @@ class PlayerKickEvent extends PlayerEvent implements Cancellable{ $this->reason = $reason; } + /** + * Sets the message shown on the kicked player's disconnection screen. + * This message is also displayed in the console and server log. + */ public function setReason(string $reason) : void{ $this->reason = $reason; } + /** + * Returns the message shown on the kicked player's disconnection screen. + * This message is also displayed in the console and server log. + * When kicked by the /kick command, the default is something like "Kicked by admin.". + */ public function getReason() : string{ return $this->reason; } + /** + * Sets the quit message broadcasted to other players. + */ public function setQuitMessage(Translatable|string $quitMessage) : void{ $this->quitMessage = $quitMessage; } + /** + * Returns the quit message broadcasted to other players, e.g. "Steve left the game". + */ public function getQuitMessage() : Translatable|string{ return $this->quitMessage; } From e934e2bd2648f15e60f957c205e423464064f709 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 21:05:27 +0100 Subject: [PATCH 12/28] PlayerDropItemEvent: updated documentation this can be triggered by dropping an item outside of the inventory menu while the inventory window is open. --- src/event/player/PlayerDropItemEvent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/event/player/PlayerDropItemEvent.php b/src/event/player/PlayerDropItemEvent.php index a97a6f5fa..3fc8d7966 100644 --- a/src/event/player/PlayerDropItemEvent.php +++ b/src/event/player/PlayerDropItemEvent.php @@ -29,7 +29,7 @@ use pocketmine\item\Item; use pocketmine\player\Player; /** - * Called when a player tries to drop an item from its hotbar + * Called when a player tries to drop an item */ class PlayerDropItemEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; From 7d172e221156c270ad4ebd273da1921cc560aa67 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 21:07:29 +0100 Subject: [PATCH 13/28] PlayerCommandPreprocessEvent: updated documentation --- src/event/player/PlayerCommandPreprocessEvent.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/event/player/PlayerCommandPreprocessEvent.php b/src/event/player/PlayerCommandPreprocessEvent.php index f1fae9665..bdcf0f1c0 100644 --- a/src/event/player/PlayerCommandPreprocessEvent.php +++ b/src/event/player/PlayerCommandPreprocessEvent.php @@ -28,12 +28,10 @@ use pocketmine\event\CancellableTrait; use pocketmine\player\Player; /** - * Called when a player runs a command or chats, early in the process + * Called when a player runs a command or chats, before it is processed. * - * You don't want to use this except for a few cases like logging commands, - * blocking commands on certain places, or applying modifiers. - * - * The message contains a slash at the start + * If the message is prefixed with a / (forward slash), it will be interpreted as a command. + * Otherwise, it will be broadcasted as a chat message. */ class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; From 3ca80b353be6a48fcb41a1df79836a3fa597353b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 21:20:11 +0100 Subject: [PATCH 14/28] InventoryTransactionEvent: rewrite documentation --- src/event/inventory/InventoryTransactionEvent.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/event/inventory/InventoryTransactionEvent.php b/src/event/inventory/InventoryTransactionEvent.php index 7ec8c9023..1d653a5d0 100644 --- a/src/event/inventory/InventoryTransactionEvent.php +++ b/src/event/inventory/InventoryTransactionEvent.php @@ -29,8 +29,17 @@ use pocketmine\event\Event; use pocketmine\inventory\transaction\InventoryTransaction; /** - * Called when there is a transaction between two Inventory objects. - * The source of this can be a Player, entities, mobs, or even hoppers in the future! + * Called when a player performs actions involving items in inventories. + * + * This may involve multiple inventories, and may include actions such as: + * - moving items from one slot to another + * - splitting itemstacks + * - dragging itemstacks across inventory slots (slot painting) + * - dropping an item on the ground + * - taking an item from the creative inventory menu + * - destroying (trashing) an item + * + * @see https://doc.pmmp.io/en/rtfd/developer-reference/inventory-transactions.html for more information on inventory transactions */ class InventoryTransactionEvent extends Event implements Cancellable{ use CancellableTrait; From 8ecf9717d6612b8f63d486d10a986fa8241fffff Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 21:21:13 +0100 Subject: [PATCH 15/28] PlayerItemHeldEvent: add documentation since some nuances of the intended behaviour were previously unclear... --- src/event/player/PlayerItemHeldEvent.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/event/player/PlayerItemHeldEvent.php b/src/event/player/PlayerItemHeldEvent.php index 71f55fc53..2e24bd377 100644 --- a/src/event/player/PlayerItemHeldEvent.php +++ b/src/event/player/PlayerItemHeldEvent.php @@ -28,6 +28,11 @@ use pocketmine\event\CancellableTrait; use pocketmine\item\Item; use pocketmine\player\Player; +/** + * Called when a player's held item changes. + * This could be because they selected a different hotbar slot, or because the item in the selected hotbar slot was + * changed. + */ class PlayerItemHeldEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; From 4a3e42f82e962765cddbb9186111a80251e6c2fe Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 21:21:51 +0100 Subject: [PATCH 16/28] PlayerTransferEvent: add documentation --- src/event/player/PlayerTransferEvent.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/event/player/PlayerTransferEvent.php b/src/event/player/PlayerTransferEvent.php index 9e6669893..adaa0ca5d 100644 --- a/src/event/player/PlayerTransferEvent.php +++ b/src/event/player/PlayerTransferEvent.php @@ -27,6 +27,9 @@ use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; use pocketmine\player\Player; +/** + * Called when a player attempts to be transferred to another server, e.g. by using /transferserver. + */ class PlayerTransferEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; @@ -44,26 +47,44 @@ class PlayerTransferEvent extends PlayerEvent implements Cancellable{ $this->message = $message; } + /** + * Returns the destination server address. This could be an IP or a domain name. + */ public function getAddress() : string{ return $this->address; } + /** + * Sets the destination server address. + */ public function setAddress(string $address) : void{ $this->address = $address; } + /** + * Returns the destination server port. + */ public function getPort() : int{ return $this->port; } + /** + * Sets the destination server port. + */ public function setPort(int $port) : void{ $this->port = $port; } + /** + * Returns the disconnect reason shown in the server log and on the console. + */ public function getMessage() : string{ return $this->message; } + /** + * Sets the disconnect reason shown in the server log and on the console. + */ public function setMessage(string $message) : void{ $this->message = $message; } From 1154c7c1ab9711101194004b4c59c9a64c2ec06c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 21:23:13 +0100 Subject: [PATCH 17/28] PlayerQuitEvent: improve documentation --- src/event/player/PlayerQuitEvent.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/event/player/PlayerQuitEvent.php b/src/event/player/PlayerQuitEvent.php index 9791cd893..3e08cb315 100644 --- a/src/event/player/PlayerQuitEvent.php +++ b/src/event/player/PlayerQuitEvent.php @@ -27,7 +27,14 @@ use pocketmine\lang\Translatable; use pocketmine\player\Player; /** - * Called when a player leaves the server + * Called when a player disconnects from the server for any reason. + * + * Some possible reasons include: + * - being kicked by an operator + * - disconnecting from the game + * - timeout due to network connectivity issues + * + * @see PlayerKickEvent */ class PlayerQuitEvent extends PlayerEvent{ @@ -42,14 +49,23 @@ class PlayerQuitEvent extends PlayerEvent{ $this->quitReason = $quitReason; } + /** + * Sets the quit message broadcasted to other players. + */ public function setQuitMessage(Translatable|string $quitMessage) : void{ $this->quitMessage = $quitMessage; } + /** + * Returns the quit message broadcasted to other players, e.g. "Steve left the game". + */ public function getQuitMessage() : Translatable|string{ return $this->quitMessage; } + /** + * Returns the disconnect reason shown in the server log and on the console. + */ public function getQuitReason() : string{ return $this->quitReason; } From 351cd4bfd7fd2e6e06b741717429bee51fa35022 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 21:46:53 +0100 Subject: [PATCH 18/28] Improve documentation of world-related events --- src/event/world/ChunkLoadEvent.php | 6 +++++- src/event/world/ChunkPopulateEvent.php | 3 ++- src/event/world/ChunkUnloadEvent.php | 2 +- src/event/world/WorldInitEvent.php | 2 +- src/event/world/WorldLoadEvent.php | 2 +- src/event/world/WorldSaveEvent.php | 2 +- src/event/world/WorldUnloadEvent.php | 2 +- 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/event/world/ChunkLoadEvent.php b/src/event/world/ChunkLoadEvent.php index f8f1ef776..affc43a31 100644 --- a/src/event/world/ChunkLoadEvent.php +++ b/src/event/world/ChunkLoadEvent.php @@ -27,7 +27,7 @@ use pocketmine\world\format\Chunk; use pocketmine\world\World; /** - * Called when a Chunk is loaded + * Called when a Chunk is loaded or newly created by the world generator. */ class ChunkLoadEvent extends ChunkEvent{ /** @var bool */ @@ -38,6 +38,10 @@ class ChunkLoadEvent extends ChunkEvent{ $this->newChunk = $newChunk; } + /** + * Returns whether the chunk is newly generated. + * If false, the chunk was loaded from storage. + */ public function isNewChunk() : bool{ return $this->newChunk; } diff --git a/src/event/world/ChunkPopulateEvent.php b/src/event/world/ChunkPopulateEvent.php index 3797bb58b..c86ab9761 100644 --- a/src/event/world/ChunkPopulateEvent.php +++ b/src/event/world/ChunkPopulateEvent.php @@ -24,7 +24,8 @@ declare(strict_types=1); namespace pocketmine\event\world; /** - * Called when a Chunk is populated (after receiving it on the main thread) + * Called when a Chunk is fully populated by the world generator. + * This means that the terrain has been generated, and all artifacts (e.g. trees, grass, ponds, etc.) have been placed. */ class ChunkPopulateEvent extends ChunkEvent{ diff --git a/src/event/world/ChunkUnloadEvent.php b/src/event/world/ChunkUnloadEvent.php index 89b58b6d4..41b70ab3a 100644 --- a/src/event/world/ChunkUnloadEvent.php +++ b/src/event/world/ChunkUnloadEvent.php @@ -27,7 +27,7 @@ use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; /** - * Called when a Chunk is unloaded + * Called when a Chunk is unloaded from memory. */ class ChunkUnloadEvent extends ChunkEvent implements Cancellable{ use CancellableTrait; diff --git a/src/event/world/WorldInitEvent.php b/src/event/world/WorldInitEvent.php index 4b85571ed..238da6087 100644 --- a/src/event/world/WorldInitEvent.php +++ b/src/event/world/WorldInitEvent.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace pocketmine\event\world; /** - * Called when a World is initializing + * Called when a new world is created/generated. */ class WorldInitEvent extends WorldEvent{ diff --git a/src/event/world/WorldLoadEvent.php b/src/event/world/WorldLoadEvent.php index 18235c29b..6e8264300 100644 --- a/src/event/world/WorldLoadEvent.php +++ b/src/event/world/WorldLoadEvent.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace pocketmine\event\world; /** - * Called when a World is loaded + * Called when a world is loaded or newly created/generated. */ class WorldLoadEvent extends WorldEvent{ diff --git a/src/event/world/WorldSaveEvent.php b/src/event/world/WorldSaveEvent.php index e43894791..43437d0c3 100644 --- a/src/event/world/WorldSaveEvent.php +++ b/src/event/world/WorldSaveEvent.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace pocketmine\event\world; /** - * Called when a World is saved + * Called when a world is saved. Saving may be triggered manually (e.g. via commands) or automatically (autosave). */ class WorldSaveEvent extends WorldEvent{ diff --git a/src/event/world/WorldUnloadEvent.php b/src/event/world/WorldUnloadEvent.php index 7f5b3ff8b..a8e226cae 100644 --- a/src/event/world/WorldUnloadEvent.php +++ b/src/event/world/WorldUnloadEvent.php @@ -27,7 +27,7 @@ use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; /** - * Called when a World is unloaded + * Called when a world is unloaded from memory. */ class WorldUnloadEvent extends WorldEvent implements Cancellable{ use CancellableTrait; From 7618b13c6e9ef0059425364fccb9e9db7ee0f015 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 21:57:14 +0100 Subject: [PATCH 19/28] ItemDespawnEvent: improve documentation --- src/event/entity/ItemDespawnEvent.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/event/entity/ItemDespawnEvent.php b/src/event/entity/ItemDespawnEvent.php index 6942fcf1b..ef496a23c 100644 --- a/src/event/entity/ItemDespawnEvent.php +++ b/src/event/entity/ItemDespawnEvent.php @@ -28,6 +28,9 @@ use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; /** + * Called when a dropped item tries to despawn due to its despawn delay running out. + * Cancelling the event will reset the despawn delay to default (5 minutes). + * * @phpstan-extends EntityEvent */ class ItemDespawnEvent extends EntityEvent implements Cancellable{ From 3abe80184ae52179334ac7c42860270dd68343b8 Mon Sep 17 00:00:00 2001 From: IvanCraft623 <57236932+IvanCraft623@users.noreply.github.com> Date: Sat, 21 May 2022 16:09:21 -0500 Subject: [PATCH 20/28] Update ItemSpawnEvent doc (#5059) --- src/event/entity/ItemSpawnEvent.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/event/entity/ItemSpawnEvent.php b/src/event/entity/ItemSpawnEvent.php index 59154f029..5c4b1d874 100644 --- a/src/event/entity/ItemSpawnEvent.php +++ b/src/event/entity/ItemSpawnEvent.php @@ -26,6 +26,15 @@ namespace pocketmine\event\entity; use pocketmine\entity\object\ItemEntity; /** + * Called when an item is spawned or loaded. + * + * Some possible reasons include: + * - item is loaded from disk + * - player dropping an item + * - block drops + * - loot of a player or entity + * + * @see PlayerDropItemEvent * @phpstan-extends EntityEvent */ class ItemSpawnEvent extends EntityEvent{ From 331b05c68102b56393122d1910804ce8c084308c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 22:11:21 +0100 Subject: [PATCH 21/28] Improve documentation of EntitySpawnEvent and EntityDespawnEvent --- src/event/entity/EntityDespawnEvent.php | 4 +++- src/event/entity/EntitySpawnEvent.php | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/event/entity/EntityDespawnEvent.php b/src/event/entity/EntityDespawnEvent.php index 0fd0da8a0..73d73dd84 100644 --- a/src/event/entity/EntityDespawnEvent.php +++ b/src/event/entity/EntityDespawnEvent.php @@ -26,7 +26,9 @@ namespace pocketmine\event\entity; use pocketmine\entity\Entity; /** - * Called when a entity is despawned + * Called when an entity is removed from the world. This could be for a variety of reasons, including chunks being + * unloaded, entity death, etc. + * * @phpstan-extends EntityEvent */ class EntityDespawnEvent extends EntityEvent{ diff --git a/src/event/entity/EntitySpawnEvent.php b/src/event/entity/EntitySpawnEvent.php index 89e660a42..6feab8cad 100644 --- a/src/event/entity/EntitySpawnEvent.php +++ b/src/event/entity/EntitySpawnEvent.php @@ -26,7 +26,8 @@ namespace pocketmine\event\entity; use pocketmine\entity\Entity; /** - * Called when a entity is spawned + * Called when an entity is added to the world. This might be a new entity or an entity loaded from storage. + * * @phpstan-extends EntityEvent */ class EntitySpawnEvent extends EntityEvent{ From 645c44ae9c8becc9283ca0a21a2d9cf5c5241492 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 22:41:28 +0100 Subject: [PATCH 22/28] Explosion: remove unused variables --- src/world/Explosion.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/world/Explosion.php b/src/world/Explosion.php index 4f007deaa..3049b5be7 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -95,9 +95,6 @@ class Explosion{ $blockFactory = BlockFactory::getInstance(); - $currentChunk = null; - $currentSubChunk = null; - $mRays = $this->rays - 1; for($i = 0; $i < $this->rays; ++$i){ for($j = 0; $j < $this->rays; ++$j){ From 7eaf1246a08ec6f3f1bceee78af0b6d3f379c5c6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 22:43:26 +0100 Subject: [PATCH 23/28] Explosion: cap yield at 100% this could overflow if the explosion size is less than 1. While this currently doesn't have any negative effects, if we decided to support >100% yield, this would cause some issues. --- src/world/Explosion.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/world/Explosion.php b/src/world/Explosion.php index 3049b5be7..660c6663c 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -42,6 +42,7 @@ use pocketmine\world\utils\SubChunkExplorer; use pocketmine\world\utils\SubChunkExplorerStatus; use function ceil; use function floor; +use function min; use function mt_rand; use function sqrt; @@ -154,7 +155,7 @@ class Explosion{ */ public function explodeB() : bool{ $source = (new Vector3($this->source->x, $this->source->y, $this->source->z))->floor(); - $yield = (1 / $this->size) * 100; + $yield = min(100, (1 / $this->size) * 100); if($this->what instanceof Entity){ $ev = new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield); From afc6e8878d8c75e0c785ee94b37c6d76bb370655 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 22:44:45 +0100 Subject: [PATCH 24/28] EntityExplodeEvent: clamp yield in range 0-100 --- src/event/entity/EntityExplodeEvent.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/event/entity/EntityExplodeEvent.php b/src/event/entity/EntityExplodeEvent.php index 6daf923cc..fc4e63bf1 100644 --- a/src/event/entity/EntityExplodeEvent.php +++ b/src/event/entity/EntityExplodeEvent.php @@ -53,6 +53,9 @@ class EntityExplodeEvent extends EntityEvent implements Cancellable{ $this->entity = $entity; $this->position = $position; $this->blocks = $blocks; + if($yield < 0.0 || $yield > 100.0){ + throw new \InvalidArgumentException("Yield must be in range 0.0 - 100.0"); + } $this->yield = $yield; } @@ -80,6 +83,9 @@ class EntityExplodeEvent extends EntityEvent implements Cancellable{ } public function setYield(float $yield) : void{ + if($yield < 0.0 || $yield > 100.0){ + throw new \InvalidArgumentException("Yield must be in range 0.0 - 100.0"); + } $this->yield = $yield; } } From 3dd7c09351050e22c764e65985f1f2894c8ad5b3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 23:00:34 +0100 Subject: [PATCH 25/28] Improve documentation of ExplosionPrimeEvent and EntityExplodeEvent --- src/event/entity/EntityExplodeEvent.php | 21 +++++++++++++++++++-- src/event/entity/ExplosionPrimeEvent.php | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/event/entity/EntityExplodeEvent.php b/src/event/entity/EntityExplodeEvent.php index fc4e63bf1..fa69d2fbf 100644 --- a/src/event/entity/EntityExplodeEvent.php +++ b/src/event/entity/EntityExplodeEvent.php @@ -31,7 +31,11 @@ use pocketmine\utils\Utils; use pocketmine\world\Position; /** - * Called when a entity explodes + * Called when an entity explodes, after the explosion's impact has been calculated. + * No changes have been made to the world at this stage. + * + * @see ExplosionPrimeEvent + * * @phpstan-extends EntityEvent */ class EntityExplodeEvent extends EntityEvent implements Cancellable{ @@ -47,7 +51,8 @@ class EntityExplodeEvent extends EntityEvent implements Cancellable{ protected $yield; /** - * @param Block[] $blocks + * @param Block[] $blocks + * @param float $yield 0-100 */ public function __construct(Entity $entity, Position $position, array $blocks, float $yield){ $this->entity = $entity; @@ -64,6 +69,8 @@ class EntityExplodeEvent extends EntityEvent implements Cancellable{ } /** + * Returns a list of blocks destroyed by the explosion. + * * @return Block[] */ public function getBlockList() : array{ @@ -71,6 +78,8 @@ class EntityExplodeEvent extends EntityEvent implements Cancellable{ } /** + * Sets the blocks destroyed by the explosion. + * * @param Block[] $blocks */ public function setBlockList(array $blocks) : void{ @@ -78,10 +87,18 @@ class EntityExplodeEvent extends EntityEvent implements Cancellable{ $this->blocks = $blocks; } + /** + * Returns the percentage chance of drops from each block destroyed by the explosion. + * @return float 0-100 + */ public function getYield() : float{ return $this->yield; } + /** + * Sets the percentage chance of drops from each block destroyed by the explosion. + * @param float $yield 0-100 + */ public function setYield(float $yield) : void{ if($yield < 0.0 || $yield > 100.0){ throw new \InvalidArgumentException("Yield must be in range 0.0 - 100.0"); diff --git a/src/event/entity/ExplosionPrimeEvent.php b/src/event/entity/ExplosionPrimeEvent.php index 68bec6fa4..cffc44a34 100644 --- a/src/event/entity/ExplosionPrimeEvent.php +++ b/src/event/entity/ExplosionPrimeEvent.php @@ -28,7 +28,11 @@ use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; /** - * Called when a entity decides to explode + * Called when an entity decides to explode, before the explosion's impact is calculated. + * This allows changing the force of the explosion and whether it will destroy blocks. + * + * @see EntityExplodeEvent + * * @phpstan-extends EntityEvent */ class ExplosionPrimeEvent extends EntityEvent implements Cancellable{ From 2ec65ba799c0d0f2ed593cd598ae7f9b32572faa Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 May 2022 23:22:04 +0100 Subject: [PATCH 26/28] ExplosionPrimeEvent: require a positive explosion radius --- src/event/entity/ExplosionPrimeEvent.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/event/entity/ExplosionPrimeEvent.php b/src/event/entity/ExplosionPrimeEvent.php index cffc44a34..4856041bc 100644 --- a/src/event/entity/ExplosionPrimeEvent.php +++ b/src/event/entity/ExplosionPrimeEvent.php @@ -44,6 +44,9 @@ class ExplosionPrimeEvent extends EntityEvent implements Cancellable{ private $blockBreaking; public function __construct(Entity $entity, float $force){ + if($force <= 0){ + throw new \InvalidArgumentException("Explosion radius must be positive"); + } $this->entity = $entity; $this->force = $force; $this->blockBreaking = true; @@ -54,6 +57,9 @@ class ExplosionPrimeEvent extends EntityEvent implements Cancellable{ } public function setForce(float $force) : void{ + if($force <= 0){ + throw new \InvalidArgumentException("Explosion radius must be positive"); + } $this->force = $force; } From 7bbb2617c8b0af24ffd6df86041e487eed9fb889 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 22 May 2022 16:12:12 +0100 Subject: [PATCH 27/28] Release 4.3.4 --- changelogs/4.3.md | 32 ++++++++++++++++++++++++++++++++ src/VersionInfo.php | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/changelogs/4.3.md b/changelogs/4.3.md index b7149c752..3ea7c1b23 100644 --- a/changelogs/4.3.md +++ b/changelogs/4.3.md @@ -43,3 +43,35 @@ Released 16th May 2022. - Fixed server crash when chunks are unloaded during chunk generation callbacks - Fixed dead coral fan items placing coral fans in the wrong orientation. - Fixed max stack size of boat items. + +# 4.3.4 +Released 22nd May 2022. + +## Fixes +- Fixed `difficulty` in `server.properties` having no effect - it's now applied to newly generated worlds. + - Note: this setting still doesn't behave the same way as vanilla due to potential disruption to existing servers. +- Fixed paintings not working in newly generated worlds and some other cases. +- Fixed inventory window switching breaking the inventory UI in some cases (e.g. pressing E while clicking a chest). +- Fixed minecart items incorrectly stacking. +- Fixed incorrect light levels in translucent blocks at the top of the world. +- Fixed teleporting sleeping players causing broken behaviour on the sleeping player's client. +- Fixed `EntityExplodeEvent->setYield()` accepting values outside the range 0-100. +- Fixed `ExplosionPrimeEvent->setForce()` accepting negative values (later resulting in crashes). + +## Documentation +- Updated documentation for the following events: + - `CommandEvent` + - `EntityDespawnEvent` + - `EntityExplodeEvent` + - `EntitySpawnEvent` + - `ExplosionPrimeEvent` + - `InventoryTransactionEvent` + - `ItemDespawnEvent` + - `ItemSpawnEvent` + - `PlayerCommandPreprocessEvent` + - `PlayerDropItemEvent` + - `PlayerItemHeldEvent` + - `PlayerKickEvent` + - `PlayerQuitEvent` + - `PlayerTransferEvent` + - `UpdateNotifyEvent` diff --git a/src/VersionInfo.php b/src/VersionInfo.php index d414abd25..6d8830744 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -32,7 +32,7 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; public const BASE_VERSION = "4.3.4"; - public const IS_DEVELOPMENT_BUILD = true; + public const IS_DEVELOPMENT_BUILD = false; public const BUILD_CHANNEL = "stable"; private function __construct(){ From 1591881bf28b816776be1a7dc5e254a09bf9377b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 22 May 2022 16:12:24 +0100 Subject: [PATCH 28/28] 4.3.5 is next --- src/VersionInfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 6d8830744..c82ffb643 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -31,8 +31,8 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; - public const BASE_VERSION = "4.3.4"; - public const IS_DEVELOPMENT_BUILD = false; + public const BASE_VERSION = "4.3.5"; + public const IS_DEVELOPMENT_BUILD = true; public const BUILD_CHANNEL = "stable"; private function __construct(){