Hello, I have been going through the tutorial at learn-mc.ga/MCPE/ and its a great learning resource. From what I have learned there I have started to play with a test plugin and am running into trouble getting my task to execute. Here is my the reference to calling the task Command with the task PHP: public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ if($cmd->getName() == "info"){ if(!$sender instanceof Player){ $sender->sendMessage("This Command Only Works for players! Please perform this command IN GAME!"); }else{ $sender->getInventory()->addItem(Item::get(364,0,4)); $sender->sendMessage("You have just recieved 4 steak!"); $task = new tasks\remindertext($this, $sender->getName()); // Create the new class Task by calling $this->getServer()->getScheduler()->scheduleDelayedTask($task, 5*20); // Counted in ticks (1 second = 20 ticks) } } return true; } remindertext.php file located in Bago/tasks PHP: <?phpnamespace Bago\tasks;use pocketmine\scheduler\PluginTask;use Bago\Main;class remindertext extends PluginTask {public function __construct(Main $main, string $playername) { parent::__construct($main); $this->playername = $playername;}public function onRun($tick) { // $player = $this->getOwner()->getServer()->getPlayer($this->playername()); if($player instanceof Player) { $player->sendMessage("10 seconds has past!"); }}} When I then go into the game do the /info command it works fine, gives me the steaks then this error in console occurs. [Server thread/CRITICAL]: Could not execute task Bago\tasks\remindertext: Call to undefined method Bago\tasks\remindertext:layername() [Server thread/CRITICAL]: Error: "Call to undefined method Bago\tasks\remindertext:layername()" (EXCEPTION) in "/phar_BagoDev_uGuj5mz8tuc6lYm.phar/src/Bago/tasks/remindertext" at line 16 I have tried to use pocketmine/player and server in the remindertext.php and that doesnt fix it nor should I need to call these since they are already called in the Main.php I believe but I tried just in case. Thanks for your help in advance! -Bago
Thank you for the information! I see why that would cause the issue with the error. I have updated the 2nd file to read like this PHP: <?phpnamespace Bago\tasks;use pocketmine\scheduler\PluginTask;use Bago\Main;class remindertext extends PluginTask {public function __construct(Main $main, string $playername) { parent::__construct($main); $this->playername = $playername;}public function onRun($tick) { // $player = $this->getOwner()->getServer()->getPlayer($this->playername); if($player instanceof Player) { $player->sendMessage("10 seconds has past!"); }}} Now I do not get the error YaY! however the task never occurs and there is no error in console. Humm..... -Bago
Thanks! I know I need to update the text to 5 seconds. I just wanted to change the ticks so I didnt have to wait so long to see if it worked. It must be a conflict with some other part of the Main.php although the only other commands are join event and plugin loading messages in console. Here is the full code for the Main.php file. PHP: <?phpnamespace Bago;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\event\player\PlayerQuitEvent;use pocketmine\utils\TextFormat;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\Player;use pocketmine\Server;use pocketmine\item\Item;class Main extends PluginBase implements Listener{ public function onLoad(){ $this->getLogger()->info(TextFormat::GREEN."Bago's Plugin Loading"); } public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this,$this); $this->getLogger()->info(TextFormat::GREEN."Bago's Plugin Enabled"); } public function onDisable(){ $this->getLogger()->info(TextFormat::GREEN."Bago's Plugin Disabled"); } public function onJoin(PlayerJoinEvent $event){ $player = $event->getPlayer(); $name = $player->getName(); $this->getServer()->broadcastMessage(TextFormat::RED."$name Joined Bagos test Server! Awesome!"); } public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ if($cmd->getName() == "info"){ if(!$sender instanceof Player){ $sender->sendMessage("This Command Only Works for players! Please perform this command IN GAME!"); }else{ $sender->getInventory()->addItem(Item::get(364,0,4)); $sender->sendMessage("You have just recieved 4 steak!"); $task = new tasks\remindertext($this, $sender->getName()); // Create the new class Task by calling $this->getServer()->getScheduler()->scheduleDelayedTask($task, 5*20); // Counted in ticks (1 second = 20 ticks) } } return true; }}