mirror of
https://github.com/Phoenix616/RandomTeleport.git
synced 2024-11-14 06:36:36 +01:00
Fix case where the chunk check didn't finish.
Also make sure random chunk location calculation is correct and some minor style fixes.
This commit is contained in:
parent
8b4f7a74d3
commit
a363a960f4
@ -33,7 +33,6 @@ import org.bukkit.entity.Entity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -50,6 +49,7 @@ public class RandomSearcher {
|
||||
private ValidatorRegistry validators = new ValidatorRegistry();
|
||||
|
||||
private static final List<int[]> RANDOM_LIST = new ArrayList<int[]>();
|
||||
|
||||
static {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
@ -295,19 +295,15 @@ public class RandomSearcher {
|
||||
do {
|
||||
randChunkX = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1);
|
||||
randChunkZ = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1);
|
||||
if (checked.containsEntry(randChunkX, randChunkZ)) {
|
||||
checks++;
|
||||
if (checks >= maxTries) {
|
||||
future.completeExceptionally(new NotFoundException("location"));
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
checked.put(randChunkX, randChunkZ);
|
||||
} while (!inRadius(randChunkX, randChunkZ, minChunk, maxChunk));
|
||||
} while (!checked.put(randChunkX, randChunkZ) || !inRadius(randChunkX, randChunkZ, minChunk, maxChunk));
|
||||
|
||||
randomLoc.setX((center.getBlockX() >> 4 + randChunkX) * 16);
|
||||
randomLoc.setZ((center.getBlockZ() >> 4 + randChunkZ) * 16);
|
||||
randomLoc.setX(((center.getBlockX() >> 4) + randChunkX) * 16);
|
||||
randomLoc.setZ(((center.getBlockZ() >> 4) + randChunkZ) * 16);
|
||||
PaperLib.getChunkAtAsync(randomLoc, generatedOnly).thenApply(c -> {
|
||||
checks++;
|
||||
int indexOffset = random.nextInt(RANDOM_LIST.size());
|
||||
|
Loading…
Reference in New Issue
Block a user