Merge branch 'develop' into rank_management

This commit is contained in:
tastybento 2023-11-10 10:53:08 -08:00 committed by GitHub
commit 8c2ff93d35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 145 additions and 122 deletions

View File

@ -7,6 +7,7 @@
package world.bentobox.bentobox.listeners.teleports;
import java.util.Objects;
import java.util.UUID;
import org.bukkit.Bukkit;
@ -77,8 +78,29 @@ public class EntityTeleportListener extends AbstractTeleportListener implements
event.setCancelled(true);
return;
}
// Trigger event processor.
this.portalProcess(event, event.getTo().getWorld().getEnvironment());
// Check which teleportation is happening.
World.Environment source = fromWorld.getEnvironment();
World.Environment destination = event.getTo().getWorld().getEnvironment();
if (World.Environment.NETHER == source && World.Environment.NORMAL == destination ||
World.Environment.NORMAL == source && World.Environment.NETHER == destination)
{
// Nether to overworld or opposite
this.portalProcess(event, World.Environment.NETHER);
}
else if (World.Environment.THE_END == source && World.Environment.NORMAL == destination ||
World.Environment.NORMAL == source && World.Environment.THE_END == destination)
{
// end to overworld or opposite
this.portalProcess(event, World.Environment.THE_END);
}
else
{
// unknown teleportation
this.portalProcess(event, event.getTo().getWorld().getEnvironment());
}
}
@ -224,32 +246,24 @@ public class EntityTeleportListener extends AbstractTeleportListener implements
}
this.inTeleport.add(event.getEntity().getUniqueId());
// Get target world.
World toWorld;
if (environment.equals(World.Environment.NORMAL))
{
toWorld = overWorld;
}
else
{
toWorld = this.getNetherEndWorld(overWorld, environment);
}
if (!overWorld.equals(toWorld) && !this.isIslandWorld(overWorld, environment))
if (fromWorld.equals(overWorld) && !this.isIslandWorld(overWorld, environment))
{
// This is not island world. Use standard nether or end world teleportation.
this.handleToStandardNetherOrEnd(event, overWorld, toWorld);
this.handleToStandardNetherOrEnd(event, overWorld, environment);
return;
}
if (!overWorld.equals(fromWorld) && !this.isIslandWorld(overWorld, environment))
if (!fromWorld.equals(overWorld) && !this.isIslandWorld(overWorld, environment))
{
// If entering a portal in the other world, teleport to a portal in overworld if
// there is one
this.handleFromStandardNetherOrEnd(event, overWorld, toWorld.getEnvironment());
this.handleFromStandardNetherOrEnd(event, overWorld, environment);
return;
}
// To the nether/end or overworld.
World toWorld = !fromWorld.getEnvironment().equals(environment) ?
this.getNetherEndWorld(overWorld, environment) : overWorld;
// Set the destination location
// If portals cannot be created, then destination is the spawn point, otherwise it's the vector
@ -286,7 +300,7 @@ public class EntityTeleportListener extends AbstractTeleportListener implements
// Let the server teleport
return;
}
if (environment.equals(World.Environment.THE_END))
{
// Prevent death from hitting the ground while calculating location.
@ -324,10 +338,11 @@ public class EntityTeleportListener extends AbstractTeleportListener implements
* Handle teleport to standard nether or end
* @param event - EntityPortalEvent
* @param overWorld - over world
* @param toWorld - to world
* @param environment - to target environment
*/
private void handleToStandardNetherOrEnd(EntityPortalEvent event, World overWorld, World toWorld)
private void handleToStandardNetherOrEnd(EntityPortalEvent event, World overWorld, World.Environment environment)
{
World toWorld = Objects.requireNonNull(this.getNetherEndWorld(overWorld, environment));
Location spawnPoint = toWorld.getSpawnLocation();
// If going to the nether and nether portals are active then just teleport to approx location
@ -345,7 +360,7 @@ public class EntityTeleportListener extends AbstractTeleportListener implements
toWorld.setSpawnLocation(100, 50, 0);
}
if (this.isAllowedOnServer(toWorld.getEnvironment()))
if (this.isAllowedOnServer(environment))
{
// To Standard Nether or end
event.setTo(spawnPoint);

View File

@ -301,7 +301,7 @@ public class PlayerTeleportListener extends AbstractTeleportListener implements
// Find the distance from edge of island's protection and set the search radius
this.getIsland(event.getTo()).ifPresent(island ->
event.setSearchRadius(this.calculateSearchRadius(event.getTo(), island)));
event.setSearchRadius(this.calculateSearchRadius(event.getTo(), island)));
// Check if there is an island there or not
if (this.isPastingMissingIslands(overWorld) &&
@ -327,7 +327,7 @@ public class PlayerTeleportListener extends AbstractTeleportListener implements
return;
}
if (environment.equals(World.Environment.THE_END))
if (World.Environment.THE_END.equals(environment))
{
// Prevent death from hitting the ground while calculating location.
event.getPlayer().setVelocity(new Vector(0,0,0));
@ -374,14 +374,14 @@ public class PlayerTeleportListener extends AbstractTeleportListener implements
Location spawnPoint = toWorld.getSpawnLocation();
// If going to the nether and nether portals are active then just teleport to approx location
if (environment.equals(World.Environment.NETHER) &&
if (World.Environment.NETHER.equals(environment) &&
this.plugin.getIWM().getWorldSettings(overWorld).isMakeNetherPortals())
{
spawnPoint = event.getFrom().toVector().toLocation(toWorld);
}
// If spawn is set as 0,63,0 in the End then move it to 100, 50 ,0.
if (environment.equals(World.Environment.THE_END) && spawnPoint.getBlockX() == 0 && spawnPoint.getBlockZ() == 0)
if (World.Environment.THE_END.equals(environment) && spawnPoint.getBlockX() == 0 && spawnPoint.getBlockZ() == 0)
{
// Set to the default end spawn
spawnPoint = new Location(toWorld, 100, 50, 0);
@ -413,7 +413,7 @@ public class PlayerTeleportListener extends AbstractTeleportListener implements
*/
private void handleFromStandardNetherOrEnd(PlayerPortalEvent event, World overWorld, World.Environment environment)
{
if (environment.equals(World.Environment.NETHER) &&
if (World.Environment.NETHER.equals(environment) &&
this.plugin.getIWM().getWorldSettings(overWorld).isMakeNetherPortals())
{
// Set to location directly to the from location.

View File

@ -34,50 +34,51 @@ import world.bentobox.bentobox.util.Util;
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({BentoBox.class, Util.class, Bukkit.class })
@PrepareForTest({ BentoBox.class, Util.class, Bukkit.class })
public class EntityTeleportListenerTest extends AbstractCommonSetup {
private EntityTeleportListener etl;
@Mock
private IslandsManager im;
private EntityTeleportListener etl;
@Mock
private IslandsManager im;
/**
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
when(plugin.getIslands()).thenReturn(im);
when(plugin.getIslandsManager()).thenReturn(im);
when(im.getProtectedIslandAt(any())).thenReturn(Optional.of(island));
etl = new EntityTeleportListener(plugin);
}
/**
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
/**
* Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#EntityTeleportListener(world.bentobox.bentobox.BentoBox)}.
*/
@Test
public void testEntityTeleportListener() {
assertNotNull(etl);
}
when(plugin.getIslands()).thenReturn(im);
when(plugin.getIslandsManager()).thenReturn(im);
/**
* Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
public void testOnEntityPortalWrongWorld() {
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
when(Util.getWorld(any())).thenReturn(null);
EntityPortalEvent event = new EntityPortalEvent(player, location, location, 10);
etl.onEntityPortal(event);
assertFalse(event.isCancelled());
}
/**
when(im.getProtectedIslandAt(any())).thenReturn(Optional.of(island));
etl = new EntityTeleportListener(plugin);
}
/**
* Test method for
* {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#EntityTeleportListener(world.bentobox.bentobox.BentoBox)}.
*/
@Test
public void testEntityTeleportListener() {
assertNotNull(etl);
}
/**
* Test method for
* {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
public void testOnEntityPortalWrongWorld() {
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
when(Util.getWorld(any())).thenReturn(null);
EntityPortalEvent event = new EntityPortalEvent(player, location, location, 10);
etl.onEntityPortal(event);
assertFalse(event.isCancelled());
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
@ -87,44 +88,47 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
etl.onEntityPortal(event);
assertFalse(event.isCancelled());
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
public void testOnEntityPortalNullTo() {
EntityPortalEvent event = new EntityPortalEvent(player, location, null, 10);
etl.onEntityPortal(event);
assertFalse(event.isCancelled());
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
public void testOnEntityPortalTeleportDisabled() {
EntityPortalEvent event = new EntityPortalEvent(player, location, location, 10);
etl.onEntityPortal(event);
assertTrue(event.isCancelled());
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
public void testOnEntityPortalTeleportEnabled() {
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
when(Util.getWorld(any())).thenReturn(world);
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
Flags.ENTITY_PORTAL_TELEPORT.setSetting(world, true);
EntityPortalEvent event = new EntityPortalEvent(player, location, location, 10);
etl.onEntityPortal(event);
assertFalse(event.isCancelled());
}
/**
/**
* Test method for
* {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
public void testOnEntityPortalNullTo() {
EntityPortalEvent event = new EntityPortalEvent(player, location, null, 10);
etl.onEntityPortal(event);
assertFalse(event.isCancelled());
}
/**
* Test method for
* {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
public void testOnEntityPortalTeleportDisabled() {
EntityPortalEvent event = new EntityPortalEvent(player, location, location, 10);
etl.onEntityPortal(event);
assertTrue(event.isCancelled());
}
/**
* Test method for
* {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
public void testOnEntityPortalTeleportEnabled() {
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
when(Util.getWorld(any())).thenReturn(world);
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
Flags.ENTITY_PORTAL_TELEPORT.setSetting(world, true);
EntityPortalEvent event = new EntityPortalEvent(player, location, location, 10);
etl.onEntityPortal(event);
assertFalse(event.isCancelled());
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
@ -139,15 +143,15 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
when(Util.getWorld(any())).thenReturn(world2);
when(location.getWorld()).thenReturn(null);
when(location.getWorld()).thenReturn(world);
Flags.ENTITY_PORTAL_TELEPORT.setSetting(world, true);
EntityPortalEvent event = new EntityPortalEvent(player, location, location2, 10);
etl.onEntityPortal(event);
assertTrue(event.isCancelled());
}
/**
/**
* Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
@ -168,12 +172,14 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
assertTrue(event.isCancelled());
}
/**
/**
* Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityPortal(org.bukkit.event.entity.EntityPortalEvent)}.
*/
@Test
public void testOnEntityPortalTeleportEnabledIsAllowedInConfig() {
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
when(iwm.isNetherGenerate(any())).thenReturn(true);
when(iwm.isNetherIslands(any())).thenReturn(true);
@ -192,18 +198,20 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityEnterPortal(org.bukkit.event.entity.EntityPortalEnterEvent)}.
*/
@Test
public void testOnEntityEnterPortal() {
}
/**
* Test method for
* {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityEnterPortal(org.bukkit.event.entity.EntityPortalEnterEvent)}.
*/
@Test
public void testOnEntityEnterPortal() {
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityExitPortal(org.bukkit.event.entity.EntityPortalExitEvent)}.
*/
@Test
public void testOnEntityExitPortal() {
}
/**
* Test method for
* {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityExitPortal(org.bukkit.event.entity.EntityPortalExitEvent)}.
*/
@Test
public void testOnEntityExitPortal() {
}
}