mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-21 16:47:39 +01:00
Fixed test failures.
Fixed bug where spawn locs could be null.
This commit is contained in:
parent
a663395a13
commit
94bc2355ac
@ -1,5 +1,7 @@
|
||||
package us.tastybento.bskyblock.listeners;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -117,7 +119,7 @@ public class NetherPortals implements Listener {
|
||||
if (plugin.getIWM().isEndGenerate(overWorld) && plugin.getIWM().isEndIslands(overWorld)) {
|
||||
World endWorld = plugin.getIWM().getEndWorld(overWorld);
|
||||
// End exists and end islands are being used
|
||||
Location to = plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.THE_END)).orElse(e.getFrom().toVector().toLocation(endWorld));
|
||||
Location to = plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.THE_END)).filter(Objects::nonNull).orElse(e.getFrom().toVector().toLocation(endWorld));
|
||||
e.setCancelled(true);
|
||||
new SafeTeleportBuilder(plugin)
|
||||
.entity(e.getPlayer())
|
||||
@ -177,7 +179,7 @@ public class NetherPortals implements Listener {
|
||||
if (e.getFrom().getWorld().getEnvironment().equals(Environment.NETHER)) {
|
||||
// If this is from the island nether, then go to the same vector, otherwise try island home location
|
||||
Location to = plugin.getIWM().isNetherIslands(overWorld)
|
||||
? plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.NORMAL)).orElse(e.getFrom().toVector().toLocation(overWorld))
|
||||
? plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.NORMAL)).filter(Objects::nonNull).orElse(e.getFrom().toVector().toLocation(overWorld))
|
||||
: plugin.getIslands().getIslandLocation(overWorld, e.getPlayer().getUniqueId());
|
||||
|
||||
e.setCancelled(true);
|
||||
@ -192,7 +194,7 @@ public class NetherPortals implements Listener {
|
||||
World nether = plugin.getIWM().getNetherWorld(overWorld);
|
||||
// If this is to island nether, then go to the same vector, otherwise try spawn
|
||||
Location to = (plugin.getIWM().isNetherIslands(overWorld) && plugin.getIWM().isNetherGenerate(overWorld))
|
||||
? plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.NETHER)).orElse(e.getFrom().toVector().toLocation(nether))
|
||||
? plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.NETHER)).filter(Objects::nonNull).orElse(e.getFrom().toVector().toLocation(nether))
|
||||
: nether.getSpawnLocation();
|
||||
e.setCancelled(true);
|
||||
// Else other worlds teleport to the nether
|
||||
|
@ -12,6 +12,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -46,6 +47,7 @@ import org.powermock.reflect.Whitebox;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.Settings;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.managers.IslandWorldManager;
|
||||
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||
import us.tastybento.bskyblock.managers.LocalesManager;
|
||||
@ -125,6 +127,8 @@ public class NetherPortalsTest {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
||||
Optional<Island> optionalIsland = Optional.empty();
|
||||
when(im.getIslandAt(Mockito.any())).thenReturn(optionalIsland);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
@ -479,7 +483,7 @@ public class NetherPortalsTest {
|
||||
when(iwm.isNetherIslands(world)).thenReturn(false);
|
||||
|
||||
|
||||
// Real entity, next to spawn
|
||||
// Real entity, next to spawn
|
||||
en = mock(Entity.class);
|
||||
when(blockLoc.toVector()).thenReturn(new Vector(0,0,0));
|
||||
EntityExplodeEvent e = new EntityExplodeEvent(en, from, affectedBlocks, 0);
|
||||
@ -538,6 +542,69 @@ public class NetherPortalsTest {
|
||||
Mockito.verify(nether, Mockito.never()).getSpawnLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.listeners.NetherPortals#onNetherPortal(org.bukkit.event.player.PlayerPortalEvent)}.
|
||||
*/
|
||||
@Test
|
||||
public void testOnNetherPortalFromWorldToNetherIslandWithSpawnDefined() {
|
||||
NetherPortals np = new NetherPortals(plugin);
|
||||
Location from = mock(Location.class);
|
||||
// Teleport from world to nether
|
||||
when(from.getWorld()).thenReturn(world);
|
||||
when(from.toVector()).thenReturn(new Vector(1,2,3));
|
||||
PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL);
|
||||
// Nether islands active
|
||||
when(iwm.isNetherIslands(world)).thenReturn(true);
|
||||
when(iwm.isNetherGenerate(world)).thenReturn(true);
|
||||
|
||||
Island island = mock(Island.class);
|
||||
Location spawnLoc = mock(Location.class);
|
||||
when(island.getSpawnPoint(Mockito.any())).thenReturn(spawnLoc);
|
||||
Optional<Island> optionalIsland = Optional.of(island);
|
||||
// Island exists at location
|
||||
when(im.getIslandAt(Mockito.any())).thenReturn(optionalIsland);
|
||||
|
||||
|
||||
assertTrue(np.onNetherPortal(e));
|
||||
// Verify
|
||||
assertTrue(e.isCancelled());
|
||||
// If nether islands, then to = from but in nether
|
||||
Mockito.verify(from).toVector();
|
||||
// Do not go to spawn
|
||||
Mockito.verify(nether, Mockito.never()).getSpawnLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.listeners.NetherPortals#onNetherPortal(org.bukkit.event.player.PlayerPortalEvent)}.
|
||||
*/
|
||||
@Test
|
||||
public void testOnNetherPortalFromWorldToNetherIslandWithNoSpawnDefined() {
|
||||
NetherPortals np = new NetherPortals(plugin);
|
||||
Location from = mock(Location.class);
|
||||
// Teleport from world to nether
|
||||
when(from.getWorld()).thenReturn(world);
|
||||
when(from.toVector()).thenReturn(new Vector(1,2,3));
|
||||
PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL);
|
||||
// Nether islands active
|
||||
when(iwm.isNetherIslands(world)).thenReturn(true);
|
||||
when(iwm.isNetherGenerate(world)).thenReturn(true);
|
||||
|
||||
Island island = mock(Island.class);
|
||||
when(island.getSpawnPoint(Mockito.any())).thenReturn(null);
|
||||
Optional<Island> optionalIsland = Optional.of(island);
|
||||
// Island exists at location
|
||||
when(im.getIslandAt(Mockito.any())).thenReturn(optionalIsland);
|
||||
|
||||
|
||||
assertTrue(np.onNetherPortal(e));
|
||||
// Verify
|
||||
assertTrue(e.isCancelled());
|
||||
// If nether islands, then to = from but in nether
|
||||
Mockito.verify(from).toVector();
|
||||
// Do not go to spawn
|
||||
Mockito.verify(nether, Mockito.never()).getSpawnLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.listeners.NetherPortals#onNetherPortal(org.bukkit.event.player.PlayerPortalEvent)}.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user