|
26 | 26 | import org.bukkit.Location; |
27 | 27 | import org.bukkit.World; |
28 | 28 | import org.bukkit.World.Environment; |
| 29 | +import org.bukkit.entity.ExperienceOrb; |
29 | 30 | import org.bukkit.entity.LivingEntity; |
| 31 | +import org.bukkit.entity.Zombie; |
30 | 32 | import org.bukkit.event.entity.EntityDamageEvent; |
31 | 33 | import org.bukkit.event.entity.EntityDamageEvent.DamageCause; |
| 34 | +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; |
| 35 | +import org.bukkit.event.entity.EntityTargetLivingEntityEvent; |
32 | 36 | import org.bukkit.event.inventory.ClickType; |
33 | 37 | import org.bukkit.inventory.Inventory; |
34 | 38 | import org.bukkit.inventory.ItemStack; |
@@ -291,4 +295,59 @@ void testOnVisitorGetDamageVoidPlayerHasIsland() { |
291 | 295 | verify(im).homeTeleportAsync(any(), eq(mockPlayer)); |
292 | 296 | verify(pim).callEvent(any(InvincibleVistorFlagDamageRemovalEvent.class)); |
293 | 297 | } |
| 298 | + |
| 299 | + /** |
| 300 | + * Test that onVisitorTargeting cancels mob targeting of a visitor when ENTITY_ATTACK is in IV settings. |
| 301 | + */ |
| 302 | + @Test |
| 303 | + void testOnVisitorTargetingCancelsMobTargeting() { |
| 304 | + ivSettings.add(DamageCause.ENTITY_ATTACK.name()); |
| 305 | + Zombie zombie = mock(Zombie.class); |
| 306 | + when(zombie.getWorld()).thenReturn(world); |
| 307 | + EntityTargetLivingEntityEvent e = new EntityTargetLivingEntityEvent(zombie, mockPlayer, TargetReason.CLOSEST_PLAYER); |
| 308 | + listener.onVisitorTargeting(e); |
| 309 | + assertTrue(e.isCancelled()); |
| 310 | + } |
| 311 | + |
| 312 | + /** |
| 313 | + * Test that onVisitorTargeting does NOT cancel experience orb targeting of a visitor. |
| 314 | + * XP orbs should still be able to track visitors for pickup, regardless of IV settings. |
| 315 | + */ |
| 316 | + @Test |
| 317 | + void testOnVisitorTargetingDoesNotCancelExperienceOrbTargeting() { |
| 318 | + ivSettings.add(DamageCause.ENTITY_ATTACK.name()); |
| 319 | + ExperienceOrb orb = mock(ExperienceOrb.class); |
| 320 | + when(orb.getWorld()).thenReturn(world); |
| 321 | + EntityTargetLivingEntityEvent e = new EntityTargetLivingEntityEvent(orb, mockPlayer, TargetReason.CLOSEST_PLAYER); |
| 322 | + listener.onVisitorTargeting(e); |
| 323 | + assertFalse(e.isCancelled()); |
| 324 | + } |
| 325 | + |
| 326 | + /** |
| 327 | + * Test that onVisitorTargeting does not cancel when entity_attack is not in IV settings. |
| 328 | + */ |
| 329 | + @Test |
| 330 | + void testOnVisitorTargetingNotInIvSettings() { |
| 331 | + // ENTITY_ATTACK is not in ivSettings by default |
| 332 | + Zombie zombie = mock(Zombie.class); |
| 333 | + when(zombie.getWorld()).thenReturn(world); |
| 334 | + EntityTargetLivingEntityEvent e = new EntityTargetLivingEntityEvent(zombie, mockPlayer, TargetReason.CLOSEST_PLAYER); |
| 335 | + listener.onVisitorTargeting(e); |
| 336 | + assertFalse(e.isCancelled()); |
| 337 | + } |
| 338 | + |
| 339 | + /** |
| 340 | + * Test that onVisitorTargeting does not cancel when user is on their own island. |
| 341 | + */ |
| 342 | + @Test |
| 343 | + void testOnVisitorTargetingNotVisitor() { |
| 344 | + ivSettings.add(DamageCause.ENTITY_ATTACK.name()); |
| 345 | + when(im.userIsOnIsland(any(), any())).thenReturn(true); |
| 346 | + Zombie zombie = mock(Zombie.class); |
| 347 | + when(zombie.getWorld()).thenReturn(world); |
| 348 | + EntityTargetLivingEntityEvent e = new EntityTargetLivingEntityEvent(zombie, mockPlayer, TargetReason.CLOSEST_PLAYER); |
| 349 | + listener.onVisitorTargeting(e); |
| 350 | + assertFalse(e.isCancelled()); |
| 351 | + } |
| 352 | + |
294 | 353 | } |
0 commit comments