Load initial tp location async

Fixes https://github.com/BentoBoxWorld/BentoBox/issues/1584
This commit is contained in:
tastybento 2020-11-26 17:25:17 -08:00
parent 93d7fad860
commit caed56f16e
2 changed files with 12 additions and 3 deletions

View File

@ -66,6 +66,10 @@ public class SafeSpotTeleport {
this.result = builder.getResult(); this.result = builder.getResult();
// If there is no portal scan required, try the desired location immediately // If there is no portal scan required, try the desired location immediately
Util.getChunkAtAsync(location).thenRun(()-> tryTogo(builder.getFailureMessage()));
}
private void tryTogo(String failureMessage) {
if (plugin.getIslands().isSafeLocation(location)) { if (plugin.getIslands().isSafeLocation(location)) {
if (portal) { if (portal) {
// If the desired location is safe, then that's where you'll go if there's no portal // If the desired location is safe, then that's where you'll go if there's no portal
@ -86,7 +90,7 @@ public class SafeSpotTeleport {
notChecking = true; notChecking = true;
// Start a recurring task until done or cancelled // Start a recurring task until done or cancelled
task = Bukkit.getScheduler().runTaskTimer(plugin, () -> gatherChunks(builder.getFailureMessage()), 0L, SPEED); task = Bukkit.getScheduler().runTaskTimer(plugin, () -> gatherChunks(failureMessage), 0L, SPEED);
} }
private void gatherChunks(String failureMessage) { private void gatherChunks(String failureMessage) {

View File

@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -45,7 +46,7 @@ import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class}) @PrepareForTest({Bukkit.class, BentoBox.class, User.class, Util.class})
public class AdminTeleportCommandTest { public class AdminTeleportCommandTest {
private CompositeCommand ac; private CompositeCommand ac;
@ -137,6 +138,10 @@ public class AdminTeleportCommandTest {
// We do no actually want to teleport in this test, so return no island // We do no actually want to teleport in this test, so return no island
Optional<Island> nothing = Optional.empty(); Optional<Island> nothing = Optional.empty();
when(im.getIslandAt(any())).thenReturn(nothing ); when(im.getIslandAt(any())).thenReturn(nothing );
// Util
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
when(Util.getUUID(anyString())).thenCallRealMethod();
} }
@After @After