forked from aternosorg/hawk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
getEntity.php
81 lines (65 loc) · 2.16 KB
/
getEntity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
require_once __DIR__ . "/../vendor/autoload.php";
use Aternos\Hawk\File;
use Aternos\Hawk\Hawk;
use Aternos\Hawk\McCoordinatesFloat;
use Aternos\Hawk\Region;
if (!isset($argc)) {
echo "argc and argv disabled. check php.ini " . PHP_EOL;
return;
}
$yes = ["Y", "y", false];
$no = ["N", "n"];
switch ($argc) {
case 1:
case 2:
case 3:
echo "too few params given.
\targument 1: path of world folder " . PHP_EOL . "
\targument 2: name of entity e.g. 'minecraft:armor_stand' " . PHP_EOL . "
\targument 3: entity coordinates(x,y,z) " . PHP_EOL;
return;
case 4:
if (!file_exists($argv[1])) {
echo "directory does not exist. " . PHP_EOL;
return;
}
break;
default:
echo "too many params given. choose: " . PHP_EOL . "
\targument 1: path of world folder " . PHP_EOL . "
\targument 2: name of entity e.g. 'minecraft:armor_stand' " . PHP_EOL . "
\targument 3: entity coordinates(x,y,z) " . PHP_EOL;
return;
}
$inputPath = $argv[1];
$entityName = $argv[2];
$coordinates = explode(",", $argv[3]);
if(count($coordinates) !== 3){
echo "Wrong coordinates " . PHP_EOL;
return;
}
$entityPos = new McCoordinatesFloat($coordinates[0], $coordinates[1], $coordinates[2]);
$fileName = Region::getRegionFileNameFromBlock(McCoordinatesFloat::get3DCoordinates($entityPos));
$blockPath = $inputPath . "/region/" . $fileName;
$entitiesPath = $inputPath . "/entities/" . $fileName;
$blockFiles = (file_exists($blockPath)) ? [new File($blockPath)] : [];
$entitiesFiles = (file_exists($entitiesPath)) ? [new File($entitiesPath)] : [];
$hawk = new Hawk($blockFiles, $entitiesFiles);
$entities = $hawk->getEntities($entityName,$entityPos);
foreach ($entities as $index => $entity) {
echo $index . ": " . $entity->getName() . " at " . $entity->getCoordinates() . " " . PHP_EOL;
}
$count = count($entities);
$message = " entity found " . PHP_EOL;
if($count !== 1){
$message = " entities found " . PHP_EOL;
}
echo $count . $message;
// Close files
foreach ($blockFiles as $file){
$file->close();
}
foreach ($entitiesFiles as $file){
$file->close();
}