mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-08 09:27:38 +01:00
Handle null itemInHand for BlockPlaceEvent
Officially, null is invalid as an in-hand item. It should be AIR. Fixes https://github.com/BentoBoxWorld/BentoBox/issues/1172
This commit is contained in:
parent
559578002b
commit
898e310e4f
@ -27,6 +27,7 @@ public class PlaceBlocksListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onBlockPlace(final BlockPlaceEvent e) {
|
||||
if (e.getBlock().getType().equals(Material.FIRE)
|
||||
|| e.getItemInHand() == null // Note that this should never happen officially, but it's possible for other plugins to cause it to happen
|
||||
|| e.getItemInHand().getType().equals(Material.WRITABLE_BOOK)
|
||||
|| e.getItemInHand().getType().equals(Material.WRITTEN_BOOK)) {
|
||||
// Books can only be placed on lecterns and as such are protected by the LECTERN flag.
|
||||
|
@ -224,6 +224,22 @@ public class PlaceBlocksListenerTest {
|
||||
pbl.onBlockPlace(e);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PlaceBlocksListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
|
||||
*/
|
||||
@Test
|
||||
public void testOnBlockPlaceNullItemInHand() {
|
||||
Block placedBlock = mock(Block.class);
|
||||
when(placedBlock.getType()).thenReturn(Material.STONE);
|
||||
when(placedBlock.getLocation()).thenReturn(location);
|
||||
BlockState replacedBlockState = mock(BlockState.class);
|
||||
Block placedAgainst = mock(Block.class);
|
||||
EquipmentSlot hand = EquipmentSlot.HAND;
|
||||
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, null, player, true, hand);
|
||||
pbl.onBlockPlace(e);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PlaceBlocksListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
|
||||
|
Loading…
Reference in New Issue
Block a user