diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BucketListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BucketListener.java index a4822f399..3dd360185 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BucketListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BucketListener.java @@ -39,17 +39,20 @@ public void onBucketEmpty(final PlayerBucketEmptyEvent e) { @EventHandler(priority = EventPriority.LOW) public void onBucketFill(final PlayerBucketFillEvent e) { // Check filling of various liquids - if (e.getItemStack().getType().equals(Material.LAVA_BUCKET) && (!checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA))) { + switch (e.getItemStack().getType()) { + case LAVA_BUCKET: + checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA); return; - } - if (e.getItemStack().getType().equals(Material.WATER_BUCKET) && (!checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_WATER))) { + case WATER_BUCKET: + checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_WATER); return; - } - if (e.getItemStack().getType().equals(Material.MILK_BUCKET) && (!checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.MILKING))) { + case MILK_BUCKET: + checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.MILKING); return; + default: + // Check general bucket use + checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.BUCKET); } - // Check general bucket use - checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.BUCKET); } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java index 142d257d7..c5636727b 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java @@ -283,6 +283,42 @@ public void testOnBucketFillNotAllowed() { verify(notifier, times(4)).notify(any(), eq("protection.protected")); } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BucketListener#onBucketFill(org.bukkit.event.player.PlayerBucketFillEvent)}. + */ + @Test + public void testOnBucketFillMixedAllowed() { + when(island.isAllowed(any(), eq(Flags.BUCKET))).thenReturn(false); + when(island.isAllowed(any(), eq(Flags.COLLECT_WATER))).thenReturn(true); + when(island.isAllowed(any(), eq(Flags.COLLECT_LAVA))).thenReturn(true); + when(island.isAllowed(any(), eq(Flags.MILKING))).thenReturn(true); + Block block = mock(Block.class); + when(block.getLocation()).thenReturn(location); + when(block.getRelative(any())).thenReturn(block); + ItemStack item = mock(ItemStack.class); + when(item.getType()).thenReturn(Material.WATER_BUCKET); + PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + l.onBucketFill(e); + assertFalse(e.isCancelled()); + + when(item.getType()).thenReturn(Material.BUCKET); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + l.onBucketFill(e); + assertTrue(e.isCancelled()); + + when(item.getType()).thenReturn(Material.LAVA_BUCKET); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + l.onBucketFill(e); + assertFalse(e.isCancelled()); + + when(item.getType()).thenReturn(Material.MILK_BUCKET); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + l.onBucketFill(e); + assertFalse(e.isCancelled()); + + verify(notifier).notify(any(), eq("protection.protected")); + } /** * Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BucketListener#onTropicalFishScooping(org.bukkit.event.player.PlayerInteractEntityEvent)}.