Skip to content

Commit b5ff354

Browse files
authored
Merge pull request #2513 from BentoBoxWorld/2512_random_errors
NPE fix for #2512
2 parents 37ba89a + a40e9ec commit b5ff354

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ public void onBreakHanging(final HangingBreakByEntityEvent e) {
8484
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
8585
public void onPlayerInteract(final PlayerInteractEvent e)
8686
{
87+
if (e.getClickedBlock() == null) {
88+
return;
89+
}
8790
Player p = e.getPlayer();
8891
Location l = e.getClickedBlock().getLocation();
8992
Material m = e.getClickedBlock().getType();
@@ -95,7 +98,7 @@ public void onPlayerInteract(final PlayerInteractEvent e)
9598
if (((CaveVinesPlant) e.getClickedBlock().getBlockData()).isBerries()) {
9699
this.checkIsland(e, p, l, Flags.HARVEST);
97100
}
98-
}
101+
}
99102
case SWEET_BERRY_BUSH -> this.checkIsland(e, p, l, Flags.HARVEST);
100103
case ROOTED_DIRT -> this.checkIsland(e, p, l, Flags.BREAK_BLOCKS);
101104
default -> { // Do nothing

src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -621,4 +621,15 @@ public void testLeftClickHopper() {
621621

622622
assertTrue(e.useInteractedBlock() == Result.ALLOW);
623623
}
624+
625+
/**
626+
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onPlayerInteract(PlayerInteractEvent)}
627+
*/
628+
@Test
629+
public void testNoClick() {
630+
PlayerInteractEvent e = mock(PlayerInteractEvent.class);
631+
when(e.getClickedBlock()).thenReturn(null);
632+
bbl.onPlayerInteract(e);
633+
verify(e).getClickedBlock();
634+
}
624635
}

0 commit comments

Comments
 (0)