Teleports void visitors to same environment as they left.

https://github.com/BentoBoxWorld/BentoBox/issues/814
This commit is contained in:
tastybento 2019-07-05 21:46:09 -07:00
parent edd7bbf97a
commit d6b0859d40
2 changed files with 16 additions and 1 deletions

View File

@ -112,7 +112,13 @@ 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()) { 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(island ->
// Teleport
new SafeSpotTeleport.Builder(getPlugin())
.entity(p)
.location(island.getCenter().toVector().toLocation(p.getWorld()))
.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);
@ -122,5 +128,7 @@ public class InvincibleVisitorsListener extends FlagListener implements ClickHan
}
}
}
}

View File

@ -27,6 +27,8 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -114,6 +116,11 @@ public class InvincibleVisitorsListenerTest {
// Island Manager
Island island = mock(Island.class);
when(island.getOwner()).thenReturn(uuid);
@Nullable
Location location = mock(Location.class);
Vector vector = mock(Vector.class);
when(location.toVector()).thenReturn(vector);
when(island.getCenter()).thenReturn(location);
when(im.getIsland(Mockito.any(World.class), Mockito.any(User.class))).thenReturn(island);
optionalIsland = Optional.of(island);
// Visitor