mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-16 07:45:12 +01:00
Change behavior of teleporting to default nether
If create-and-link-portals is true, then teleporting to the nether will not go to a central portal point and instead create a portal in the nether at the same coordinates as the portal in the overworld. Teleporting back will not be affected. https://github.com/BentoBoxWorld/BSkyBlock/issues/464
This commit is contained in:
parent
94b982f644
commit
9062aab34b
@ -395,6 +395,10 @@ public class PortalTeleportationListener implements Listener {
|
|||||||
if (fromWorld.getEnvironment() != env) {
|
if (fromWorld.getEnvironment() != env) {
|
||||||
World toWorld = Objects.requireNonNull(getNetherEndWorld(overWorld, env));
|
World toWorld = Objects.requireNonNull(getNetherEndWorld(overWorld, env));
|
||||||
Location spawnPoint = toWorld.getSpawnLocation();
|
Location spawnPoint = toWorld.getSpawnLocation();
|
||||||
|
// If going to the nether and nether portals are active then just teleport to approx location
|
||||||
|
if (env.equals(Environment.NETHER) && plugin.getIWM().getWorldSettings(overWorld).isMakeNetherPortals()) {
|
||||||
|
spawnPoint = e.getFrom().toVector().toLocation(toWorld);
|
||||||
|
}
|
||||||
// If spawn is set as 0,63,0 in the End then move it to 100, 50 ,0.
|
// If spawn is set as 0,63,0 in the End then move it to 100, 50 ,0.
|
||||||
if (env.equals(Environment.THE_END) && spawnPoint.getBlockX() == 0 && spawnPoint.getBlockZ() == 0) {
|
if (env.equals(Environment.THE_END) && spawnPoint.getBlockX() == 0 && spawnPoint.getBlockZ() == 0) {
|
||||||
// Set to the default end spawn
|
// Set to the default end spawn
|
||||||
|
@ -109,6 +109,10 @@ public class StandardSpawnProtectionListener implements Listener {
|
|||||||
* @return true if in the spawn area, false if not
|
* @return true if in the spawn area, false if not
|
||||||
*/
|
*/
|
||||||
private boolean atSpawn(@NonNull Location location) {
|
private boolean atSpawn(@NonNull Location location) {
|
||||||
|
if (plugin.getIWM().getWorldSettings(location.getWorld()).isMakeNetherPortals()) {
|
||||||
|
// If nether portals are active, there is no common spawn
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Vector p = location.toVector().multiply(new Vector(1, 0, 1));
|
Vector p = location.toVector().multiply(new Vector(1, 0, 1));
|
||||||
Vector spawn = location.getWorld().getSpawnLocation().toVector().multiply(new Vector(1, 0, 1));
|
Vector spawn = location.getWorld().getSpawnLocation().toVector().multiply(new Vector(1, 0, 1));
|
||||||
int radius = plugin.getIWM().getNetherSpawnRadius(location.getWorld());
|
int radius = plugin.getIWM().getNetherSpawnRadius(location.getWorld());
|
||||||
@ -118,6 +122,7 @@ public class StandardSpawnProtectionListener implements Listener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If the player is not in the standard nether or standard end or op, do nothing.
|
* If the player is not in the standard nether or standard end or op, do nothing.
|
||||||
|
* If portal making is true, then do not protect spawn.
|
||||||
* Used to protect the standard spawn for nether or end.
|
* Used to protect the standard spawn for nether or end.
|
||||||
*
|
*
|
||||||
* @param player - the player
|
* @param player - the player
|
||||||
@ -127,6 +132,8 @@ public class StandardSpawnProtectionListener implements Listener {
|
|||||||
return (player.isOp() || player.getWorld().getEnvironment().equals(World.Environment.NORMAL)
|
return (player.isOp() || player.getWorld().getEnvironment().equals(World.Environment.NORMAL)
|
||||||
|| !plugin.getIWM().inWorld(Util.getWorld(player.getWorld()))
|
|| !plugin.getIWM().inWorld(Util.getWorld(player.getWorld()))
|
||||||
|| (player.getWorld().getEnvironment().equals(World.Environment.NETHER) && plugin.getIWM().isNetherIslands(player.getWorld()))
|
|| (player.getWorld().getEnvironment().equals(World.Environment.NETHER) && plugin.getIWM().isNetherIslands(player.getWorld()))
|
||||||
|
|| (player.getWorld().getEnvironment().equals(World.Environment.NETHER) && plugin.getIWM().getWorldSettings(player.getWorld()).isMakeNetherPortals())
|
||||||
|| (player.getWorld().getEnvironment().equals(World.Environment.THE_END) && plugin.getIWM().isEndIslands(player.getWorld())));
|
|| (player.getWorld().getEnvironment().equals(World.Environment.THE_END) && plugin.getIWM().isEndIslands(player.getWorld())));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,7 @@ public class PortalTeleportationListenerTest {
|
|||||||
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
||||||
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
||||||
when(iwm.getNetherSpawnRadius(any())).thenReturn(100);
|
when(iwm.getNetherSpawnRadius(any())).thenReturn(100);
|
||||||
|
when(iwm.getWorldSettings(any())).thenReturn(ws);
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
|
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
|
||||||
@ -186,6 +187,9 @@ public class PortalTeleportationListenerTest {
|
|||||||
// Player
|
// Player
|
||||||
when(player.getType()).thenReturn(EntityType.PLAYER);
|
when(player.getType()).thenReturn(EntityType.PLAYER);
|
||||||
|
|
||||||
|
// Bukkit
|
||||||
|
when(Bukkit.getAllowNether()).thenReturn(true);
|
||||||
|
when(Bukkit.getAllowEnd()).thenReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@ -465,6 +469,29 @@ public class PortalTeleportationListenerTest {
|
|||||||
assertTrue(np.onIslandPortal(e));
|
assertTrue(np.onIslandPortal(e));
|
||||||
// Verify
|
// Verify
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
|
// We are not going to 1,2,3
|
||||||
|
assertFalse(e.getTo().toString().contains("x=1.0,y=2.0,z=3.0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link PortalTeleportationListener#onIslandPortal(org.bukkit.event.player.PlayerPortalEvent)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testonIslandPortalFromWorldToNetherStandardMakePortals() {
|
||||||
|
when(ws.isMakeNetherPortals()).thenReturn(true);
|
||||||
|
PortalTeleportationListener np = new PortalTeleportationListener(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(player, from, null, TeleportCause.NETHER_PORTAL);
|
||||||
|
// Nether islands inactive
|
||||||
|
when(iwm.isNetherIslands(any())).thenReturn(false);
|
||||||
|
when(iwm.isNetherGenerate(any())).thenReturn(true);
|
||||||
|
assertTrue(np.onIslandPortal(e));
|
||||||
|
// Verify
|
||||||
|
assertFalse(e.isCancelled());
|
||||||
|
assertTrue(e.getTo().toString().contains("x=1.0,y=2.0,z=3.0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,6 +40,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
|||||||
import org.powermock.reflect.Whitebox;
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
@ -82,6 +83,8 @@ public class StandardSpawnProtectionListenerTest {
|
|||||||
private BlockState blockState;
|
private BlockState blockState;
|
||||||
@Mock
|
@Mock
|
||||||
private Location spawnLocation;
|
private Location spawnLocation;
|
||||||
|
@Mock
|
||||||
|
private WorldSettings ws;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
@ -105,6 +108,7 @@ public class StandardSpawnProtectionListenerTest {
|
|||||||
when(iwm.isEndIslands(any())).thenReturn(false);
|
when(iwm.isEndIslands(any())).thenReturn(false);
|
||||||
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
||||||
when(iwm.getNetherSpawnRadius(any())).thenReturn(25);
|
when(iwm.getNetherSpawnRadius(any())).thenReturn(25);
|
||||||
|
when(iwm.getWorldSettings(any())).thenReturn(ws);
|
||||||
// Util
|
// Util
|
||||||
PowerMockito.mockStatic(Util.class);
|
PowerMockito.mockStatic(Util.class);
|
||||||
when(Util.getWorld(any())).thenReturn(world);
|
when(Util.getWorld(any())).thenReturn(world);
|
||||||
@ -157,6 +161,18 @@ public class StandardSpawnProtectionListenerTest {
|
|||||||
verify(player).sendMessage("protection.spawn-protected");
|
verify(player).sendMessage("protection.spawn-protected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOnBlockPlaceDisallowedNoProtection() {
|
||||||
|
when(iwm.isNetherIslands(any())).thenReturn(true);
|
||||||
|
BlockPlaceEvent e = new BlockPlaceEvent(block, blockState, null, null, player, true, EquipmentSlot.HAND);
|
||||||
|
ssp.onBlockPlace(e);
|
||||||
|
assertFalse(e.isCancelled());
|
||||||
|
verify(player, never()).sendMessage("protection.spawn-protected");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
|
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
|
||||||
*/
|
*/
|
||||||
@ -232,6 +248,18 @@ public class StandardSpawnProtectionListenerTest {
|
|||||||
verify(player).sendMessage("protection.spawn-protected");
|
verify(player).sendMessage("protection.spawn-protected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockBreak(org.bukkit.event.block.BlockBreakEvent)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOnBlockBreakDisallowedNoProtection() {
|
||||||
|
when(ws.isMakeNetherPortals()).thenReturn(true);
|
||||||
|
BlockBreakEvent e = new BlockBreakEvent(block, player);
|
||||||
|
ssp.onBlockBreak(e);
|
||||||
|
assertFalse(e.isCancelled());
|
||||||
|
verify(player, never()).sendMessage("protection.spawn-protected");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockBreak(org.bukkit.event.block.BlockBreakEvent)}.
|
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockBreak(org.bukkit.event.block.BlockBreakEvent)}.
|
||||||
*/
|
*/
|
||||||
@ -267,6 +295,32 @@ public class StandardSpawnProtectionListenerTest {
|
|||||||
assertEquals(1, blockList.size());
|
assertEquals(1, blockList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOnExplosionNoProtection() {
|
||||||
|
when(ws.isMakeNetherPortals()).thenReturn(true);
|
||||||
|
List<Block> blockList = new ArrayList<>();
|
||||||
|
blockList.add(block);
|
||||||
|
blockList.add(block);
|
||||||
|
blockList.add(block);
|
||||||
|
blockList.add(block);
|
||||||
|
blockList.add(block);
|
||||||
|
// Make some inside and outside spawn
|
||||||
|
when(location.toVector()).thenReturn(new Vector(0,0,0),
|
||||||
|
new Vector(0,0,0),
|
||||||
|
new Vector(0,0,0),
|
||||||
|
new Vector(0,0,0),
|
||||||
|
new Vector(10000,0,0));
|
||||||
|
EntityExplodeEvent e = new EntityExplodeEvent(player, location, blockList, 0);
|
||||||
|
ssp.onExplosion(e);
|
||||||
|
// No blocks should be removed
|
||||||
|
assertEquals(5, blockList.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBucketEmpty(org.bukkit.event.player.PlayerBucketEmptyEvent)}.
|
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBucketEmpty(org.bukkit.event.player.PlayerBucketEmptyEvent)}.
|
||||||
*/
|
*/
|
||||||
@ -278,6 +332,18 @@ public class StandardSpawnProtectionListenerTest {
|
|||||||
verify(player).sendMessage("protection.spawn-protected");
|
verify(player).sendMessage("protection.spawn-protected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBucketEmpty(org.bukkit.event.player.PlayerBucketEmptyEvent)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOnBucketEmptyDisallowedNoProtection() {
|
||||||
|
when(ws.isMakeNetherPortals()).thenReturn(true);
|
||||||
|
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.DOWN, null, null);
|
||||||
|
ssp.onBucketEmpty(e);
|
||||||
|
assertFalse(e.isCancelled());
|
||||||
|
verify(player, never()).sendMessage("protection.spawn-protected");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBucketEmpty(org.bukkit.event.player.PlayerBucketEmptyEvent)}.
|
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBucketEmpty(org.bukkit.event.player.PlayerBucketEmptyEvent)}.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user