Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into reimpl/1
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Jun 18, 2023
2 parents 75641ed + 61ca4e7 commit 9c7bfc7
Show file tree
Hide file tree
Showing 78 changed files with 441 additions and 284 deletions.
13 changes: 2 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import java.io.ByteArrayOutputStream

buildscript {
configurations.all {
resolutionStrategy {
force("org.ow2.asm:asm:9.3")
force("org.ow2.asm:asm-commons:9.3")
}
}
}

plugins {
id("java-library")
id("maven-publish")
id("com.github.johnrengelman.shadow") version "7.1.2"
id("com.github.johnrengelman.shadow") version "8.1.1"
}

subprojects {
Expand Down Expand Up @@ -45,7 +36,7 @@ subprojects {
}
shadowJar {
archiveClassifier.set("")
archiveFileName.set("${rootProject.name.capitalize()}-${project.version}.jar")
archiveFileName.set("${project.property("artifactName")}-${project.version}.jar")
}
build {
dependsOn(shadowJar)
Expand Down
4 changes: 2 additions & 2 deletions bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
compileOnly(group = "com.github.Puremin0rez", name = "WorldBorder", version = "1.19") {
isTransitive = false
}
implementation(group = "org.bstats", name = "bstats-bukkit", version = "3.0.0")
implementation(group = "org.bstats", name = "bstats-bukkit", version = "3.0.2")
implementation(project(":chunky-common"))
implementation(project(":chunky-paper"))
implementation(project(":chunky-folia"))
Expand All @@ -19,7 +19,7 @@ tasks {
processResources {
filesMatching("plugin.yml") {
expand(
"name" to rootProject.name.capitalize(),
"name" to project.property("artifactName"),
"version" to project.version,
"group" to project.group,
"author" to project.property("author"),
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dependencies {
compileOnly(group = "com.google.code.gson", name = "gson", version = "2.8.9")
testImplementation(group = "junit", name = "junit", version = "4.13.2")
testImplementation(group = "com.google.code.gson", name = "gson", version = "2.8.9")
implementation(project(":chunky-nbt"))
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void run() {
final String poolThreadName = Thread.currentThread().getName();
Thread.currentThread().setName(String.format("Chunky-%s Thread", selection.world().getName()));
final Semaphore working = new Semaphore(MAX_WORKING_COUNT);
final boolean forceLoadExistingChunks = chunky.getConfig().isForceLoadExistingChunks();
final boolean forceLoadExistingChunks = true;
startTime.set(System.currentTimeMillis());
while (!stopped && chunkIterator.hasNext()) {
final ChunkCoordinate chunk = chunkIterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public final class CommandLiteral {
public static final String CONTINUE = "continue";
public static final String CORNERS = "corners";
public static final String HELP = "help";
public static final String INHABITED = "inhabited";
public static final String INTERVAL = "interval";
public static final String PAGE = "page";
public static final String PATTERN = "pattern";
Expand All @@ -27,6 +28,7 @@ public final class CommandLiteral {
public static final String SPAWN = "spawn";
public static final String START = "start";
public static final String TRIM = "trim";
public static final String TRIM_MODE = "trimMode";
public static final String WORLDBORDER = "worldborder";
public static final String WORLD = "world";
public static final String X = "x";
Expand Down
78 changes: 49 additions & 29 deletions common/src/main/java/org/popcraft/chunky/command/TrimCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.popcraft.chunky.Selection;
import org.popcraft.chunky.nbt.CompoundTag;
import org.popcraft.chunky.nbt.LongTag;
import org.popcraft.chunky.nbt.util.RegionFile;
import org.popcraft.chunky.platform.Sender;
import org.popcraft.chunky.platform.World;
import org.popcraft.chunky.shape.Shape;
Expand All @@ -13,7 +14,6 @@
import org.popcraft.chunky.util.Formatting;
import org.popcraft.chunky.util.Input;
import org.popcraft.chunky.util.TranslationKey;
import org.popcraft.chunky.world.RegionFile;

import java.io.IOException;
import java.io.RandomAccessFile;
Expand Down Expand Up @@ -90,24 +90,12 @@ public void execute(final Sender sender, final CommandArguments arguments) {
final Runnable deletionAction = () -> chunky.getScheduler().runTask(() -> {
sender.sendMessagePrefixed(TranslationKey.FORMAT_START, selection.world().getName(), translate("shape_" + selection.shape()), Formatting.number(selection.centerX()), Formatting.number(selection.centerZ()), Formatting.radius(selection));
final Optional<Path> regionPath = selection.world().getRegionDirectory();
final Optional<Path> poiPath = selection.world().getPOIDirectory();
final Optional<Path> entitiesPath = selection.world().getEntitiesDirectory();
final AtomicLong deleted = new AtomicLong();
final long startTime = System.currentTimeMillis();
try {
if (regionPath.isPresent()) {
try (final Stream<Path> regionWalker = Files.walk(regionPath.get())) {
regionWalker.forEach(region -> deleted.getAndAdd(checkRegion(region, shape, inside, inhabitedTimeCheck, inhabitedTime)));
}
}
if (poiPath.isPresent()) {
try (final Stream<Path> poiWalker = Files.walk(poiPath.get())) {
poiWalker.forEach(region -> checkRegion(region, shape, inside, inhabitedTimeCheck, inhabitedTime));
}
}
if (entitiesPath.isPresent()) {
try (final Stream<Path> entityWalker = Files.walk(entitiesPath.get())) {
entityWalker.forEach(region -> checkRegion(region, shape, inside, inhabitedTimeCheck, inhabitedTime));
regionWalker.forEach(region -> deleted.getAndAdd(checkRegion(selection.world(), region.getFileName().toString(), shape, inside, inhabitedTimeCheck, inhabitedTime)));
}
}
} catch (IOException e) {
Expand All @@ -118,32 +106,34 @@ public void execute(final Sender sender, final CommandArguments arguments) {
});
chunky.setPendingAction(sender, deletionAction);
sender.sendMessagePrefixed(inside ? TranslationKey.FORMAT_TRIM_CONFIRM_INSIDE : TranslationKey.FORMAT_TRIM_CONFIRM, selection.world().getName(), translate("shape_" + selection.shape()), Formatting.number(selection.centerX()), Formatting.number(selection.centerZ()), Formatting.radius(selection), "/chunky confirm");
if (inhabitedTimeCheck) {
sender.sendMessagePrefixed(TranslationKey.FORMAT_TRIM_CONFIRM_INHABITED, Formatting.number(inhabitedTime));
}
}

private int checkRegion(final Path region, final Shape shape, final boolean inside, final boolean inhabitedTimeCheck, final int inhabitedTime) {
final Optional<ChunkCoordinate> regionCoordinate = tryRegionCoordinate(region);
private int checkRegion(final World world, final String regionFileName, final Shape shape, final boolean inside, final boolean inhabitedTimeCheck, final int inhabitedTime) {
final Optional<ChunkCoordinate> regionCoordinate = tryRegionCoordinate(regionFileName);
if (regionCoordinate.isEmpty()) {
return 0;
}
final int chunkX = regionCoordinate.get().x() << 5;
final int chunkZ = regionCoordinate.get().z() << 5;
if (!inhabitedTimeCheck && shouldDeleteRegion(shape, inside, chunkX, chunkZ)) {
return deleteRegion(region);
return deleteRegion(world, regionFileName);
} else {
return trimRegion(region, shape, inside, chunkX, chunkZ, inhabitedTimeCheck, inhabitedTime);
return trimRegion(world, regionFileName, shape, inside, chunkX, chunkZ, inhabitedTimeCheck, inhabitedTime);
}
}

private Optional<ChunkCoordinate> tryRegionCoordinate(final Path region) {
final String fileName = region.getFileName().toString();
if (!fileName.startsWith("r.")) {
private Optional<ChunkCoordinate> tryRegionCoordinate(final String regionFileName) {
if (!regionFileName.startsWith("r.")) {
return Optional.empty();
}
final int extension = fileName.indexOf(".mca");
final int extension = regionFileName.indexOf(".mca");
if (extension < 2) {
return Optional.empty();
}
final String regionCoordinates = fileName.substring(2, extension);
final String regionCoordinates = regionFileName.substring(2, extension);
final int separator = regionCoordinates.indexOf('.');
final Optional<Integer> regionX = Input.tryInteger(regionCoordinates.substring(0, separator));
final Optional<Integer> regionZ = Input.tryInteger(regionCoordinates.substring(separator + 1));
Expand All @@ -166,24 +156,40 @@ private boolean shouldDeleteRegion(final Shape shape, final boolean inside, fina
return true;
}

private int deleteRegion(final Path region) {
private int deleteRegion(final World world, final String regionFileName) {
try {
Files.deleteIfExists(region);
final Path regionPath = world.getRegionDirectory().map(region -> region.resolve(regionFileName)).orElseThrow(IllegalStateException::new);
Files.deleteIfExists(regionPath);
final Path poiPath = world.getPOIDirectory().map(region -> region.resolve(regionFileName)).orElse(null);
if (poiPath != null) {
Files.deleteIfExists(poiPath);
}
final Path entitiesPath = world.getEntitiesDirectory().map(region -> region.resolve(regionFileName)).orElse(null);
if (entitiesPath != null) {
Files.deleteIfExists(entitiesPath);
}
return 1024;
} catch (IOException e) {
e.printStackTrace();
return 0;
}
}

private int trimRegion(final Path region, final Shape shape, final boolean inside, final int chunkX, final int chunkZ, final boolean inhabitedTimeCheck, final int inhabitedTime) {
private int trimRegion(final World world, final String regionFileName, final Shape shape, final boolean inside, final int chunkX, final int chunkZ, final boolean inhabitedTimeCheck, final int inhabitedTime) {
final Path regionPath = world.getRegionDirectory().map(region -> region.resolve(regionFileName)).orElseThrow(IllegalStateException::new);
final Path poiPath = world.getPOIDirectory().map(region -> region.resolve(regionFileName)).orElse(null);
final Path entitiesPath = world.getEntitiesDirectory().map(region -> region.resolve(regionFileName)).orElse(null);
int marked = 0;
int deleted = 0;
final RegionFile regionData = inhabitedTimeCheck ? new RegionFile(region.toFile()) : null;
try (final RandomAccessFile regionFile = new RandomAccessFile(region.toFile(), "rw")) {
final RegionFile regionData = inhabitedTimeCheck ? new RegionFile(regionPath.toFile()) : null;
try (final RandomAccessFile regionFile = new RandomAccessFile(regionPath.toFile(), "rw");
final RandomAccessFile poiFile = poiPath == null || Files.notExists(poiPath) ? null : new RandomAccessFile(poiPath.toFile(), "rw");
final RandomAccessFile entitiesFile = entitiesPath == null || Files.notExists(entitiesPath) ? null : new RandomAccessFile(entitiesPath.toFile(), "rw")) {
if (regionFile.length() < 4096) {
return 0;
}
final boolean poiValid = poiFile != null && poiFile.length() >= 4096;
final boolean entitiesValid = entitiesFile != null && entitiesFile.length() >= 4096;
for (int offsetX = 0; offsetX < 32; ++offsetX) {
for (int offsetZ = 0; offsetZ < 32; ++offsetZ) {
final int offsetChunkX = chunkX + offsetX;
Expand Down Expand Up @@ -218,14 +224,28 @@ private int trimRegion(final Path region, final Shape shape, final boolean insid
regionFile.writeInt(0);
++deleted;
}
if (poiValid) {
poiFile.seek(chunkLocation);
if (poiFile.readInt() != 0) {
poiFile.seek(chunkLocation);
poiFile.writeInt(0);
}
}
if (entitiesValid) {
entitiesFile.seek(chunkLocation);
if (entitiesFile.readInt() != 0) {
entitiesFile.seek(chunkLocation);
entitiesFile.writeInt(0);
}
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
if (inhabitedTimeCheck && marked == 1024) {
deleteRegion(region);
deleteRegion(world, regionFileName);
}
return deleted;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public final class TranslationKey {
public static final String FORMAT_CONTINUE_NO_TASKS = "format_continue_no_tasks";
public static final String FORMAT_TRIM_CONFIRM = "format_trim_confirm";
public static final String FORMAT_TRIM_CONFIRM_INSIDE = "format_trim_confirm_inside";
public static final String FORMAT_TRIM_CONFIRM_INHABITED = "format_trim_confirm_inhabited";
public static final String FORMAT_PATTERN = "format_pattern";
public static final String FORMAT_PAUSE = "format_pause";
public static final String FORMAT_PAUSE_NO_TASKS = "format_pause_no_tasks";
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/lang/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"format_continue_no_tasks": "Няма задачи за възобновяване.",
"format_trim_confirm": "&cПредупреждение: Чънкове в %s, извън %s региона центриран на %s, %s с радиус от %s ще бъдат перманентно изтрити. Моля, уверете се, че сте направили бакъп на Вашият сървър преди да продължите, за да избегнете потенциални щети. Ще бъдете задължени напълно да рестартирате Вашият сървър, след като задачата приключи. Ако разбирате и желаете да продължите напишете '%s'.",
"format_trim_confirm_inside": "&cWarning: Chunks in %s inside of the %s region centered at %s, %s with radius %s will be permanently deleted. Please make sure you have taken a backup of your server before continuing to avoid potential damage. You will be required to restart your server fully after the task has finished. If you understand and wish to proceed, type '%s'.",
"format_trim_confirm_inhabited": "&eNotice: Filtering chunks by a maximum inhabited time of %s ticks. Trim may take longer than usual to complete.",
"format_pattern": "Шарка променена на %s.",
"format_pause": "Задача поставена на пауза за %s.",
"format_pause_no_tasks": "Няма задачи за поставяне на пауза.",
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/lang/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"format_continue_no_tasks": "Nema procesa za nastavak.",
"format_trim_confirm": "&cUpozorenje: Čankovi u %s izvan %s regije centrirani u %s, %s sa razdaljinom %s će biti trajno obrisani. Napravite rezervnu kopiju servera prije nego što nastavite da biste izbjegli potencijalnu štetu. Morate restartovati server kada se proces završi. Ako ste razumjeli i želite nastaviti, napišite '%s'.",
"format_trim_confirm_inside": "&cWarning: Chunks in %s inside of the %s region centered at %s, %s with radius %s will be permanently deleted. Please make sure you have taken a backup of your server before continuing to avoid potential damage. You will be required to restart your server fully after the task has finished. If you understand and wish to proceed, type '%s'.",
"format_trim_confirm_inhabited": "&eNotice: Filtering chunks by a maximum inhabited time of %s ticks. Trim may take longer than usual to complete.",
"format_pattern": "Oblik promijenjen u %s.",
"format_pause": "Proces za %s pauziran.",
"format_pause_no_tasks": "Nema procesa za pauziranje.",
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/resources/lang/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"format_continue_no_tasks": "Žádné úkoly k pokračování.",
"format_trim_confirm": "&cVarování: chunky v %s mimo oblast %s se středem na %s, %s s poloměrem %s budou natrvalo odstraněny. Před pokračováním se ujistěte, že jste si vytvořili zálohu svého serveru a zabránili tak potenciálnímu poškození. Po dokončení úkolu budete muset plně restartovat server. Pokud souhlasíte a přejete si pokračovat, zadejte '%s'.",
"format_trim_confirm_inside": "&cVarování: chunky v %s uvnitř oblasti %s se středem v %s, %s s poloměrem %s budou natrvalo odstraněny. Před pokračováním se ujistěte, že jste si vytvořili zálohu svého serveru a zabránili tak potenciálnímu poškození. Po dokončení úkolu budete muset plně restartovat server. Pokud souhlasíte a přejete si pokračovat, zadejte '%s'.",
"format_trim_confirm_inhabited": "&eUpozornění: Filtrování chunků podle maximální doby osídlení z %s tiků. Dokončení může trvat déle než obvykle.",
"format_pattern": "Vzor změněn na %s.",
"format_pause": "Úkol pozastaven pro %s.",
"format_pause_no_tasks": "Žádné úkoly k pozastavení.",
Expand Down Expand Up @@ -75,7 +76,7 @@
"pattern_loop": "opakování",
"pattern_spiral": "spirála",
"pattern_csv": "csv",
"pattern_region": "region",
"pattern_region": "oblast",
"shape_circle": "kruh",
"shape_diamond": "diamant",
"shape_ellipse": "elipsa",
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"format_continue_no_tasks": "Keine Aufgaben zum Weitermachen.",
"format_trim_confirm": "&cWarnung: Chunks in %s ausserhalb von der %s Region zentriert bei %s, %s mit Radius %s wird vollständig gelöscht. Bitte stelle sicher, dass du ein Backup von deinem Server gemacht hast, bevor du weiter machst, um eventuelle Schäden zu verhindern. Du musst deinen Server komplett neustarten nachdem die Aufgabe erledigt ist. Wenn du dies verstehst und weitermachen willst, schreibe '%s'.",
"format_trim_confirm_inside": "&cWarnung: Chunks in %s der %s Region zentriert bei %s, %s mit Radius %s wird vollständig gelöscht. Bitte stelle sicher, dass du ein Backup von deinem Server gemacht hast, bevor du weiter machst, um eventuelle Schäden zu verhindern. Du musst deinen Server komplett neustarten nachdem die Aufgabe erledigt ist. Wenn du dies verstehst und weitermachen willst, schreibe '%s'.",
"format_trim_confirm_inhabited": "&eHinweis: Filtere Chunks nach einer maximalen bewohnten Zeit von %s ticks. Trimmen kann länger dauern als üblich zum abschliessen.",
"format_pattern": "Muster geändert zu %s.",
"format_pause": "Aufgabe pausiert für %s.",
"format_pause_no_tasks": "Keine aufgaben zum pausieren.",
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"format_continue_no_tasks": "No tasks to continue.",
"format_trim_confirm": "&cWarning: Chunks in %s outside of the %s region centered at %s, %s with radius %s will be permanently deleted. Please make sure you have taken a backup of your server before continuing to avoid potential damage. You will be required to restart your server fully after the task has finished. If you understand and wish to proceed, type '%s'.",
"format_trim_confirm_inside": "&cWarning: Chunks in %s inside of the %s region centered at %s, %s with radius %s will be permanently deleted. Please make sure you have taken a backup of your server before continuing to avoid potential damage. You will be required to restart your server fully after the task has finished. If you understand and wish to proceed, type '%s'.",
"format_trim_confirm_inhabited": "&eNotice: Filtering chunks by a maximum inhabited time of %s ticks. Trim may take longer than usual to complete.",
"format_pattern": "Pattern changed to %s.",
"format_pause": "Task paused for %s.",
"format_pause_no_tasks": "No tasks to pause.",
Expand Down
Loading

0 comments on commit 9c7bfc7

Please sign in to comment.