mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-06 00:18:36 +01:00
Small optimization around utility sameworld check
May improve https://github.com/BentoBoxWorld/BentoBox/issues/676
This commit is contained in:
parent
8ac0f08285
commit
7882a77b14
@ -26,9 +26,22 @@ import world.bentobox.bentobox.lists.Flags;
|
||||
*/
|
||||
public class LockAndBanListener extends FlagListener {
|
||||
|
||||
/**
|
||||
* Result of checking the island for locked state or player bans
|
||||
*
|
||||
*/
|
||||
private enum CheckResult {
|
||||
/**
|
||||
* player is banned from island
|
||||
*/
|
||||
BANNED,
|
||||
/**
|
||||
* Island is locked
|
||||
*/
|
||||
LOCKED,
|
||||
/**
|
||||
* Island is open for teleporting
|
||||
*/
|
||||
OPEN
|
||||
}
|
||||
|
||||
|
@ -630,6 +630,9 @@ public class IslandsManager {
|
||||
.build();
|
||||
return;
|
||||
}
|
||||
if (!home.getChunk().isLoaded()) {
|
||||
home.getChunk().load();
|
||||
}
|
||||
player.teleport(home);
|
||||
if (number == 1) {
|
||||
user.sendMessage("commands.island.go.teleport");
|
||||
|
@ -201,9 +201,18 @@ public class Util {
|
||||
* @return true if the same
|
||||
*/
|
||||
public static boolean sameWorld(World world, World world2) {
|
||||
String worldName = world.getName().replaceAll(NETHER, "").replaceAll(THE_END, "");
|
||||
String world2Name = world2.getName().replaceAll(NETHER, "").replaceAll(THE_END, "");
|
||||
return worldName.equalsIgnoreCase(world2Name);
|
||||
return stripName(world).equals(stripName(world2));
|
||||
}
|
||||
|
||||
private static String stripName(World world) {
|
||||
switch (world.getEnvironment()) {
|
||||
case NETHER:
|
||||
return world.getName().substring(0, world.getName().length() - NETHER.length());
|
||||
case THE_END:
|
||||
return world.getName().substring(0, world.getName().length() - THE_END.length());
|
||||
default:
|
||||
return world.getName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,7 @@
|
||||
package world.bentobox.bentobox.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@ -170,7 +171,34 @@ public class UtilTest {
|
||||
*/
|
||||
@Test
|
||||
public void testSameWorld() {
|
||||
//fail("Not yet implemented"); // TODO
|
||||
World world = mock(World.class);
|
||||
World world2 = mock(World.class);
|
||||
World world3 = mock(World.class);
|
||||
World world4 = mock(World.class);
|
||||
when(world.getName()).thenReturn("world");
|
||||
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
||||
when(world2.getName()).thenReturn("world_nether");
|
||||
when(world2.getEnvironment()).thenReturn(World.Environment.NETHER);
|
||||
when(world3.getName()).thenReturn("world_the_end");
|
||||
when(world3.getEnvironment()).thenReturn(World.Environment.THE_END);
|
||||
when(world4.getName()).thenReturn("hfhhfhf_nether");
|
||||
when(world4.getEnvironment()).thenReturn(World.Environment.NETHER);
|
||||
|
||||
assertTrue(Util.sameWorld(world, world));
|
||||
assertTrue(Util.sameWorld(world2, world2));
|
||||
assertTrue(Util.sameWorld(world3, world3));
|
||||
assertTrue(Util.sameWorld(world, world2));
|
||||
assertTrue(Util.sameWorld(world, world3));
|
||||
assertTrue(Util.sameWorld(world2, world));
|
||||
assertTrue(Util.sameWorld(world2, world3));
|
||||
assertTrue(Util.sameWorld(world3, world2));
|
||||
assertTrue(Util.sameWorld(world3, world));
|
||||
assertFalse(Util.sameWorld(world4, world));
|
||||
assertFalse(Util.sameWorld(world4, world2));
|
||||
assertFalse(Util.sameWorld(world4, world3));
|
||||
assertFalse(Util.sameWorld(world, world4));
|
||||
assertFalse(Util.sameWorld(world2, world4));
|
||||
assertFalse(Util.sameWorld(world3, world4));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user