-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy paththanos.php
executable file
·52 lines (41 loc) · 1.1 KB
/
thanos.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
#!/usr/bin/php
<?php
use Aternos\Thanos\Helper;
use Aternos\Thanos\Thanos;
use Aternos\Thanos\World\AnvilWorld;
require_once 'vendor/autoload.php';
if (!isset($argv[1])) {
exit("Usage: cleanup.php <world> [<output>]\n");
}
$input = $argv[1];
$output = null;
$moveOutput = false;
if (isset($argv[2])) {
$output = $argv[2];
} else {
$output = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'thanos-' . uniqid();
$moveOutput = true;
}
if (!is_dir($input) || count(scandir($input)) === 2) {
exit('World must be a directory and not empty' . PHP_EOL);
}
if (file_exists($output) && count(scandir($output)) !== 2) {
exit('Output directory must be empty' . PHP_EOL);
}
if (!file_exists($output)) {
mkdir($output);
}
$startTime = microtime(true);
$world = new AnvilWorld($input, $output);
$thanos = new Thanos();
$thanos->setMinInhabitedTime(0);
$removedChunks = $thanos->snap($world);
if ($moveOutput) {
Helper::removeDirectory($input);
rename($output, $input);
}
echo sprintf('Removed %d chunks in %.2f seconds',
$removedChunks,
round(microtime(true) - $startTime, 2)
);
echo PHP_EOL;