From 988f2ee736fbc020fb423d3c5a2efd066ef0da36 Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Sat, 27 Jul 2019 15:39:50 +0100 Subject: [PATCH] Return earlier if check count exceeds max tries --- .../randomteleport/searcher/RandomSearcher.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/randomteleport-plugin/src/main/java/de/themoep/randomteleport/searcher/RandomSearcher.java b/randomteleport-plugin/src/main/java/de/themoep/randomteleport/searcher/RandomSearcher.java index 76a1b28..6cc9866 100644 --- a/randomteleport-plugin/src/main/java/de/themoep/randomteleport/searcher/RandomSearcher.java +++ b/randomteleport-plugin/src/main/java/de/themoep/randomteleport/searcher/RandomSearcher.java @@ -314,6 +314,11 @@ public class RandomSearcher { } do { + checks++; + if (checks >= maxTries) { + future.completeExceptionally(new NotFoundException("location")); + return; + } if (loadedOnly) { Chunk chunk = loadedChunks[random.nextInt(loadedChunks.length)]; randChunkX = chunk.getX(); @@ -322,11 +327,6 @@ public class RandomSearcher { randChunkX = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1); randChunkZ = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1); } - checks++; - if (checks >= maxTries) { - future.completeExceptionally(new NotFoundException("location")); - return; - } } while (!checked.put(randChunkX, randChunkZ) || !inRadius(randChunkX, randChunkZ, minChunk, maxChunk)); randomLoc.setX(((center.getBlockX() >> 4) + randChunkX) * 16);