diff --git a/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java b/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java index 5056bee..1b29ace 100644 --- a/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java @@ -1061,7 +1061,7 @@ public class TryToComplete } }); - this.world.getNearbyEntities(boundingBox).forEach(entity -> { + user.getWorld().getNearbyEntities(boundingBox).forEach(entity -> { // Check if entity is inside challenge bounding box if (requiredMap.containsKey(entity.getType())) { diff --git a/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTest.java b/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTest.java index 582c06d..9f72b31 100644 --- a/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTest.java +++ b/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTest.java @@ -131,6 +131,7 @@ public class TryToCompleteTest { when(addon.getPlugin()).thenReturn(plugin); // World when(user.getWorld()).thenReturn(world); + when(world.getName()).thenReturn("world"); when(world.getEnvironment()).thenReturn(Environment.NORMAL); // Addons manager @@ -587,6 +588,34 @@ public class TryToCompleteTest { verify(user).sendMessage("challenges.messages.you-completed-challenge", "[value]", "name"); } + /** + * Test method for {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}. + */ + @Test + public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandPlayerInOtherEnvironment() { + challenge.setEnvironment(Collections.singleton(Environment.NETHER)); + World netherWorld = mock(World.class); + when(user.getWorld()).thenReturn(netherWorld); + when(netherWorld.getName()).thenReturn("world_nether"); + when(netherWorld.getEnvironment()).thenReturn(Environment.NETHER); + challenge.setChallengeType(ChallengeType.ISLAND); + IslandRequirements req = new IslandRequirements(); + Map requiredEntities = new HashMap<>(); + requiredEntities.put(EntityType.PUFFERFISH, 1); + req.setRequiredEntities(requiredEntities); + req.setSearchRadius(1); + challenge.setRequirements(req); + Entity ent = mock(Entity.class); + when(ent.getType()).thenReturn(EntityType.PUFFERFISH); + Location loc = mock(Location.class); + when(ent.getLocation()).thenReturn(loc); + List list = Collections.singletonList(ent); + when(world.getNearbyEntities(any(BoundingBox.class))).thenReturn(list); + when(netherWorld.getNearbyEntities(any(BoundingBox.class))).thenReturn(Collections.emptyList()); + assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); + verify(user).sendMessage("challenges.errors.you-still-need", "[amount]", "1", "[item]", "Pufferfish"); + } + /** * Test method for {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String, int)}. */