mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-09-29 07:07:30 +02:00
Fixed IslandsManager#getSafeHomeLocation throwing NPE if world is not an island world
Fixes https://github.com/BentoBoxWorld/BentoBox/issues/1306 The method now properly returns null if the world is not an island world.
This commit is contained in:
parent
40240c7225
commit
46ba40b70d
@ -494,12 +494,17 @@ public class IslandsManager {
|
|||||||
* Determines a safe teleport spot on player's island or the team island
|
* Determines a safe teleport spot on player's island or the team island
|
||||||
* they belong to.
|
* they belong to.
|
||||||
*
|
*
|
||||||
* @param world - world to check
|
* @param world - world to check, not null
|
||||||
* @param user - the player
|
* @param user - the player, not null
|
||||||
* @param number - a number - starting home location e.g., 1
|
* @param number - a number - starting home location, e.g. 1
|
||||||
* @return Location of a safe teleport spot or null if one cannot be found
|
* @return Location of a safe teleport spot or {@code null} if one cannot be found or if the world is not an island world.
|
||||||
*/
|
*/
|
||||||
public Location getSafeHomeLocation(@NonNull World world, @NonNull User user, int number) {
|
public Location getSafeHomeLocation(@NonNull World world, @NonNull User user, int number) {
|
||||||
|
// Check if the world is a gamemode world
|
||||||
|
if (!plugin.getIWM().inWorld(world)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Try the numbered home location first
|
// Try the numbered home location first
|
||||||
Location l = plugin.getPlayers().getHomeLocation(world, user, number);
|
Location l = plugin.getPlayers().getHomeLocation(world, user, number);
|
||||||
|
|
||||||
|
@ -693,6 +693,17 @@ public class IslandsManagerTest {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getSafeHomeLocation(World, User, int)}.
|
||||||
|
* Ensures that the method returns {@code null} if the world is not an island world.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetSafeHomeLocationWorldNotIslandWorld() {
|
||||||
|
IslandsManager im = new IslandsManager(plugin);
|
||||||
|
when(iwm.inWorld(world)).thenReturn(false);
|
||||||
|
assertNull(im.getSafeHomeLocation(world, user, 0));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getSpawnPoint(World)}.
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getSpawnPoint(World)}.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user