Skip to content

Commit a09de8c

Browse files
committed
Fix rtp attempt #1
1 parent bf23ad6 commit a09de8c

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/main/java/net/farlands/sanctuary/command/player/CommandWild.java

+23-19
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.bukkit.block.Block;
1616
import org.bukkit.entity.Player;
1717

18-
import java.util.concurrent.ExecutionException;
18+
import java.util.concurrent.atomic.AtomicReference;
1919

2020
import static com.kicas.rp.util.Utils.*;
2121
import static net.farlands.sanctuary.util.FLUtils.RNG;
@@ -75,16 +75,11 @@ public boolean execute(Player sender, String[] args) {
7575

7676
long time = System.currentTimeMillis() - FarLands.getDataHandler().getPluginData().seasonStartTime;
7777
FarLands.getInstance().getServer().getScheduler().runTaskAsynchronously(FarLands.getInstance(), () -> {
78-
try {
79-
rtpPlayer(
80-
sender,
81-
INNER_RAD,
82-
MIN_OUTER_RAD + Math.min(MAX_OUTER_RAD - MIN_OUTER_RAD, (int) (time / 180000L)) // 3 * 60 * 1000, 3 minutes per block of rtp
83-
);
84-
} catch (ExecutionException | InterruptedException e) {
85-
rtpFail(sender);
86-
e.printStackTrace();
87-
}
78+
rtpPlayer(
79+
sender,
80+
INNER_RAD,
81+
MIN_OUTER_RAD + Math.min(MAX_OUTER_RAD - MIN_OUTER_RAD, (int) (time / 180000L)) // 3 * 60 * 1000, 3 minutes per block of rtp
82+
);
8883
});
8984
return true;
9085
}
@@ -99,7 +94,7 @@ private static void rtpFail(Player player) {
9994
FarLands.getDebugger().echo(player.getName() + " /rtp → fail");
10095
}
10196

102-
private static void rtpPlayer(Player player, int minRange, int maxRange) throws ExecutionException, InterruptedException {
97+
private static void rtpPlayer(Player player, int minRange, int maxRange) {
10398
boolean overworld = player.getWorld().getName().equals("world");
10499
final int doubleMax = maxRange << 1,
105100
minSQ = minRange * minRange,
@@ -160,18 +155,24 @@ private static void rtpPlayer(Player player, int minRange, int maxRange) throws
160155
}
161156
}
162157

163-
private static Location rtpFindSafe(Location origin) throws ExecutionException, InterruptedException {
158+
private static Location rtpFindSafe(Location origin) {
164159
Location safe = origin.clone();
165160
safe.setX(safe.getBlockX() + .5);
166161
safe.setZ(safe.getBlockZ() + .5);
167-
return safe.getWorld().getChunkAtAsync(safe, true).thenApplyAsync((chunk) -> {
162+
AtomicReference<Location> ret = new AtomicReference<>();
163+
safe.getWorld().getChunkAtAsync(safe, true).whenCompleteAsync((chunk, throwable) -> {
164+
if (throwable != null) {
165+
ret.set(null);
166+
return;
167+
}
168+
168169
int bottom = 62,
169170
top = 1 + safe.getChunk().getChunkSnapshot().getHighestBlockYAt(
170-
safe.getBlockX() & 15, safe.getBlockZ() & 15
171+
safe.getBlockX() & 15, safe.getBlockZ() & 15
171172
);
172173

173174
if (canStand(safe.getBlock()) && isSafe(safe.clone()))
174-
return safe.add(0, .5, 0);
175+
ret.set(safe.add(0, .5, 0));
175176

176177
do {
177178
safe.setY((bottom + top + 1) >> 1);
@@ -183,8 +184,11 @@ private static Location rtpFindSafe(Location origin) throws ExecutionException,
183184
safe.setY((bottom + top - 1) >> 1);
184185

185186
if (canStand(safe.getBlock()) && isSafe(safe.clone()))
186-
return safe.add(0, 1.5, 0);
187-
return null;
188-
}).get();
187+
ret.set(safe.add(0, 1.5, 0));
188+
189+
ret.set(null);
190+
});
191+
192+
return ret.get();
189193
}
190194
}

0 commit comments

Comments
 (0)