@@ -328,6 +328,69 @@ void testCheckGeneratorUnlockStatus() {
328328 verify (island , times (2 )).isSpawn ();
329329 }
330330
331+ /**
332+ * Seeds a deployed, permission-gated generator tier into the cache and returns the freshly created island data with
333+ * that tier already unlocked and active, simulating a generator that a previous owner had unlocked.
334+ */
335+ private GeneratorDataObject seedPermissionGeneratorAndData () {
336+ sgm .addWorld (world );
337+ when (island .getUniqueId ()).thenReturn ("island-133" );
338+ when (island .getWorld ()).thenReturn (world );
339+ when (island .isSpawn ()).thenReturn (false );
340+
341+ when (generatorTier .getUniqueId ()).thenReturn ("magiccobblegenerator_perm" );
342+ when (generatorTier .isDeployed ()).thenReturn (true );
343+ when (generatorTier .isDefaultGenerator ()).thenReturn (false );
344+ when (generatorTier .getGeneratorType ()).thenReturn (GeneratorType .COBBLESTONE );
345+ when (generatorTier .getRequiredMinIslandLevel ()).thenReturn (0L );
346+ when (generatorTier .getRequiredPermissions ())
347+ .thenReturn (java .util .Set .of ("magiccobblegenerator.gen.perm" ));
348+ sgm .loadGeneratorTier (generatorTier , true , null );
349+
350+ GeneratorDataObject data = sgm .getGeneratorData (island );
351+ assertNotNull (data );
352+ data .getUnlockedTiers ().add ("magiccobblegenerator_perm" );
353+ data .getActiveGeneratorList ().add ("magiccobblegenerator_perm" );
354+ return data ;
355+ }
356+
357+ @ Test
358+ void testCheckGeneratorUnlockStatusRevokesPermissionGeneratorWhenOwnerLacksPermission () {
359+ GeneratorDataObject data = seedPermissionGeneratorAndData ();
360+ // Owner is online but does not have the required permission (new owner scenario, #133).
361+ when (mockPlayer .isOnline ()).thenReturn (true );
362+
363+ sgm .checkGeneratorUnlockStatus (island , null , null );
364+
365+ assertFalse (data .getUnlockedTiers ().contains ("magiccobblegenerator_perm" ));
366+ assertFalse (data .getActiveGeneratorList ().contains ("magiccobblegenerator_perm" ));
367+ }
368+
369+ @ Test
370+ void testCheckGeneratorUnlockStatusKeepsPermissionGeneratorWhenOwnerHasPermission () {
371+ GeneratorDataObject data = seedPermissionGeneratorAndData ();
372+ when (mockPlayer .isOnline ()).thenReturn (true );
373+ // Owner still has the required permission.
374+ when (mockPlayer .hasPermission (anyString ())).thenReturn (true );
375+
376+ sgm .checkGeneratorUnlockStatus (island , null , null );
377+
378+ assertTrue (data .getUnlockedTiers ().contains ("magiccobblegenerator_perm" ));
379+ assertTrue (data .getActiveGeneratorList ().contains ("magiccobblegenerator_perm" ));
380+ }
381+
382+ @ Test
383+ void testCheckGeneratorUnlockStatusDoesNotRevokeWhenOwnerOffline () {
384+ GeneratorDataObject data = seedPermissionGeneratorAndData ();
385+ // Owner is offline, so permissions cannot be checked reliably and nothing is revoked.
386+ when (mockPlayer .isOnline ()).thenReturn (false );
387+
388+ sgm .checkGeneratorUnlockStatus (island , null , null );
389+
390+ assertTrue (data .getUnlockedTiers ().contains ("magiccobblegenerator_perm" ));
391+ assertTrue (data .getActiveGeneratorList ().contains ("magiccobblegenerator_perm" ));
392+ }
393+
331394 @ Test
332395 void testGetGeneratorDataIsland () {
333396 assertNotNull (sgm .getGeneratorData (island ));
0 commit comments