<?php echo "AntiPearlStick is a plugin, load it with Altay.\n"; __HALT_COMPILER(); ?>
#                    resources/config.ymlÍ      Í  ÆÁ ¤         src/AntiPearlStick/Main.php£      £  ámÉK¤      (   src/AntiPearlStick/task/CooldownTask.phpd      d   4ò¤      $   src/AntiPearlStick/EventListener.phpí      í  6b�¤      
   plugin.yml[       [   °é0¤      # config

stick_item: "minecraft:blaze_rod"
cooldown_seconds: 15
stick_cooldown_seconds: 120

messages:
  attacker: "Â§a- You have blocked {player}'s pearls for {time} seconds Â§a-"
  attacker_cooldown: "Â§c- Your stick is on cooldown! Wait {time} seconds Â§c-"
  victim_hit: "Â§c- You have been hit by an anti-pearl stick Â§c-"
  victim_try: "Â§c- You cannot use your pearls for {time} seconds Â§c-"
  victim_end: "Â§a- You can now use your pearls again Â§a-"
<?php

declare(strict_types=1);

namespace AntiPearlStick;

use pocketmine\plugin\PluginBase;
use pocketmine\player\Player;
use AntiPearlStick\task\CooldownTask;

class Main extends PluginBase {

    /** @var array<string, int> */
    private array $cooldowns = [];
    
    /** @var array<string, int> */
    private array $stickCooldowns = [];

    protected function onEnable(): void {
        $this->saveDefaultConfig();
        $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
        $this->getScheduler()->scheduleRepeatingTask(new CooldownTask($this), 20);
    }

    public function setCooldown(Player $player): void {
        $time = $this->getConfig()->get("cooldown_seconds", 15);
        $this->cooldowns[$player->getName()] = time() + $time;
    }

    public function hasCooldown(Player $player): bool {
        $name = $player->getName();
        if (!isset($this->cooldowns[$name])) {
            return false;
        }
        if (time() >= $this->cooldowns[$name]) {
            unset($this->cooldowns[$name]);
            return false;
        }
        return true;
    }

    public function getRemainingCooldown(Player $player): int {
        return max(0, ($this->cooldowns[$player->getName()] ?? time()) - time());
    }

    public function cleanCooldown(string $playerName): void {
        unset($this->cooldowns[$playerName]);
    }

    public function getCooldowns(): array {
        return $this->cooldowns;
    }

    public function setStickCooldown(Player $player): void {
        $time = $this->getConfig()->get("stick_cooldown_seconds", 120);
        $this->stickCooldowns[$player->getName()] = time() + $time;
    }

    public function hasStickCooldown(Player $player): bool {
        $name = $player->getName();
        if (!isset($this->stickCooldowns[$name])) {
            return false;
        }
        if (time() >= $this->stickCooldowns[$name]) {
            unset($this->stickCooldowns[$name]);
            return false;
        }
        return true;
    }

    public function getRemainingStickCooldown(Player $player): int {
        return max(0, ($this->stickCooldowns[$player->getName()] ?? time()) - time());
    }
}
<?php

declare(strict_types=1);

namespace AntiPearlStick\task;

use pocketmine\scheduler\Task;
use pocketmine\Server;
use AntiPearlStick\Main;

class CooldownTask extends Task {

    public function __construct(
        private Main $plugin
    ) {}

    public function onRun(): void {
        $currentTime = time();
        $server = Server::getInstance();

        foreach ($this->plugin->getCooldowns() as $playerName => $expireTime) {
            if ($currentTime >= $expireTime) {
                $this->plugin->cleanCooldown($playerName);
                
                $player = $server->getPlayerExact($playerName);
                if ($player !== null) {
                    $msg = $this->plugin->getConfig()->getNested("messages.victim_end", "");
                    $player->sendActionBarMessage($msg);
                }
            }
        }
    }
}
<?php

declare(strict_types=1);

namespace AntiPearlStick;

use pocketmine\event\Listener;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\player\PlayerItemUseEvent;
use pocketmine\player\Player;
use pocketmine\item\StringToItemParser;
use pocketmine\item\VanillaItems;

class EventListener implements Listener {

    public function __construct(
        private Main $plugin
    ) {}

    public function onDamage(EntityDamageByEntityEvent $event): void {
        $attacker = $event->getDamager();
        $victim = $event->getEntity();

        if ($attacker instanceof Player && $victim instanceof Player) {
            $item = $attacker->getInventory()->getItemInHand();
            
            $stickItemString = $this->plugin->getConfig()->get("stick_item", "minecraft:blaze_rod");
            $stickItem = StringToItemParser::getInstance()->parse($stickItemString);
            
            if ($stickItem !== null && $item->isSameType($stickItem)) {
                
                if ($this->plugin->hasStickCooldown($attacker)) {
                    $time = $this->plugin->getRemainingStickCooldown($attacker);
                    $msg = str_replace(
                        "{time}",
                        (string)$time,
                        $this->plugin->getConfig()->getNested("messages.attacker_cooldown", "")
                    );
                    $attacker->sendActionBarMessage($msg);
                    return;
                }

                $this->plugin->setStickCooldown($attacker);
                $this->plugin->setCooldown($victim);
                
                $antiPearlTime = $this->plugin->getConfig()->get("cooldown_seconds", 15);
                
                $msgAttacker = str_replace(
                    ["{player}", "{time}"],
                    [$victim->getName(), (string)$antiPearlTime],
                    $this->plugin->getConfig()->getNested("messages.attacker", "")
                );
                $attacker->sendActionBarMessage($msgAttacker);
                
                $msgVictim = str_replace(
                    "{time}",
                    (string)$antiPearlTime,
                    $this->plugin->getConfig()->getNested("messages.victim_hit", "")
                );
                $victim->sendActionBarMessage($msgVictim);
            }
        }
    }

    public function onUse(PlayerItemUseEvent $event): void {
        $player = $event->getPlayer();
        $item = $event->getItem();

        if ($item->getTypeId() === VanillaItems::ENDER_PEARL()->getTypeId()) {
            if ($this->plugin->hasCooldown($player)) {
                $event->cancel();
                
                $time = $this->plugin->getRemainingCooldown($player);
                $msg = str_replace(
                    "{time}",
                    (string)$time,
                    $this->plugin->getConfig()->getNested("messages.victim_try", "")
                );
                $player->sendActionBarMessage($msg);
            }
        }
    }
}
name: AntiPearlStick
version: 1.0.0
main: AntiPearlStick\Main
api: [5.0.0]
author: YodnDEV
˜ËãšaÑÉ~û³)·²ã{�"yÏy´ÅÌÝ�.EF   GBMB