mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-24 19:45:14 +01:00
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:
parent
db971d81ab
commit
6368585a57
@ -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()))
|
||||
{
|
||||
|
@ -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)}.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user