Fixes drop into block after island reset issue.

https://github.com/BentoBoxWorld/BentoBox/issues/705
This commit is contained in:
tastybento 2019-05-29 17:13:22 -07:00
parent 110deea28e
commit c7f2eb5f2a
3 changed files with 6 additions and 25 deletions

View File

@ -3,7 +3,6 @@ package world.bentobox.bentobox.api.commands.island;
import java.io.IOException;
import java.util.List;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import world.bentobox.bentobox.api.addons.GameModeAddon;
@ -98,7 +97,6 @@ public class IslandResetCommand extends ConfirmableCommand {
private boolean resetIsland(User user, String name) {
// Reset the island
Player player = user.getPlayer();
player.setGameMode(GameMode.SPECTATOR);
user.sendMessage("commands.island.create.creating-island");
// Get the player's old island
Island oldIsland = getIslands().getIsland(getWorld(), player.getUniqueId());

View File

@ -639,11 +639,12 @@ public class IslandsManager {
} else {
user.sendMessage("commands.island.go.teleported", TextVariables.NUMBER, String.valueOf(number));
}
// Exit spectator mode if in it
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
player.setGameMode(plugin.getIWM().getDefaultGameMode(world));
}
// Exit spectator mode if in it - running this too quickly after teleporting can result in the player dropping a block
Bukkit.getScheduler().runTaskLater(plugin, () -> {
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
player.setGameMode(plugin.getIWM().getDefaultGameMode(world));
}
}, 4L);
// If this is a new island, then run commands and do resets
if (newIsland) {
// TODO add command running

View File

@ -604,26 +604,8 @@ public class IslandsManagerTest {
IslandsManager im = new IslandsManager(plugin);
when(pm.getHomeLocation(Mockito.any(), Mockito.any(User.class), Mockito.eq(0))).thenReturn(null);
when(pm.getHomeLocation(Mockito.any(), Mockito.any(User.class), Mockito.eq(1))).thenReturn(location);
when(player.getGameMode()).thenReturn(GameMode.SPECTATOR);
im.homeTeleport(world, player, 0);
Mockito.verify(player).teleport(location);
Mockito.verify(player).setGameMode(GameMode.SURVIVAL);
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#homeTeleport(World, Player, int)}.
*/
@Test
public void testHomeTeleportPlayerIntDifferentGameMode() {
when(iwm.getDefaultGameMode(world)).thenReturn(GameMode.CREATIVE);
IslandsManager im = new IslandsManager(plugin);
when(pm.getHomeLocation(Mockito.any(), Mockito.any(User.class), Mockito.eq(0))).thenReturn(null);
when(pm.getHomeLocation(Mockito.any(), Mockito.any(User.class), Mockito.eq(1))).thenReturn(location);
when(player.getGameMode()).thenReturn(GameMode.SPECTATOR);
im.homeTeleport(world, player, 0);
Mockito.verify(player).teleport(location);
Mockito.verify(player).setGameMode(GameMode.CREATIVE);
}