15
15
import org .bukkit .block .Block ;
16
16
import org .bukkit .entity .Player ;
17
17
18
- import java .util .concurrent .ExecutionException ;
18
+ import java .util .concurrent .atomic . AtomicReference ;
19
19
20
20
import static com .kicas .rp .util .Utils .*;
21
21
import static net .farlands .sanctuary .util .FLUtils .RNG ;
@@ -75,16 +75,11 @@ public boolean execute(Player sender, String[] args) {
75
75
76
76
long time = System .currentTimeMillis () - FarLands .getDataHandler ().getPluginData ().seasonStartTime ;
77
77
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
+ );
88
83
});
89
84
return true ;
90
85
}
@@ -99,7 +94,7 @@ private static void rtpFail(Player player) {
99
94
FarLands .getDebugger ().echo (player .getName () + " /rtp → fail" );
100
95
}
101
96
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 ) {
103
98
boolean overworld = player .getWorld ().getName ().equals ("world" );
104
99
final int doubleMax = maxRange << 1 ,
105
100
minSQ = minRange * minRange ,
@@ -160,18 +155,24 @@ private static void rtpPlayer(Player player, int minRange, int maxRange) throws
160
155
}
161
156
}
162
157
163
- private static Location rtpFindSafe (Location origin ) throws ExecutionException , InterruptedException {
158
+ private static Location rtpFindSafe (Location origin ) {
164
159
Location safe = origin .clone ();
165
160
safe .setX (safe .getBlockX () + .5 );
166
161
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
+
168
169
int bottom = 62 ,
169
170
top = 1 + safe .getChunk ().getChunkSnapshot ().getHighestBlockYAt (
170
- safe .getBlockX () & 15 , safe .getBlockZ () & 15
171
+ safe .getBlockX () & 15 , safe .getBlockZ () & 15
171
172
);
172
173
173
174
if (canStand (safe .getBlock ()) && isSafe (safe .clone ()))
174
- return safe .add (0 , .5 , 0 );
175
+ ret . set ( safe .add (0 , .5 , 0 ) );
175
176
176
177
do {
177
178
safe .setY ((bottom + top + 1 ) >> 1 );
@@ -183,8 +184,11 @@ private static Location rtpFindSafe(Location origin) throws ExecutionException,
183
184
safe .setY ((bottom + top - 1 ) >> 1 );
184
185
185
186
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 ();
189
193
}
190
194
}
0 commit comments