feat: prevent edits outside +/- 30,000,000 blocks (#2285)

* feat: prevent edits outside +/- 30,000,000 blocks

* Remove import
This commit is contained in:
Jordan
2023-06-12 10:27:07 +01:00
committed by GitHub
parent ca4080eea7
commit e449910af5
7 changed files with 76 additions and 1 deletions

View File

@ -182,6 +182,11 @@ public enum FaweCache implements Trimable {
"fawe.cancel.reason.outside.region"),
Type.OUTSIDE_REGION
);
public static final FaweException OUTSIDE_SAFE_REGION = new FaweException(
Caption.of(
"fawe.cancel.reason.outside.safe.region"),
Type.OUTSIDE_REGION
);
public static final FaweException MAX_CHECKS = new FaweException(
Caption.of("fawe.cancel.reason.max" + ".checks"),
Type.MAX_CHECKS

View File

@ -312,6 +312,12 @@ public class Settings extends Config {
" - Any blacklist regions are likely to override any internal allowed regions."
})
public boolean WORLDGUARD_REGION_BLACKLIST = false;
@Comment({
"Restrict all edits to within the safe chunk limits of +/- 30 million blocks",
" - Edits outside this range may induce crashing",
" - Forcefully prevents any edit outside this range"
})
public boolean RESTRICT_TO_SAFE_RANGE = true;
}

View File

@ -80,6 +80,7 @@ public class FaweException extends RuntimeException {
MANUAL,
NO_REGION,
OUTSIDE_REGION,
OUTSIDE_SAFE_REGION,
MAX_CHECKS,
MAX_CHANGES,
LOW_MEMORY,

View File

@ -293,7 +293,9 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen
if (pair == lastPair) {
return lastChunk;
}
if (!processGet(x, z)) {
if (!processGet(x, z) || (Settings.settings().REGION_RESTRICTIONS_OPTIONS.RESTRICT_TO_SAFE_RANGE
// if any chunk coord is outside 30 million blocks
&& (x > 1875000 || z > 1875000 || x < -1875000 || z < -1875000))) {
lastPair = pair;
lastChunk = NullChunk.getInstance();
return NullChunk.getInstance();

View File

@ -110,6 +110,14 @@ public class AsyncPreloader implements Preloader, Runnable {
Iterator<BlockVector2> chunksIter = chunks.iterator();
while (chunksIter.hasNext() && pair.getValue() == chunks) { // Ensure the queued load is still valid
BlockVector2 chunk = chunksIter.next();
if (Settings.settings().REGION_RESTRICTIONS_OPTIONS.RESTRICT_TO_SAFE_RANGE) {
int x = chunk.getX();
int z = chunk.getZ();
// if any chunk coord is outside 30 million blocks
if (x > 1875000 || z > 1875000 || x < -1875000 || z < -1875000) {
continue;
}
}
queueLoad(world, chunk);
}
}

View File

@ -149,6 +149,7 @@
"fawe.cancel.reason.max.iterations": "Max iterations",
"fawe.cancel.reason.outside.level": "Outside world",
"fawe.cancel.reason.outside.region": "Outside allowed region (bypass with /wea, or disable `region-restrictions` in config.yml)",
"fawe.cancel.reason.outside.safe.region": "Outside safe edit region of +/- 30,000,000 blocks.",
"fawe.cancel.reason.no.region": "No allowed region (bypass with /wea, or disable `region-restrictions` in config.yml)",
"fawe.cancel.reason.no.region.reason": "No allowed region: {0}",
"fawe.cancel.reason.no.region.plot.noworldeditflag": "Plot flag NoWorldeditFlag set",