diff --git a/src/main/java/world/bentobox/chunkblock/listeners/BossBarListener.java b/src/main/java/world/bentobox/chunkblock/listeners/BossBarListener.java index 36fe748..9610f78 100644 --- a/src/main/java/world/bentobox/chunkblock/listeners/BossBarListener.java +++ b/src/main/java/world/bentobox/chunkblock/listeners/BossBarListener.java @@ -57,7 +57,7 @@ private boolean ready() { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBreakBlockEvent(MagicBlockEvent e) { - if (!ready()) { + if (!ready() || e.getPlayerUUID() == null) { return; } // Update boss bar diff --git a/src/test/java/world/bentobox/chunkblock/listeners/BossBarListenerTest.java b/src/test/java/world/bentobox/chunkblock/listeners/BossBarListenerTest.java index 4bd49b7..e520e8c 100644 --- a/src/test/java/world/bentobox/chunkblock/listeners/BossBarListenerTest.java +++ b/src/test/java/world/bentobox/chunkblock/listeners/BossBarListenerTest.java @@ -249,4 +249,16 @@ void testBukkitToAdventureParsesHex() { void testBukkitToAdventureNullIsEmpty() { assertEquals(Component.empty(), BossBarListener.bukkitToAdventure(null)); } + + /** + * NPC/minion breaks fire MagicBlockEvent with a null playerUUID; the listener must not throw. + */ + @Test + void testNullPlayerUUIDDoesNotThrow() { + when(island.isAllowed(addon.CHUNKBLOCK_BOSSBAR)).thenReturn(true); + when(island.isAllowed(addon.CHUNKBLOCK_ACTIONBAR)).thenReturn(true); + bbl.onBreakBlockEvent(new MagicBlockEvent(island, null, null, block, Material.STONE)); + verify(mockPlayer, never()).sendActionBar(any(Component.class)); + verify(bossBar, never()).addPlayer(any()); + } }