Fixes bug with checking entities in nether and end (#219)

https://github.com/BentoBoxWorld/Challenges/issues/218

Adds test case to check for compliance.
This commit is contained in:
tastybento 2020-03-09 02:39:59 -07:00 committed by GitHub
parent db971d81ab
commit 6368585a57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -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()))
{

View File

@ -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<EntityType, Integer> 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<Entity> 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)}.
*/