TimingsCommand: some code cleanup

This commit is contained in:
Dylan K. Taylor 2018-07-30 14:53:10 +01:00
parent a97c7d3132
commit a4aee98cba

View File

@ -105,7 +105,12 @@ class TimingsCommand extends VanillaCommand{
$host = $sender->getServer()->getProperty("timings.host", "timings.pmmp.io");
$sender->getServer()->getAsyncPool()->submitTask(new class([
$sender->getServer()->getAsyncPool()->submitTask(new class($sender, $host, $agent, $data) extends BulkCurlTask{
/** @var string */
private $host;
public function __construct(CommandSender $sender, string $host, string $agent, array $data){
parent::__construct([
["page" => "https://$host?upload=true", "extraOpts" => [
CURLOPT_HTTPHEADER => [
"User-Agent: $agent",
@ -116,12 +121,7 @@ class TimingsCommand extends VanillaCommand{
CURLOPT_AUTOREFERER => false,
CURLOPT_FOLLOWLOCATION => false
]]
], $sender, $host) extends BulkCurlTask{
/** @var string */
private $host;
public function __construct(array $operations, $complexData = null, string $host){
parent::__construct($operations, $complexData);
], $sender);
$this->host = $host;
}
@ -136,17 +136,13 @@ class TimingsCommand extends VanillaCommand{
return;
}
if(isset($result[0]) && is_array($response = json_decode($result[0], true)) && isset($response["id"])){
$pasteId = $response["id"];
}
if(isset($pasteId)){
$sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsRead",
["https://" . $this->host . "/?id=" . $pasteId]));
["https://" . $this->host . "/?id=" . $response["id"]]));
}else{
$sender->sendMessage(new TranslationContainer("pocketmine.command.timings.pasteError"));
}
}
});
}else{
fclose($fileTimings);
$sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsWrite", [$timings]));