mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-01 00:10:40 +01:00
We're no longer switching the player to SPECTATOR mode when teleporting
Fixes https://github.com/BentoBoxWorld/BentoBox/issues/786 Fixes https://github.com/BentoBoxWorld/BentoBox/issues/578
This commit is contained in:
parent
18f37c4efa
commit
6759a8acc9
@ -60,7 +60,6 @@ public class AdminTeleportCommand extends CompositeCommand {
|
|||||||
.entity(user.getPlayer())
|
.entity(user.getPlayer())
|
||||||
.location(warpSpot)
|
.location(warpSpot)
|
||||||
.failureMessage(failureMessage)
|
.failureMessage(failureMessage)
|
||||||
.overrideGamemode(false)
|
|
||||||
.build();
|
.build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -113,10 +113,7 @@ public class InvincibleVisitorsListener extends FlagListener implements ClickHan
|
|||||||
Player p = (Player) e.getEntity();
|
Player p = (Player) e.getEntity();
|
||||||
// Handle the void - teleport player back to island in a safe spot
|
// Handle the void - teleport player back to island in a safe spot
|
||||||
if(e.getCause().equals(DamageCause.VOID)) {
|
if(e.getCause().equals(DamageCause.VOID)) {
|
||||||
if (getIslands().getIslandAt(p.getLocation()).isPresent()) {
|
if (getIslands().getIslandAt(p.getLocation()).isPresent()) { getIslands().getIslandAt(p.getLocation()).ifPresent(i -> new SafeSpotTeleport.Builder(getPlugin()).entity(p).island(i).build());
|
||||||
// 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());
|
|
||||||
} else if (getIslands().hasIsland(p.getWorld(), p.getUniqueId())) {
|
} else if (getIslands().hasIsland(p.getWorld(), p.getUniqueId())) {
|
||||||
// No island in this location - if the player has an island try to teleport them back
|
// No island in this location - if the player has an island try to teleport them back
|
||||||
getIslands().homeTeleport(p.getWorld(), p);
|
getIslands().homeTeleport(p.getWorld(), p);
|
||||||
|
@ -646,12 +646,6 @@ public class IslandsManager {
|
|||||||
} else {
|
} else {
|
||||||
user.sendMessage("commands.island.go.teleported", TextVariables.NUMBER, String.valueOf(number));
|
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 this is a new island, then run commands and do resets
|
||||||
if (newIsland) {
|
if (newIsland) {
|
||||||
// TODO add command running
|
// TODO add command running
|
||||||
@ -920,10 +914,6 @@ public class IslandsManager {
|
|||||||
if (spawn.containsKey(w)) {
|
if (spawn.containsKey(w)) {
|
||||||
// go to island spawn
|
// go to island spawn
|
||||||
p.teleport(spawn.get(w).getSpawnPoint(w.getEnvironment()));
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -40,7 +40,6 @@ public class SafeSpotTeleport {
|
|||||||
private final Location location;
|
private final Location location;
|
||||||
private boolean portal;
|
private boolean portal;
|
||||||
private final int homeNumber;
|
private final int homeNumber;
|
||||||
private final boolean overrideGamemode;
|
|
||||||
|
|
||||||
// Locations
|
// Locations
|
||||||
private Location bestSpot;
|
private Location bestSpot;
|
||||||
@ -57,18 +56,12 @@ public class SafeSpotTeleport {
|
|||||||
* @param portal - true if this is a portal teleport
|
* @param portal - true if this is a portal teleport
|
||||||
* @param homeNumber - home number to go to
|
* @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.plugin = plugin;
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.portal = portal;
|
this.portal = portal;
|
||||||
this.homeNumber = homeNumber;
|
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 there is no portal scan required, try the desired location immediately
|
||||||
if (plugin.getIslands().isSafeLocation(location)) {
|
if (plugin.getIslands().isSafeLocation(location)) {
|
||||||
@ -78,13 +71,6 @@ public class SafeSpotTeleport {
|
|||||||
} else {
|
} else {
|
||||||
// If this is not a portal teleport, then go to the safe location immediately
|
// If this is not a portal teleport, then go to the safe location immediately
|
||||||
entity.teleport(location);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,20 +111,13 @@ public class SafeSpotTeleport {
|
|||||||
if (portal && bestSpot != null) {
|
if (portal && bestSpot != null) {
|
||||||
// Portals found, teleport to the best spot we found
|
// Portals found, teleport to the best spot we found
|
||||||
teleportEntity(bestSpot);
|
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) {
|
} else if (entity instanceof Player) {
|
||||||
// Failed, no safe spot
|
// Failed, no safe spot
|
||||||
if (!failureMessage.isEmpty()) {
|
if (!failureMessage.isEmpty()) {
|
||||||
User.getInstance(entity).notify(failureMessage);
|
User.getInstance(entity).notify(failureMessage);
|
||||||
}
|
}
|
||||||
if (overrideGamemode && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) {
|
if (!plugin.getIWM().inWorld(entity.getLocation())) {
|
||||||
if (plugin.getIWM().inWorld(entity.getLocation())) {
|
|
||||||
((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(entity.getWorld()));
|
|
||||||
} else {
|
|
||||||
// Last resort
|
// Last resort
|
||||||
((Player)entity).setGameMode(GameMode.SURVIVAL);
|
|
||||||
if (Bukkit.getServer().isPrimaryThread()) {
|
if (Bukkit.getServer().isPrimaryThread()) {
|
||||||
((Player)entity).performCommand("spawn");
|
((Player)entity).performCommand("spawn");
|
||||||
} else {
|
} else {
|
||||||
@ -146,7 +125,6 @@ public class SafeSpotTeleport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,17 +225,8 @@ public class SafeSpotTeleport {
|
|||||||
}
|
}
|
||||||
Vector velocity = entity.getVelocity();
|
Vector velocity = entity.getVelocity();
|
||||||
entity.teleport(loc);
|
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 boolean portal = false;
|
||||||
private String failureMessage = "";
|
private String failureMessage = "";
|
||||||
private Location location;
|
private Location location;
|
||||||
private boolean overrideGamemode = true;
|
|
||||||
|
|
||||||
public Builder(BentoBox plugin) {
|
public Builder(BentoBox plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -402,9 +370,10 @@ public class SafeSpotTeleport {
|
|||||||
* Sets whether the player's gamemode should be overridden. Default is <tt>true</tt>
|
* Sets whether the player's gamemode should be overridden. Default is <tt>true</tt>
|
||||||
* @param overrideGamemode whether the player's gamemode should be overridden.
|
* @param overrideGamemode whether the player's gamemode should be overridden.
|
||||||
* @return Builder
|
* @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) {
|
public Builder overrideGamemode(boolean overrideGamemode) {
|
||||||
this.overrideGamemode = overrideGamemode;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,7 +395,7 @@ public class SafeSpotTeleport {
|
|||||||
if (failureMessage.isEmpty() && entity instanceof Player) {
|
if (failureMessage.isEmpty() && entity instanceof Player) {
|
||||||
failureMessage = "general.errors.no-safe-location-found";
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -137,7 +137,6 @@ public class InvincibleVisitorsListenerTest {
|
|||||||
when(panel.getInventory()).thenReturn(top);
|
when(panel.getInventory()).thenReturn(top);
|
||||||
|
|
||||||
when(Bukkit.createInventory(Mockito.any(), Mockito.anyInt(), Mockito.any())).thenReturn(top);
|
when(Bukkit.createInventory(Mockito.any(), Mockito.anyInt(), Mockito.any())).thenReturn(top);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -244,7 +243,6 @@ public class InvincibleVisitorsListenerTest {
|
|||||||
// Player should be teleported to this island
|
// Player should be teleported to this island
|
||||||
listener.onVisitorGetDamage(e);
|
listener.onVisitorGetDamage(e);
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
Mockito.verify(player).setGameMode(Mockito.eq(GameMode.SPECTATOR));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -255,7 +253,6 @@ public class InvincibleVisitorsListenerTest {
|
|||||||
// Player should die
|
// Player should die
|
||||||
listener.onVisitorGetDamage(e);
|
listener.onVisitorGetDamage(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
Mockito.verify(player, Mockito.never()).setGameMode(Mockito.eq(GameMode.SPECTATOR));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -266,9 +263,6 @@ public class InvincibleVisitorsListenerTest {
|
|||||||
// Player should be teleported to their island
|
// Player should be teleported to their island
|
||||||
listener.onVisitorGetDamage(e);
|
listener.onVisitorGetDamage(e);
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
Mockito.verify(player, Mockito.never()).setGameMode(Mockito.eq(GameMode.SPECTATOR));
|
|
||||||
Mockito.verify(im).homeTeleport(Mockito.any(), Mockito.eq(player));
|
Mockito.verify(im).homeTeleport(Mockito.any(), Mockito.eq(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public class SafeSpotTeleportBuilderTest {
|
|||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
sstb = new SafeSpotTeleport.Builder(plugin);
|
sstb = new SafeSpotTeleport.Builder(plugin);
|
||||||
sstb.build();
|
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);
|
assertEquals(sst, ttt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package world.bentobox.bentobox.util.teleport;
|
package world.bentobox.bentobox.util.teleport;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
@ -109,14 +106,13 @@ public class SafeSpotTeleportTest {
|
|||||||
|
|
||||||
// Player
|
// Player
|
||||||
// Return first survival and then spectator
|
// 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.getWorld()).thenReturn(world);
|
||||||
when(loc.getBlockX()).thenReturn(0);
|
when(loc.getBlockX()).thenReturn(0);
|
||||||
when(loc.getBlockY()).thenReturn(120);
|
when(loc.getBlockY()).thenReturn(120);
|
||||||
when(loc.getBlockZ()).thenReturn(0);
|
when(loc.getBlockZ()).thenReturn(0);
|
||||||
Block block = mock(Block.class);
|
Block block = mock(Block.class);
|
||||||
when(loc.getBlock()).thenReturn(block);
|
when(loc.getBlock()).thenReturn(block);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,23 +122,8 @@ public class SafeSpotTeleportTest {
|
|||||||
public void testSafeSpotTeleportImmediateSafe() throws Exception {
|
public void testSafeSpotTeleportImmediateSafe() throws Exception {
|
||||||
boolean portal = false;
|
boolean portal = false;
|
||||||
int homeNumber = 1;
|
int homeNumber = 1;
|
||||||
new SafeSpotTeleport(plugin, player, loc, "failure message", portal, homeNumber, true);
|
new SafeSpotTeleport(plugin, player, loc, "failure message", portal, homeNumber);
|
||||||
Mockito.verify(player).setGameMode(GameMode.SPECTATOR);
|
|
||||||
Mockito.verify(player).teleport(loc);
|
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);
|
when(im.isSafeLocation(Mockito.any())).thenReturn(false);
|
||||||
boolean portal = false;
|
boolean portal = false;
|
||||||
int homeNumber = 1;
|
int homeNumber = 1;
|
||||||
new SafeSpotTeleport(plugin, player, loc, "failure message", portal, homeNumber, true);
|
new SafeSpotTeleport(plugin, player, loc, "failure message", portal, homeNumber);
|
||||||
Mockito.verify(player).setGameMode(GameMode.SPECTATOR);
|
|
||||||
Mockito.verify(player, Mockito.never()).teleport(loc);
|
Mockito.verify(player, Mockito.never()).teleport(loc);
|
||||||
Mockito.verify(sch).runTaskTimer(Mockito.any(), Mockito.any(Runnable.class), Mockito.eq(0L), Mockito.eq(1L));
|
Mockito.verify(sch).runTaskTimer(Mockito.any(), Mockito.any(Runnable.class), Mockito.eq(0L), Mockito.eq(1L));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user