Collect water wasn't overriding bucket usage for visitors

Fixes https://github.com/BentoBoxWorld/BentoBox/issues/1545
This commit is contained in:
tastybento 2020-10-12 15:45:38 -07:00
parent f09ea1ffef
commit 4a24364f81
2 changed files with 46 additions and 7 deletions

View File

@ -39,18 +39,21 @@ public class BucketListener extends FlagListener {
@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);
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onTropicalFishScooping(final PlayerInteractEntityEvent e) {

View File

@ -284,6 +284,42 @@ public class BucketListenerTest {
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)}.
*/