Fixed portal teleportation listener

The reason the test was failing was because the check on whether the
player had an island or not was not being done. I added the check back
in. So now, if a player has no island, the portal will just do nothing.
This commit is contained in:
tastybento 2019-02-19 23:27:11 -08:00
parent e56d6715af
commit 96dda2c96d
2 changed files with 14 additions and 13 deletions

View File

@ -63,11 +63,12 @@ public class PortalTeleportationListener implements Listener {
// To Standard end
e.setTo(plugin.getIWM().getEndWorld(fromWorld).getSpawnLocation());
}
// From standard end
else {
// From standard end - check if player has an island to go to
else if (plugin.getIslands().hasIsland(Util.getWorld(fromWorld), e.getPlayer().getUniqueId())) {
e.setCancelled(true);
plugin.getIslands().homeTeleport(Util.getWorld(fromWorld), e.getPlayer());
}
// No island, so just do nothing
return false;
}
@ -81,10 +82,10 @@ public class PortalTeleportationListener implements Listener {
e.setCancelled(true);
// Else other worlds teleport to the nether
new SafeSpotTeleport.Builder(plugin)
.entity(e.getPlayer())
.location(to)
.portal()
.build();
.entity(e.getPlayer())
.location(to)
.portal()
.build();
return true;
}
// TO END
@ -94,10 +95,10 @@ public class PortalTeleportationListener implements Listener {
e.setCancelled(true);
// Else other worlds teleport to the nether
new SafeSpotTeleport.Builder(plugin)
.entity(e.getPlayer())
.location(to)
.portal()
.build();
.entity(e.getPlayer())
.location(to)
.portal()
.build();
return true;
}

View File

@ -21,7 +21,6 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.util.Vector;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
@ -70,6 +69,9 @@ public class PortalTeleportationListenerTest {
when(nether.getEnvironment()).thenReturn(Environment.NETHER);
end = mock(World.class);
when(end.getEnvironment()).thenReturn(Environment.THE_END);
Location endSpawn = mock(Location.class);
when(endSpawn.getWorld()).thenReturn(end);
when(end.getSpawnLocation()).thenReturn(endSpawn);
when(iwm.getEndWorld(Mockito.any())).thenReturn(end);
when(iwm.isEndGenerate(Mockito.any())).thenReturn(true);
when(iwm.getIslandWorld(Mockito.any())).thenReturn(world);
@ -191,7 +193,6 @@ public class PortalTeleportationListenerTest {
/**
* Test method for {@link PortalTeleportationListener#onEndIslandPortal(org.bukkit.event.player.PlayerPortalEvent)}.
*/
@Ignore
@Test
public void testOnEndIslandPortalWrongWorld() {
PortalTeleportationListener np = new PortalTeleportationListener(plugin);
@ -209,7 +210,6 @@ public class PortalTeleportationListenerTest {
/**
* Test method for {@link PortalTeleportationListener#onEndIslandPortal(org.bukkit.event.player.PlayerPortalEvent)}.
*/
@Ignore
@Test
public void testOnEndIslandPortalHome() {
PortalTeleportationListener np = new PortalTeleportationListener(plugin);