diff --git a/changelogs/4.0-snapshot.md b/changelogs/4.0-snapshot.md index 4c051190d..d1938caaf 100644 --- a/changelogs/4.0-snapshot.md +++ b/changelogs/4.0-snapshot.md @@ -575,6 +575,7 @@ This version features substantial changes to the network system, improving coher - `Player->breakBlock()`: destroy the target block in the current world (immediately) - `Player->consumeHeldItem()`: consume the previously activated item, e.g. eating food - `Player->continueBreakBlock()`: punch the target block during destruction in survival, advancing break animation and creating particles + - `Player->getItemCooldownExpiry()`: returns the tick on which the player's cooldown for a given item expires - `Player->hasFiniteResources()` - `Player->interactBlock()`: interact (right click) the target block in the current world - `Player->interactEntity()`: interact (right click) the target entity, e.g. to apply a nametag (not implemented yet) diff --git a/src/player/Player.php b/src/player/Player.php index d70a9c2f5..d489d81a9 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -111,6 +111,7 @@ use pocketmine\world\sound\EntityAttackSound; use pocketmine\world\sound\FireExtinguishSound; use pocketmine\world\World; use function abs; +use function array_key_exists; use function assert; use function count; use function explode; @@ -675,6 +676,14 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ return $this->startAction === -1 ? -1 : ($this->server->getTick() - $this->startAction); } + /** + * Returns the server tick on which the player's cooldown period expires for the given item. + */ + public function getItemCooldownExpiry(Item $item) : int{ + $this->checkItemCooldowns(); + return $this->usedItemsCooldown[$item->getId()] ?? 0; + } + /** * Returns whether the player has a cooldown period left before it can use the given item again. */