@@ -91,6 +91,9 @@ class BlockLimitsListenerTest {
9191 @ Mock
9292 private Limits addon ;
9393
94+ @ Mock
95+ private world .bentobox .limits .Settings limitsSettings ;
96+
9497 @ Mock
9598 private World world ;
9699
@@ -135,6 +138,8 @@ void setUp() throws Exception {
135138 doAnswer (invocation -> null ).when (addon ).log (anyString ());
136139 doAnswer (invocation -> null ).when (addon ).logError (anyString ());
137140 when (addon .isCoveredGameMode (anyString ())).thenReturn (true );
141+ when (addon .getSettings ()).thenReturn (limitsSettings );
142+ when (limitsSettings .isShowLimitMessages ()).thenReturn (true );
138143 when (addon .inGameModeWorld (any (World .class ))).thenReturn (false );
139144 // Override to true for our test world so event handlers don't bail early
140145 when (addon .inGameModeWorld (world )).thenReturn (true );
@@ -403,6 +408,48 @@ void testBlockPlaceAtLimitCancelsEvent() {
403408 assertTrue (event .isCancelled ());
404409 }
405410
411+ @ Test
412+ void testBlockPlaceAtLimitNotifiesWhenMessagesEnabled () {
413+ IslandBlockCount ibc = new IslandBlockCount ("test-island-id" , "BSkyBlock" );
414+ for (int i = 0 ; i < 10 ; i ++) {
415+ ibc .add (Environment .NORMAL , Material .HOPPER .getKey ());
416+ }
417+ listener .setIsland ("test-island-id" , ibc );
418+ Notifier notifier = mock (Notifier .class );
419+ when (plugin .getNotifier ()).thenReturn (notifier );
420+
421+ Block block = mockBlock (Material .HOPPER , blockLocation );
422+ BlockState replacedState = mock (BlockState .class );
423+ BlockPlaceEvent event = new BlockPlaceEvent (block , replacedState , block , new ItemStack (Material .HOPPER ), player , true , EquipmentSlot .HAND );
424+
425+ listener .onBlock (event );
426+
427+ assertTrue (event .isCancelled ());
428+ verify (notifier ).notify (any (), anyString ());
429+ }
430+
431+ @ Test
432+ void testBlockPlaceAtLimitSilentWhenMessagesDisabled () {
433+ when (limitsSettings .isShowLimitMessages ()).thenReturn (false );
434+ IslandBlockCount ibc = new IslandBlockCount ("test-island-id" , "BSkyBlock" );
435+ for (int i = 0 ; i < 10 ; i ++) {
436+ ibc .add (Environment .NORMAL , Material .HOPPER .getKey ());
437+ }
438+ listener .setIsland ("test-island-id" , ibc );
439+ Notifier notifier = mock (Notifier .class );
440+ when (plugin .getNotifier ()).thenReturn (notifier );
441+
442+ Block block = mockBlock (Material .HOPPER , blockLocation );
443+ BlockState replacedState = mock (BlockState .class );
444+ BlockPlaceEvent event = new BlockPlaceEvent (block , replacedState , block , new ItemStack (Material .HOPPER ), player , true , EquipmentSlot .HAND );
445+
446+ listener .onBlock (event );
447+
448+ // Still enforced, just silent
449+ assertTrue (event .isCancelled ());
450+ verify (notifier , never ()).notify (any (), anyString ());
451+ }
452+
406453 @ Test
407454 void testBlockPlaceUnlimitedMaterialAllowed () {
408455 Block block = mockBlock (Material .DIRT , blockLocation );
0 commit comments