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();
// 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 (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;
// 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) {
@ -368,7 +372,7 @@ public class SafeSpotTeleport {
build();
return result;
}
/**
* Try to teleport the player
* @return SafeSpotTeleport

View File

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