-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy paththanos.php
More file actions
executable file
·56 lines (45 loc) · 1.34 KB
/
thanos.php
File metadata and controls
executable file
·56 lines (45 loc) · 1.34 KB
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
#!/usr/bin/php
<?php
use Aternos\Thanos\Pattern\Factory\ForceLoadedChunkPatternFactory;
use Aternos\Thanos\Pattern\InhabitedTimePattern;
use Aternos\Thanos\Thanos;
use Aternos\Thanos\World\World;
require_once 'vendor/autoload.php';
if (!isset($argv[1])) {
exit("Usage: thanos.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 = World::open($input);
$destination = new \Aternos\IO\System\Directory\Directory($output);
$thanos = new Thanos([
new ForceLoadedChunkPatternFactory(),
new InhabitedTimePattern(0, false),
]);
$removedChunks = $thanos->snap($world, $destination);
if ($moveOutput) {
$world->getSource()->delete();
$destination->move($world->getSource()->getPath());
}
echo sprintf('Removed %d chunks in %.2f seconds',
$removedChunks,
round(microtime(true) - $startTime, 2)
);
echo PHP_EOL;