Skip to content

Commit

Permalink
Collect water wasn't overriding bucket usage for visitors
Browse files Browse the repository at this point in the history
Fixes #1545
  • Loading branch information
tastybento committed Oct 12, 2020
1 parent f09ea1f commit 4a24364
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}.
Expand Down

0 comments on commit 4a24364

Please sign in to comment.