1: <?php
2: namespace aliuly\common;
3: use aliuly\common\PluginAsyncTask;
4: use pocketmine\plugin\Plugin;
5: use pocketmine\Server;
6: use xPaw\MinecraftQuery;
7: use xPaw\MinecraftQueryException;
8:
9:
10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
21: class QueryAsyncTask extends PluginAsyncTask{
22: protected $host;
23: protected $port;
24: 25: 26: 27: 28: 29: 30:
31: public function __construct(Plugin $owner, $callable, $host, $port= 19132, array $args = []){
32: parent::__construct($owner,$callable,$args);
33: $this->host = $host;
34: $this->port = $port;
35: }
36: public function onRun() {
37: $this->setResult([
38: "host"=>$this->host,
39: "port" => $this->port,
40: "info" => null,
41: "players" => null,
42: ]);
43: $Query = new MinecraftQuery( );
44: try {
45:
46:
47: $Query->Connect( $this->host, $this->port, 1 );
48: } catch (MinecraftQueryException $e) {
49: $this->setResult("Query ".$this->host." error: ".$e->getMessage());
50: return;
51: }
52: $this->setResult([
53: "host"=>$this->host,
54: "port" => $this->port,
55: "info" => $Query->GetInfo(),
56: "players" => $Query->GetPlayers(),
57: ]);
58: }
59: }
60: