13declare(strict_types=1);
 
   15namespace pocketmine\network\mcpe\protocol\tools\generate_command_parameter_types;
 
   20use 
function file_get_contents;
 
   24use 
function json_decode;
 
   25use 
function strtoupper;
 
   28if(count($argv) !== 2){
 
   29    echo 
"Usage: php generate-command-parameter-types.php <input-file> \n";
 
   30    echo 
"Hint: Input file is a JSON file like command_arg_types.json in pmmp/BedrockData\n";
 
   34$jsonRaw = file_get_contents($argv[1]);
 
   35if($jsonRaw === 
false){
 
   36    echo 
"Failed to read input file $argv[1]\n";
 
   40$list = json_decode($jsonRaw, 
true, flags: JSON_THROW_ON_ERROR);
 
   42    echo 
"Failed to decode input file $argv[1], expected a JSON object\n";
 
   46$output = fopen(dirname(__DIR__) . 
"/src/types/command/CommandParameterTypes.php", 
"wb");
 
   48    throw new \RuntimeException(
"Failed to open output file");
 
   51fwrite($output, <<<
'CODE' 
   64declare(strict_types=1);
 
   66namespace pocketmine\network\mcpe\protocol\types\command;
 
   72final class CommandParameterTypes{
 
   74    private function __construct(){
 
   81uasort($list, 
function(array $left, array $right) : 
int{
 
   82    return $left[
"id"] <=> $right[
"id"];
 
   85foreach($list as $name => $properties){
 
   86    if($properties[
"description"] === 
"unknown"){
 
   87        echo 
"Skipping $name - description unknown, assuming internal type\n";
 
   91    fwrite($output, 
"\tpublic const " . strtoupper($name) . 
" = " . $properties[
"id"] . 
"; // " . $properties[
"description"] . 
"\n");
 
   94fwrite($output, 
"}\n");
 
   97echo 
"Done. Don't forget to run CS fixer after generating code.\n";