i use this code in the task, but it excutes one time only, why? idk PHP: <?phpnamespace onevsoneda;use pocketmine\scheduler\PluginTask;use onevsoneda\Main;use pocketmine\utils\{ TextFormat, Config};use pocketmine\level\{Position, Level};class GameSender extends PluginTask{ public $plugin; public function __construct(Main $plugin){ parent::__construct($plugin); $this->plugin = $plugin; } public function onRun(int $currentTick){ $cf = new Config($this->plugin->getDataFolder()."/config.yml", Config::YAML); $arenas = $cf->get("arenas"); if(!empty($arenas)){ foreach($arenas as $arena){ $time = $cf->get($arena."PlayTime"); $timeToStart = $cf->get($arena."StartTime"); $levelArena = $this->plugin->getServer()->getLevelByName($arena); if($levelArena instanceof Level){ $allplayers = $this->plugin->getServer()->getOnlinePlayers(); $playersArena = array(); foreach($allplayers as $play){ if($play->getLevel()->getFolderName() == $arena){ array_push($playersArena, $play); } } if(count($this->plugin->getServer()->getLevelByName($arena)->getPlayers()) == 0){ $cf->set($arena."PlayTime", 400); $cf->set($arena."StartTime", 20); } else { if(count($this->plugin->getServer()->getLevelByName($arena)->getPlayers()) >= 2){ if($timeToStart > 0){ $timeToStart--; foreach($this->plugin->getServer()->getLevelByName($arena)->getPlayers() as $pl){ $pl->sendTip(TextFormat::YELLOW."0 : ".$timeToStart); } if($timeToStart <= 0){ $cf = new Config($this->plugin->getDataFolder()."/config.yml", Config::YAML); $cf->set($arena."Move", true); $cf->set($arena."StartTime", $timeToStart); $cf->save(); } else { $aop = count($levelArena->getPlayers()); if($aop == 1){ foreach($this->plugin->getServer()->getLevelByName($arena)->getPlayers() as $pl){ foreach($this->plugin->getServer()->getOnlinePlayers() as $plpl){ $plpl->sendMessage($this->plugin->prefix.TextFormat::GREEN.$pl->getName()." Won in 1vs1-DA, arena: ".$pl->getLevel()->getFolderName()); } } $cf->set($arena."PlayTime", 400); $cf->set($arena."StartTime", 20); $cf->save(); } $time--; if($time == 0){ foreach($this->plugin->getServer()->getLevelByName($name)->getPlayers() as $pla){ $pla->teleport($this->plugin->getServer()->getDefaultLevel()->getSafeSpawn()); $pla->sendMessage($this->plugin->prefix."§aYou won the game!"); } } } } } } } } } $cf->save(); }}?> and i'm using scheduleRepeatingTask When the there is 2 players in the arena the sendTip() works but the seconds dosnt decrease, decreases only 1 time.
what you mean by executing only one time? this should work.. use that to register the task PHP: $this->getServer()->getScheduler()->scheduleRepeatingTask(new GameSender($this), 20); if you think it's executing only one time, maybe you can add a Popup into the task to test, but that's it's not supposed to happen there
Yeah, but have you tested the task correctly? I mean you don't explain what is executing only one time, this should work correctly, use sendPopup to test if the popup is receiving every time or only one time as you sayd, if so, the task is working, the problem is not the task but your code is.
The problem is that you update variable from config every time you decrease it. You should load variable from config once and then decrement it. Look at this thread, i have the same issue one day.. https://forums.pmmp.io/threads/how-...e-skywarsdodo-from-kaitododo.5449/#post-48857 You have several ways of doing this: - register the $config->get variable on construct_ or - you can register in onRun function, but you need to use $config->set and $config->save if you want that update everytime
I think you're getting a code example from an old plugin, or maybe an ImagicalMine plugin, because in the old days this should work good, but now you need to use $config->save to update everytime, i don't know why but it's update. #blameDylanKTaylor