Hello I've written a little plugin with a blaze rod and cooldown but the cooldown doesnt work Here is the file while I dont know where the error is
I can't fix it but here's another way to post your code! Spoiler: Main.php PHP: <?phpnamespace JackboyPlay\SpeedRod;use pocketmine\Server;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\utils\TextFormat;use pocketmine\level\particle\FloatingTextParticle;use pocketmine\level;use pocketmine\level\Position\getLevel;use pocketmine\level\particle\Particle;use pocketmine\Player;use pocketmine\plugin\Plugin;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\item\Item;use pocketmine\event\player\PlayerItemHeldEvent;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\event\player\PlayerQuitEvent;use pocketmine\math\Vector3;use pocketmine\level\Position;use pocketmine\utils\Config;use pocketmine\event\player\PlayerPreLoginEvent;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\event\player\PlayerChatEvent;use pocketmine\event\entity\EntityArmorChangeEvent;use pocketmine\event\entity\EntityDamageByEntityEvent;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\event\player\PlayerMoveEvent;use pocketmine\event\player\PlayerDeathEvent;use pocketmine\event\player\PlayerCommandPreprocessEvent;use pocketmine\event\block\BlockBreakEvent;use pocketmine\event\block\BlockPlaceEvent;use pocketmine\tile\Sign;use pocketmine\entity\Effect;use pocketmine\scheduler\PluginTask;use pocketmine\event\player\PlayerDropItemEvent;use pocketmine\event\player\PlayerHungerChangeEvent;use pocketmine\event\player\PlayerExperienceChangeEvent;use pocketmine\command\ConsoleCommandSender;class Main extends PluginBase implements Listener{ public $blaze = array(); public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getServer()->getScheduler()->scheduleRepeatingTask(new speedrod($this), 20); $this->getLogger()->info("§bSpeedRod §evon §aJackboyPlay §2aktiviert!"); if(!file_exists($this->getDataFolder() . "config.yml")) { @mkdir($this->getDataFolder()); file_put_contents($this->getDataFolder() . "config.yml",$this->getResource("config.yml")); } } public function onDisable() { $this->getConfig()->save(); $this->getLogger()->info("§bSpeedRod §evon §aJackboyPlay §4deaktiviert!"); } public function onCommand(CommandSender $sender, Command $command, $label, array $args) { if($command->getName() == "speedrod" || $command->getName() == "sr"){ $sender->sendMessage("§aSpeedrod Version §b1§a.§b0 §avon §eJackboyPlay"); } } public function onItem(PlayerItemHeldEvent $event){ $player = $event->getPlayer(); if($event->getItem()->getId() == 369){ if(!in_array($player->getName(), $this->blaze)){ $player->sendPopup("§cKlick auf den Boden für §aSpeed"); } if(in_array($player->getName(), $this->blaze)){ $player->sendPopup("§cBenutzung in §e" . $this->blaze[$player->getName()] . " §cSekunden!"); } } } public function onKlick(PlayerInteractEvent $event){ $player = $event->getPlayer(); if($event->getAction() == PlayerInteractEvent::RIGHT_CLICK_AIR || $event->getAction() == PlayerInteractEvent::RIGHT_CLICK_BLOCK){ if($player->getInventory()->getItemInHand()->getId() == 369){ if(in_array($player->getName(), $this->blaze)){ $player->sendMessage("§cDu kannst den Stab erst in §e" . $this->blaze[$player->getName()] . " §cSekunden benutzen!"); } if(!in_array($player->getName(), $this->blaze)){ $this->blaze[$player->getName()] = $this->getConfig()->get("Cooldown"); $this->blaze[] = $player->getName(); $player->sendMessage("§cDu hast nun §aSpeed §cfür §e" . $this->getConfig()->get("Dauer") . " §c Sekunden mit der Stärke§e " . $this->getConfig()->get("Stärke") . "§c erhalten!"); $player->addEffect(Effect::getEffect(1)->setAmplifier($this->getConfig()->get("Stärke"))->setDuration($this->getConfig()->get("Dauer") * 20)->setVisible(true)); } } } }}class speedrod extends PluginTask{ public function __construct(Plugin $owner){ parent::__construct($owner); } public function onRun($currentTick){ foreach ($this->getOwner()->getServer()->getOnlinePlayers() as $p){ if(in_array($p->getName(), $this->getOwner()->blaze)){ $this->getOwner()->blaze[$p->getName()] = $this->getOwner()->blaze[$p->getName()] - 1; } if($this->getOwner()->blaze[$p->getName()] == 0){ unset($this->getOwner()->blaze[array_search($p->getName(), $this->getOwner()->blaze)]); } } }}
PHP: $startTime = time();// More code...if((time() - $startTime) <= $integer){ // Do stuff...}else{ // Do stuff...} You can use PHP tags, instead of CODE tags.