Merge pull request #2513 from BentoBoxWorld/2512_random_errors

NPE fix for #2512
This commit is contained in:
tastybento 2024-09-21 17:22:17 -07:00 committed by GitHub
commit b5ff3544e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -84,6 +84,9 @@ public class BreakBlocksListener extends FlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerInteract(final PlayerInteractEvent e)
{
if (e.getClickedBlock() == null) {
return;
}
Player p = e.getPlayer();
Location l = e.getClickedBlock().getLocation();
Material m = e.getClickedBlock().getType();
@ -95,7 +98,7 @@ public class BreakBlocksListener extends FlagListener {
if (((CaveVinesPlant) e.getClickedBlock().getBlockData()).isBerries()) {
this.checkIsland(e, p, l, Flags.HARVEST);
}
}
}
case SWEET_BERRY_BUSH -> this.checkIsland(e, p, l, Flags.HARVEST);
case ROOTED_DIRT -> this.checkIsland(e, p, l, Flags.BREAK_BLOCKS);
default -> { // Do nothing

View File

@ -621,4 +621,15 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
assertTrue(e.useInteractedBlock() == Result.ALLOW);
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onPlayerInteract(PlayerInteractEvent)}
*/
@Test
public void testNoClick() {
PlayerInteractEvent e = mock(PlayerInteractEvent.class);
when(e.getClickedBlock()).thenReturn(null);
bbl.onPlayerInteract(e);
verify(e).getClickedBlock();
}
}