1. Go to this page and download the library: Download nicktee/taskondemand library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nicktee / taskondemand example snippets
use Nicktee\TaskOnDemand\TaskOnDemand;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\EventPriority;
TaskOnDemand::getInstance()->registerConditionalEvent(
$this, // your plugin instance
"player_quit_trigger", // unique identifier for this conditional event
PlayerQuitEvent::class, // event class to listen for
function (PlayerQuitEvent $event, array $parameters): bool {
// return true if this event matches the desired condition
// (return true unconditionally if you don't need a condition)
return $event->getPlayer()->getUniqueId()->toString() === $parameters["player"];
},
EventPriority::NORMAL, // optional; defaults to EventPriority::MONITOR
false, // optional; whether to handle cancelled events (default: false)
);
use Nicktee\TaskOnDemand\TaskOnDemand;
$duration = 15 * 20; // 15 seconds in ticks
$player->sendMessage("You are now in combat. Do not log out!");
TaskOnDemand::getInstance()->scheduleConditionalTask(
$this, // your plugin instance
"combat_log", // unique identifier for this conditional task
function(?Event $event, array $parameters) use($player): void {
if ($event === null) {
// Task was run by delay or force (not triggered by event)
$player->sendMessage("You are no longer in combat.");
} else {
// Task was triggered early by event (e.g., player quit)
$player->kill();
}
},
["player_quit_trigger"], // events that can trigger this task
["player" => $player->getUniqueId()->toString()], // parameters passed to condition
$duration // delay in ticks
);
use Nicktee\TaskOnDemand\TaskOnDemand;
TaskOnDemand::getInstance()->executeConditionalTask(
"combat_log",
["player" => $player->getUniqueId()->toString()]
);
use Nicktee\TaskOnDemand\TaskOnDemand;
TaskOnDemand::getInstance()->removeConditionalTask(
"combat_log",
["player" => $player->getUniqueId()->toString()]
);
if (TaskOnDemand::getInstance()->hasConditionalTask(
"combat_log",
["player" => $player->getUniqueId()->toString()]
)) {
$player->sendMessage("You're still in combat!");
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.