From 8ba3f034f7079f46eb357a734df16cb491221477 Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 13 Sep 2024 07:53:22 -0700 Subject: [PATCH 1/2] Prevent null island worlds from blocking purging. #2500 --- .../bentobox/api/commands/admin/purge/AdminPurgeCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommand.java index a5c6fe6cc..1e90aa431 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommand.java @@ -133,6 +133,7 @@ Set getOldIslands(int days) { // 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 From 8240484d4fe4102b632c7e39bb48371434cc294b Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 13 Sep 2024 08:00:17 -0700 Subject: [PATCH 2/2] Added test case --- .../commands/admin/purge/AdminPurgeCommandTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommandTest.java index c75191fb0..cd1da2ae1 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommandTest.java @@ -12,6 +12,7 @@ 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 void testSetUser() { 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()); + } + }