I think the problem is that the function in the main class don't waits for the end of the AsyncTask. How can I return it if the AsyncTask is done? Otherwise the variable is always empty
I have this in my AsyncTask. There I can echo the result. But I want to display it on command (using a function)
call back a main plugin with a oncomplete there which you may continue displaying it, ex sending the cmd back to the player or smth since PMMP have none of these weird Promises dohickies which is suppose to get return on a pending task, you are probably wondering what that is, dont ask me maybe google can help but i never touched these stuff because pmmp have none of these, i only know they exist on some libs
I don't really understand... Can u give me an example? Or is there a better way to get the status of another server?
like on complete under async task completed call server->getplugin->yourownplugin->onComplete($results) if you dont get it, nether do i
But how can I get the result of onComplete in the main task?? I want to get the result of the starter task (getStatus() in the main)
PHP: private $ip, $port, $timeout, $server, $status;public function __construct(Server $server, $ip, $port, $timeout = 10){ $this->ip = $ip; $this->port = $port; $this->timeout = $timeout; $this->server = $server;}public function onRun(){ $minecraft = @fsockopen($this->ip, $this->port, $this->timeout); $this->status = $minecraft == true ? "online" : "offline";}public function onCompletion(Server $server){ $server->getLogger()->notice(" Background task has finished. The output was: ".$this->status); $server->getPluginManager()->getPlugin("pluginName")->result = $this->status;}
No. I already tried that. And it doesn't work because when I run the command, the variable is empty. And if I do /info list, I see more than one server
if you wont get it, i dont think you will ever get it from me something along the lines of jasonwynn10 example but using a function called onComplete (or anything you will) instate of a variable
That's in my AsyncTask ... PHP: public function onCompletion(Server $server){ $server->getLogger()->notice(" Background task has finished. The output was: ".$this->status); $server->getPluginManager()->getPlugin("MyPlugin")->onComplete() = $this->status;} It works. But I don't get it in the main task. I could add onComplete($status). But I want to return it in the main task :/
I think u really understand what I want to do. 1. I start the AsyncTask in a function (getStatus(){}) in the main Class. 2. The AsyncTask works correctly and gives the right result onCompletion(){} 3. In the getStatus() task I want to get the result of the startet AsyncTask (doesn't work). I start the AsyncTask using this: PHP: $status = $this->getServer()->getScheduler()->scheduleAsyncTask(new StatusTask($ip, $port, $timeout));//Now I want to return $this->getResult () from the task in this function
PHP: $status = $this->getServer()->getScheduler()->scheduleAsyncTask($task = new StatusTask($ip, $port, $timeout)); // status is null$result = $task->getResult();
I don't think you should do something as complex as this. Threading/Async stuff is quite advanced and you don't seem to understand it. You just need to pass your stuff back into your plugin class. If you need an example, you may want to look at this https://github.com/robske110/SignSe.../SSS/src/robske_110/SSS/SSSAsyncTask.php#L120 https://github.com/robske110/SignSe...SS/src/robske_110/SSS/SignServerStats.php#L66
I got it to a class in the main class. But how can I display it now on Command? PHP: public function asyncTaskCallBack($data) {echo $data;}
It's not only on command. I run the function to get the status on command and to refresh status signs. How would u do that?
you can only do it AFTER command, after the callback query have resolved there you just need to tell player and update sign inside the callback/completed function