Fixed bug where animals could be bred or fed to grow up.

https://github.com/BentoBoxWorld/bentobox/issues/366
This commit is contained in:
tastybento 2018-12-09 14:09:53 -08:00
parent ff7a43feea
commit 3e07554d3b
2 changed files with 12 additions and 4 deletions

View File

@ -33,8 +33,7 @@ public class BreedingListener extends FlagListener {
Material.WHEAT_SEEDS, Material.WHEAT_SEEDS,
Material.SEAGRASS); Material.SEAGRASS);
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractAtEntityEvent e) { public void onPlayerInteract(final PlayerInteractAtEntityEvent e) {
if (e.getRightClicked() instanceof Animals) { if (e.getRightClicked() instanceof Animals) {
ItemStack inHand = e.getPlayer().getInventory().getItemInMainHand(); ItemStack inHand = e.getPlayer().getInventory().getItemInMainHand();
@ -42,9 +41,10 @@ public class BreedingListener extends FlagListener {
inHand = e.getPlayer().getInventory().getItemInOffHand(); inHand = e.getPlayer().getInventory().getItemInOffHand();
} }
if (inHand != null && BREEDING_ITEMS.contains(inHand.getType())) { 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);
}
} }
} }
} }
} }

View File

@ -239,6 +239,8 @@ public class BreedingListenerTest {
bl.onPlayerInteract(e); bl.onPlayerInteract(e);
assertFalse("Animal, breeding item in main hand, wrong world failed " + breedingMat, e.isCancelled()); 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); bl.onPlayerInteract(e);
assertTrue("Animal, breeding item in main hand failed " + breedingMat, e.isCancelled()); 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); bl.onPlayerInteract(e);
assertFalse("Animal, breeding item in off hand, wrong world failed " + breedingMat, e.isCancelled()); 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); bl.onPlayerInteract(e);
assertTrue("Animal, breeding item in off hand failed " + breedingMat, e.isCancelled()); assertTrue("Animal, breeding item in off hand failed " + breedingMat, e.isCancelled());
} }
// verify breeding was prevented
Mockito.verify(clickedEntity, Mockito.times(5)).setBreed(false);
} }
} }