Hello everybody I want some help for my plugin after my player use the command /getvipforfree i want that they have vip for 60 min but after 60 min the vip permision for that person will be removed
Note that it could be cheated if you'd use a delayed task with 60 minutes and something happens for example a server restart.
Better save the time when issuing the command and then check every few ticks if the current time >= saved time +1
$e? A task is something different than an event. You have to either pass it on the task call, or foreach the online players.
Schedule a delayed task for 20*60*60 ticks. (20 ticks = 1second) Thing is, it won't be EXACTLY 60 minutes if you use a delayed task, not because my calculations aren't exact or anything, but because server's tick is not the most accurate way of timing your tasks. Ticks can change over time (due to lag). The alMOST accurate way would be a repeating task that's ran every 20 ticks (1second), with calculation of UNIX timestamp.
like this https://github.com/LegendOfMCPE/EssentialsPE/blob/master/src/EssentialsPE/Tasks/TPRequestTask.php
What I would do would be scheduling a repeatingtask on enable every second or so. In that repeating task check for every online player if time() - $times->get($playername) is equal to or bigger than 3600. (time() in secs right?) Then if it is remove the VIP. Then oncommand save time() in a player name using something like this: $times->set($playername, time()). Hope that helps.
You'll also have to check if the time is already set when issuing the cmd, so players can't cheat a longer time.
This is an exempt out of my delayedCMDs plugin: PHP: class delayedCMDsExecutor extends PluginTask{ public function __construct(rootPlugin $main, $parent){ parent::__construct($main); $this->server = $parent->server; $this->delayedCMDs = $parent; } public function onRun($currentTick){ $currTime = time(); foreach($this->delayedCMDs->getDelayedCMDs() as $key => $delayedCMDdata){ $scheduleTime = $delayedCMDdata[0]; $delay = $delayedCMDdata[1]; if($currTime >= $scheduleTime + $delay){ $command = $delayedCMDdata[2]; $this->server->dispatchCommand(new ConsoleCommandSender(), $command); $this->delayedCMDs->removeCmd($key); } } }}
The best way would be Lambo's method from CombatLogger using '&' (reference). MainClass...(or not?) PHP: public $illuminati = [];public function onEnable() { $this->getServer()->getScheduler()->scheduleRepeatingTask(new Illuminati($this, $this->illuminati), 20);}public function setPermission(Player $player, string $permission, int $time = 60) { //Time is in minutes. $player->addAttachment($permission); $time = time() + ($time*60);//is there a better way? $this->illuminati[$player->getName()] = ["time" => $time, "permission" => $permission];} Illuminati.php PHP: private $illuminati;public function __construct(MainClass $plugin, &$illuminati) { $this->illuminati = &$illuminati; parent::__construct($plugin);}public function onRun($tick) { foreach ($this->illuminati as $data) { if ($data["time"] - time() <= 0) { $player = array_search($data, $this->illuminati); $permission = $data["permission"]; Server::getInstance()->getPlayer($player)->removeAttachment($permission); unset($this->illuminati[$player]); } }} pro spooner and spoonfeeder. (if u know what I mean...spooner e.e...lywin)