Merge pull request #2501 from BentoBoxWorld/2500_Admin_purge_command_error

Prevent null island worlds from blocking purging. #2500
This commit is contained in:
tastybento 2024-09-13 08:00:27 -07:00 committed by GitHub
commit ab8f3a7d70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -133,6 +133,7 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
// Process islands in one pass, logging and adding to the set if applicable
getPlugin().getIslands().getIslands().stream()
.filter(i -> !i.isSpawn()).filter(i -> !i.getPurgeProtected())
.filter(i -> i.getWorld() != null) // to handle currently unloaded world islands
.filter(i -> i.getWorld().equals(this.getWorld())).filter(Island::isOwned).filter(
i -> i.getMemberSet().stream()
.allMatch(member -> (currentTimeMillis

View File

@ -12,6 +12,7 @@ import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
@ -364,4 +365,15 @@ public class AdminPurgeCommandTest {
verify(user, Mockito.times(1)).sendMessage(any());
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.admin.purge.AdminPurgeCommand#getOldIslands(int)}
*/
@Test
public void testGetOldIslands() {
assertTrue(apc.getOldIslands(10).isEmpty());
Island island2 = mock(Island.class);
when(im.getIslands()).thenReturn(Set.of(island, island2));
assertTrue(apc.getOldIslands(10).isEmpty());
}
}