Adds null check for world in portal teleport listener

This should not occur, but apparently, it can sometimes.

https://github.com/BentoBoxWorld/BentoBox/issues/583
This commit is contained in:
tastybento 2019-02-26 08:19:05 -08:00
parent b5a657de52
commit 2664acbe47
2 changed files with 26 additions and 1 deletions

View File

@ -52,7 +52,7 @@ public class PortalTeleportationListener implements Listener {
return false;
}
World fromWorld = e.getFrom().getWorld();
if (e.getCause() != TeleportCause.END_PORTAL || !plugin.getIWM().isEndGenerate(fromWorld)) {
if (fromWorld == null || e.getCause() != TeleportCause.END_PORTAL || !plugin.getIWM().isEndGenerate(fromWorld)) {
// Do nothing special
return false;
}

View File

@ -207,6 +207,31 @@ public class PortalTeleportationListenerTest {
assertFalse(e.isCancelled());
}
/**
* Test method for {@link PortalTeleportationListener#onEndIslandPortal(org.bukkit.event.player.PlayerPortalEvent)}.
*/
@Test
public void testOnEndIslandPortalNullLocation() {
PortalTeleportationListener np = new PortalTeleportationListener(plugin);
Location loc = null;
PlayerPortalEvent e = new PlayerPortalEvent(null, loc, null, null, TeleportCause.END_PORTAL);
assertFalse(np.onEndIslandPortal(e));
assertFalse(e.isCancelled());
}
/**
* Test method for {@link PortalTeleportationListener#onEndIslandPortal(org.bukkit.event.player.PlayerPortalEvent)}.
*/
@Test
public void testOnEndIslandPortalNullWorld() {
PortalTeleportationListener np = new PortalTeleportationListener(plugin);
Location loc = mock(Location.class);
when(loc.getWorld()).thenReturn(null);
PlayerPortalEvent e = new PlayerPortalEvent(null, loc, null, null, TeleportCause.END_PORTAL);
assertFalse(np.onEndIslandPortal(e));
assertFalse(e.isCancelled());
}
/**
* Test method for {@link PortalTeleportationListener#onEndIslandPortal(org.bukkit.event.player.PlayerPortalEvent)}.
*/