Skip to content

Commit

Permalink
Cleanup 1.13 files before shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher White <[email protected]>
  • Loading branch information
cswhite2000 committed Jul 4, 2023
1 parent da079f4 commit e0ec433
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ jobs:
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
- id: artifact
name: Upload Jar
uses: actions/upload-artifact@v3
with:
name: ChunkPruner-1.0-SNAPSHOT.jar
path: target/ChunkPruner-1.0-SNAPSHOT.jar
if-no-files-found: error
26 changes: 25 additions & 1 deletion src/main/java/app/chrisw/mc/ChunkPruner.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -33,6 +35,21 @@ public void recursiveProcess(List<String> paths, File file) {
}
}

public void recursiveProcessEmpty(File file) {
String absolutePath = file.getAbsolutePath();
if (file.isDirectory()) {
for (File listFile : file.listFiles()) {
recursiveProcessEmpty(listFile);
}
} else {
if (absolutePath.endsWith(".mca")) {
if (file.length() < 1024 * 16) {
file.delete();
}
}
}
}

@Override
public void onEnable() {
Logger logger = Logger.getLogger("ChunkPruner");
Expand Down Expand Up @@ -68,10 +85,15 @@ public void onEnable() {
File[] regionFiles = (new File(filePath + "/region")).listFiles();

List<String> filesToDelete = new ArrayList<>();
filesToDelete.add(filePath + "/data/functions");
filesToDelete.add(filePath + "/data");
filesToDelete.add(filePath + "/playerdata");
filesToDelete.add(filePath + "/session.lock");
filesToDelete.add(filePath + "/uid.dat");
filesToDelete.add(filePath + "/DIM1/data");
filesToDelete.add(filePath + "/DIM1");
filesToDelete.add(filePath + "/DIM-1/data");
filesToDelete.add(filePath + "/DIM-1");

// This is pruning
if (regionFiles != null) {
Expand Down Expand Up @@ -131,6 +153,8 @@ public void onEnable() {
fileToDelete.delete();
}
}
Bukkit.getScheduler().runTaskLater(this, () -> Bukkit.shutdown(), 5 * 20);

Bukkit.getScheduler().runTaskLater(this, () -> recursiveProcessEmpty(baseFile), 4 * 20);
Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 10 * 20);
}
}

0 comments on commit e0ec433

Please sign in to comment.