-
Notifications
You must be signed in to change notification settings - Fork 4
/
deleteEntity.php
121 lines (106 loc) · 3.38 KB
/
deleteEntity.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?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);
switch (count($entities)) {
case 0:
echo "Entity not found " . PHP_EOL;
return;
case 1:
$hawk->deleteEntity($entities[0]);
echo "1 entity deleted " . PHP_EOL;
save();
return;
default:
$count = count($entities);
foreach ($entities as $index => $entity) {
echo $index . ": " . $entity->getName() . " at " . $entity->getCoordinates() . " " . PHP_EOL;
}
echo $count . ": delete all " . PHP_EOL;
$answer = "";
while (true) {
$answer = readline("Choose which entity will be deleted. -1 will cancel. " . PHP_EOL);
if (!is_numeric($answer) || intval($answer) > $count) {
echo "Wrong input try again. " . PHP_EOL;
continue;
}
switch (intval($answer)) {
case -1:
echo "Exiting... " . PHP_EOL;
closeFiles();
return;
case $count:
foreach ($entities as $entity){
$hawk->deleteEntity($entity);
}
save();
return;
default:
$hawk->deleteEntity($entities[intval($answer)]);
save();
return;
}
}
}
function save(): void
{
global $hawk;
$hawk->save();
closeFiles();
}
function closeFiles(): void
{
global $blockFiles;
global $entitiesFiles;
foreach ($blockFiles as $file) {
$file->close();
}
foreach ($entitiesFiles as $file) {
$file->close();
}
}