diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/BreedingListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/BreedingListener.java index 10726ee75..0bc9db45c 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/BreedingListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/BreedingListener.java @@ -33,8 +33,7 @@ public class BreedingListener extends FlagListener { Material.WHEAT_SEEDS, Material.SEAGRASS); - - @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true) public void onPlayerInteract(final PlayerInteractAtEntityEvent e) { if (e.getRightClicked() instanceof Animals) { ItemStack inHand = e.getPlayer().getInventory().getItemInMainHand(); @@ -42,9 +41,10 @@ public class BreedingListener extends FlagListener { inHand = e.getPlayer().getInventory().getItemInOffHand(); } if (inHand != null && BREEDING_ITEMS.contains(inHand.getType())) { - checkIsland(e, e.getRightClicked().getLocation(), Flags.BREEDING); + if (!checkIsland(e, e.getRightClicked().getLocation(), Flags.BREEDING)) { + ((Animals)e.getRightClicked()).setBreed(false); + } } } } - } diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/BreedingListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/BreedingListenerTest.java index e93b4eef1..b879101a6 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/BreedingListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/BreedingListenerTest.java @@ -239,6 +239,8 @@ public class BreedingListenerTest { bl.onPlayerInteract(e); assertFalse("Animal, breeding item in main hand, wrong world failed " + breedingMat, e.isCancelled()); } + // verify breeding was prevented + Mockito.verify(clickedEntity, Mockito.never()).setBreed(false); } /** @@ -256,6 +258,8 @@ public class BreedingListenerTest { bl.onPlayerInteract(e); assertTrue("Animal, breeding item in main hand failed " + breedingMat, e.isCancelled()); } + // verify breeding was prevented + Mockito.verify(clickedEntity, Mockito.times(5)).setBreed(false); } /** @@ -275,6 +279,8 @@ public class BreedingListenerTest { bl.onPlayerInteract(e); assertFalse("Animal, breeding item in off hand, wrong world failed " + breedingMat, e.isCancelled()); } + // verify breeding was not prevented + Mockito.verify(clickedEntity, Mockito.never()).setBreed(false); } /** @@ -293,5 +299,7 @@ public class BreedingListenerTest { bl.onPlayerInteract(e); assertTrue("Animal, breeding item in off hand failed " + breedingMat, e.isCancelled()); } + // verify breeding was prevented + Mockito.verify(clickedEntity, Mockito.times(5)).setBreed(false); } }