diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommand.java index 96f2aca3c..60684e876 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommand.java @@ -60,7 +60,6 @@ public class AdminTeleportCommand extends CompositeCommand { .entity(user.getPlayer()) .location(warpSpot) .failureMessage(failureMessage) - .overrideGamemode(false) .build(); return true; } diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java index 811abb2fe..57039ac2c 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java @@ -113,10 +113,7 @@ public class InvincibleVisitorsListener extends FlagListener implements ClickHan Player p = (Player) e.getEntity(); // Handle the void - teleport player back to island in a safe spot if(e.getCause().equals(DamageCause.VOID)) { - if (getIslands().getIslandAt(p.getLocation()).isPresent()) { - // Will be set back after the teleport - p.setGameMode(GameMode.SPECTATOR); - getIslands().getIslandAt(p.getLocation()).ifPresent(i -> new SafeSpotTeleport.Builder(getPlugin()).entity(p).island(i).build()); + if (getIslands().getIslandAt(p.getLocation()).isPresent()) { getIslands().getIslandAt(p.getLocation()).ifPresent(i -> new SafeSpotTeleport.Builder(getPlugin()).entity(p).island(i).build()); } else if (getIslands().hasIsland(p.getWorld(), p.getUniqueId())) { // No island in this location - if the player has an island try to teleport them back getIslands().homeTeleport(p.getWorld(), p); diff --git a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java index ff59b76b0..093521c2d 100644 --- a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java @@ -646,12 +646,6 @@ public class IslandsManager { } else { user.sendMessage("commands.island.go.teleported", TextVariables.NUMBER, String.valueOf(number)); } - // 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 @@ -920,10 +914,6 @@ public class IslandsManager { if (spawn.containsKey(w)) { // go to island spawn p.teleport(spawn.get(w).getSpawnPoint(w.getEnvironment())); - } else { - plugin.logWarning("During island deletion player " + p.getName() + " could not be sent home so was placed into spectator mode."); - p.setGameMode(GameMode.SPECTATOR); - p.setFlying(true); } } }); diff --git a/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java b/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java index 822219742..a4f643dc0 100644 --- a/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java +++ b/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java @@ -40,7 +40,6 @@ public class SafeSpotTeleport { private final Location location; private boolean portal; private final int homeNumber; - private final boolean overrideGamemode; // Locations private Location bestSpot; @@ -57,18 +56,12 @@ public class SafeSpotTeleport { * @param portal - true if this is a portal teleport * @param homeNumber - home number to go to */ - public SafeSpotTeleport(BentoBox plugin, final Entity entity, final Location location, final String failureMessage, boolean portal, int homeNumber, boolean overrideGamemode) { + public SafeSpotTeleport(BentoBox plugin, final Entity entity, final Location location, final String failureMessage, boolean portal, int homeNumber) { this.plugin = plugin; this.entity = entity; this.location = location; this.portal = portal; this.homeNumber = homeNumber; - this.overrideGamemode = overrideGamemode; - - // Put player into spectator mode - if (overrideGamemode && entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SURVIVAL)) { - ((Player)entity).setGameMode(GameMode.SPECTATOR); - } // If there is no portal scan required, try the desired location immediately if (plugin.getIslands().isSafeLocation(location)) { @@ -78,13 +71,6 @@ public class SafeSpotTeleport { } else { // If this is not a portal teleport, then go to the safe location immediately entity.teleport(location); - // Exit spectator mode if in it - if (entity instanceof Player) { - Player player = (Player)entity; - if (overrideGamemode && player.getGameMode().equals(GameMode.SPECTATOR)) { - player.setGameMode(plugin.getIWM().getDefaultGameMode(player.getWorld())); - } - } return; } } @@ -125,25 +111,17 @@ public class SafeSpotTeleport { if (portal && bestSpot != null) { // Portals found, teleport to the best spot we found teleportEntity(bestSpot); - if (overrideGamemode && entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) { - ((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(bestSpot.getWorld())); - } } else if (entity instanceof Player) { // Failed, no safe spot if (!failureMessage.isEmpty()) { User.getInstance(entity).notify(failureMessage); } - if (overrideGamemode && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) { - if (plugin.getIWM().inWorld(entity.getLocation())) { - ((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(entity.getWorld())); + if (!plugin.getIWM().inWorld(entity.getLocation())) { + // Last resort + if (Bukkit.getServer().isPrimaryThread()) { + ((Player)entity).performCommand("spawn"); } else { - // Last resort - ((Player)entity).setGameMode(GameMode.SURVIVAL); - if (Bukkit.getServer().isPrimaryThread()) { - ((Player)entity).performCommand("spawn"); - } else { - Bukkit.getScheduler().runTask(plugin, () -> ((Player)entity).performCommand("spawn")); - } + Bukkit.getScheduler().runTask(plugin, () -> ((Player)entity).performCommand("spawn")); } } } @@ -247,17 +225,8 @@ public class SafeSpotTeleport { } Vector velocity = entity.getVelocity(); entity.teleport(loc); - // Exit spectator mode if in it - if (entity instanceof Player) { - Player player = (Player)entity; - if (overrideGamemode && player.getGameMode().equals(GameMode.SPECTATOR)) { - player.setGameMode(plugin.getIWM().getDefaultGameMode(loc.getWorld())); - } - } else { - entity.setVelocity(velocity); - } + entity.setVelocity(velocity); }); - } /** @@ -333,7 +302,6 @@ public class SafeSpotTeleport { private boolean portal = false; private String failureMessage = ""; private Location location; - private boolean overrideGamemode = true; public Builder(BentoBox plugin) { this.plugin = plugin; @@ -402,9 +370,10 @@ public class SafeSpotTeleport { * Sets whether the player's gamemode should be overridden. Default is true * @param overrideGamemode whether the player's gamemode should be overridden. * @return Builder + * @deprecated As of 1.6.0, for removal. No longer in use as the player's gamemode is no longer changed upon teleporting. */ + @Deprecated public Builder overrideGamemode(boolean overrideGamemode) { - this.overrideGamemode = overrideGamemode; return this; } @@ -426,7 +395,7 @@ public class SafeSpotTeleport { if (failureMessage.isEmpty() && entity instanceof Player) { failureMessage = "general.errors.no-safe-location-found"; } - return new SafeSpotTeleport(plugin, entity, location, failureMessage, portal, homeNumber, overrideGamemode); + return new SafeSpotTeleport(plugin, entity, location, failureMessage, portal, homeNumber); } } } \ No newline at end of file diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java index 908025628..2e16b599b 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java @@ -137,7 +137,6 @@ public class InvincibleVisitorsListenerTest { when(panel.getInventory()).thenReturn(top); when(Bukkit.createInventory(Mockito.any(), Mockito.anyInt(), Mockito.any())).thenReturn(top); - } @Test @@ -244,7 +243,6 @@ public class InvincibleVisitorsListenerTest { // Player should be teleported to this island listener.onVisitorGetDamage(e); assertTrue(e.isCancelled()); - Mockito.verify(player).setGameMode(Mockito.eq(GameMode.SPECTATOR)); } @Test @@ -255,7 +253,6 @@ public class InvincibleVisitorsListenerTest { // Player should die listener.onVisitorGetDamage(e); assertFalse(e.isCancelled()); - Mockito.verify(player, Mockito.never()).setGameMode(Mockito.eq(GameMode.SPECTATOR)); } @Test @@ -266,9 +263,6 @@ public class InvincibleVisitorsListenerTest { // Player should be teleported to their island listener.onVisitorGetDamage(e); assertTrue(e.isCancelled()); - Mockito.verify(player, Mockito.never()).setGameMode(Mockito.eq(GameMode.SPECTATOR)); Mockito.verify(im).homeTeleport(Mockito.any(), Mockito.eq(player)); } - - } diff --git a/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportBuilderTest.java b/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportBuilderTest.java index 45ee5db9c..82392d8b4 100644 --- a/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportBuilderTest.java +++ b/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportBuilderTest.java @@ -62,7 +62,7 @@ public class SafeSpotTeleportBuilderTest { public void test() throws Exception { sstb = new SafeSpotTeleport.Builder(plugin); sstb.build(); - SafeSpotTeleport ttt = new SafeSpotTeleport(plugin, player, loc, null, false, 0, false); + SafeSpotTeleport ttt = new SafeSpotTeleport(plugin, player, loc, null, false, 0); assertEquals(sst, ttt); } diff --git a/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportTest.java b/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportTest.java index 5b26097ce..87ac9ed70 100644 --- a/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportTest.java +++ b/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportTest.java @@ -1,6 +1,3 @@ -/** - * - */ package world.bentobox.bentobox.util.teleport; import static org.mockito.Matchers.any; @@ -109,14 +106,13 @@ public class SafeSpotTeleportTest { // Player // Return first survival and then spectator - when(player.getGameMode()).thenReturn(GameMode.SURVIVAL, GameMode.SPECTATOR); + when(player.getGameMode()).thenReturn(GameMode.SURVIVAL); when(loc.getWorld()).thenReturn(world); when(loc.getBlockX()).thenReturn(0); when(loc.getBlockY()).thenReturn(120); when(loc.getBlockZ()).thenReturn(0); Block block = mock(Block.class); when(loc.getBlock()).thenReturn(block); - } /** @@ -126,23 +122,8 @@ public class SafeSpotTeleportTest { public void testSafeSpotTeleportImmediateSafe() throws Exception { boolean portal = false; int homeNumber = 1; - new SafeSpotTeleport(plugin, player, loc, "failure message", portal, homeNumber, true); - Mockito.verify(player).setGameMode(GameMode.SPECTATOR); + new SafeSpotTeleport(plugin, player, loc, "failure message", portal, homeNumber); Mockito.verify(player).teleport(loc); - Mockito.verify(player).setGameMode(GameMode.SURVIVAL); - } - - /** - * Test method for {@link world.bentobox.bentobox.util.teleport.SafeSpotTeleport#SafeSpotTeleport(world.bentobox.bentobox.BentoBox, org.bukkit.entity.Entity, org.bukkit.Location, java.lang.String, boolean, int)}. - */ - @Test - public void testSafeSpotTeleportImmediateSafeNoOverride() throws Exception { - boolean portal = false; - int homeNumber = 1; - new SafeSpotTeleport(plugin, player, loc, "failure message", portal, homeNumber, false); - Mockito.verify(player, Mockito.never()).setGameMode(GameMode.SPECTATOR); - Mockito.verify(player).teleport(loc); - Mockito.verify(player, Mockito.never()).setGameMode(GameMode.SURVIVAL); } /** @@ -153,11 +134,8 @@ public class SafeSpotTeleportTest { when(im.isSafeLocation(Mockito.any())).thenReturn(false); boolean portal = false; int homeNumber = 1; - new SafeSpotTeleport(plugin, player, loc, "failure message", portal, homeNumber, true); - Mockito.verify(player).setGameMode(GameMode.SPECTATOR); + new SafeSpotTeleport(plugin, player, loc, "failure message", portal, homeNumber); Mockito.verify(player, Mockito.never()).teleport(loc); Mockito.verify(sch).runTaskTimer(Mockito.any(), Mockito.any(Runnable.class), Mockito.eq(0L), Mockito.eq(1L)); - } - }