Merge 'minor-next' into 'major-next'

Automatic merge performed by: https://github.com/pmmp/RestrictedActions/actions/runs/11392123557
This commit is contained in:
github-actions
2024-10-17 19:59:15 +00:00
20 changed files with 555 additions and 11 deletions

View File

@ -284,7 +284,11 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
protected string $locale = "en_US";
protected int $startAction = -1;
/** @var int[] ID => ticks map */
/**
* @phpstan-var array<int|string, int>
* @var int[] stateId|cooldownTag => ticks map
*/
protected array $usedItemsCooldown = [];
private int $lastEmoteTick = 0;
@ -702,7 +706,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
*/
public function getItemCooldownExpiry(Item $item) : int{
$this->checkItemCooldowns();
return $this->usedItemsCooldown[$item->getStateId()] ?? 0;
return $this->usedItemsCooldown[$item->getCooldownTag() ?? $item->getStateId()] ?? 0;
}
/**
@ -710,7 +714,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
*/
public function hasItemCooldown(Item $item) : bool{
$this->checkItemCooldowns();
return isset($this->usedItemsCooldown[$item->getStateId()]);
return isset($this->usedItemsCooldown[$item->getCooldownTag() ?? $item->getStateId()]);
}
/**
@ -719,7 +723,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
public function resetItemCooldown(Item $item, ?int $ticks = null) : void{
$ticks = $ticks ?? $item->getCooldownTicks();
if($ticks > 0){
$this->usedItemsCooldown[$item->getStateId()] = $this->server->getTick() + $ticks;
$this->usedItemsCooldown[$item->getCooldownTag() ?? $item->getStateId()] = $this->server->getTick() + $ticks;
$this->getNetworkSession()->onItemCooldownChanged($item, $ticks);
}
}