Skip to content

Add an API to remove a player's item cooldown#7006

Merged
dktapps merged 1 commit intopmmp:minor-nextfrom
ItsMax123:remove-item-cooldown
Mar 19, 2026
Merged

Add an API to remove a player's item cooldown#7006
dktapps merged 1 commit intopmmp:minor-nextfrom
ItsMax123:remove-item-cooldown

Conversation

@ItsMax123
Copy link
Copy Markdown
Contributor

@ItsMax123 ItsMax123 commented Jan 30, 2026

Currently, plugins cannot remove a player's server-side item cooldown. The only publicly available API is Player->resetItemCooldown(Item $item, ?int $ticks = null), which intentionally only supports cooldown values greater than 0.

Changes

API changes

  • The following API methods have been added:
    • public Player->removeItemCooldown(Item $item) : void - removes the player's cooldown time for the given item

Tests

This testing plugin removes the cooldown on ender pearls and goat horns after 10 and 40 ticks respectively.
Video: https://github.com/user-attachments/assets/0f716c52-1369-486b-8062-902f97504a24

<?php

declare(strict_types=1);

namespace Max\Test;

use pocketmine\event\Listener;
use pocketmine\event\player\PlayerItemUseEvent;
use pocketmine\item\EnderPearl;
use pocketmine\item\GoatHorn;
use pocketmine\plugin\PluginBase;
use pocketmine\scheduler\ClosureTask;

class Test extends PluginBase implements Listener {
    public function onEnable(): void {
        $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function onItemUse(PlayerItemUseEvent $event): void {
        $item = $event->getItem();
        if ($item instanceof EnderPearl) {
            $delay = 10;
        } elseif ($item instanceof GoatHorn) {
            $delay = 40;
        } else {
            return;
        }
        $player = $event->getPlayer();
        $this->getScheduler()->scheduleDelayedTask(new ClosureTask(function() use ($player, $item) {
            $player->removeItemCooldown($item);
        }), $delay);
    }
}

@ItsMax123 ItsMax123 requested a review from a team as a code owner January 30, 2026 06:23
@ItsMax123
Copy link
Copy Markdown
Contributor Author

ItsMax123 commented Jan 30, 2026

Also, thoughts on adding a PlayerItemCooldownStartEvent? That way plugins can override an item's cooldown without having to do hacky workarounds.
I can add it to this PR or create a new one if you'd like.

@dktapps
Copy link
Copy Markdown
Member

dktapps commented Feb 2, 2026

Code looks OK but I don't know if this will actually work. Needs playtesting

@ItsMax123
Copy link
Copy Markdown
Contributor Author

Ok, I added tests to the original post.

@kaxyum
Copy link
Copy Markdown

kaxyum commented Mar 8, 2026

Also, thoughts on adding a PlayerItemCooldownStartEvent? That way plugins can override an item's cooldown without having to do hacky workarounds. I can add it to this PR or create a new one if you'd like.

Any news about that ? I think it is a good idea

@dktapps dktapps merged commit 811297f into pmmp:minor-next Mar 19, 2026
25 checks passed
@dktapps dktapps added Category: API Related to the plugin API Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Category: API Related to the plugin API Type: Enhancement Contributes features or other improvements to PocketMine-MP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants