From 36b82b89d742a74e0cd7e07ee14e188a1a29b0f9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 5 May 2026 15:09:07 +0000 Subject: [PATCH 1/2] Initial plan From 66be008c5f0498a83b8d22b5d04710ae3458b3d1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 5 May 2026 15:26:27 +0000 Subject: [PATCH 2/2] Add regression test for island creation home location bug fix Agent-Logs-Url: https://github.com/BentoBoxWorld/BentoBox/sessions/4074072d-5ba3-4cdc-aaae-6bc4eabd80c2 Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com> --- .../managers/island/NewIslandTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/java/world/bentobox/bentobox/managers/island/NewIslandTest.java b/src/test/java/world/bentobox/bentobox/managers/island/NewIslandTest.java index cb2e5fabe..ea0f80c18 100644 --- a/src/test/java/world/bentobox/bentobox/managers/island/NewIslandTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/island/NewIslandTest.java @@ -5,6 +5,8 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -17,6 +19,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World.Environment; import org.bukkit.block.Block; import org.bukkit.scheduler.BukkitScheduler; import org.eclipse.jdt.annotation.NonNull; @@ -313,4 +316,36 @@ void testBuilderHasIslandFail() throws Exception { // Removed testBuilderHasIslandFailnoReserve — test was unfinished and expected nonexistent logError call + /** + * Regression test for: Island creation changes the home location of previous island. + *

+ * When an island has a spawn point (set during blueprint paste), the home location must + * be set directly on that specific island object using {@code setHomeLocation(island, spawn, "")}, + * NOT via the user-UUID lookup {@code setHomeLocation(user, spawn)} which resolves to the + * current primary island. If a second island is created concurrently and becomes + * primary before the first island's post-creation task runs, the UUID-based lookup would + * incorrectly set the home on the second island instead. + */ + @Test + void testBuilderWithSpawnPointSetsHomeOnIslandDirectly() throws Exception { + // Make the scheduler execute the runnable immediately so postCreationTask runs inline + doAnswer(inv -> { + ((Runnable) inv.getArgument(1)).run(); + return null; + }).when(scheduler).runTask(any(BentoBox.class), any(Runnable.class)); + + // Mock a spawn point being set on the island (e.g., by blueprint paste) + Location spawnLoc = mock(Location.class); + when(island.getSpawnPoint(Environment.NORMAL)).thenReturn(spawnLoc); + + NewIsland.builder().addon(addon).name(NAME).player(user).noPaste().reason(Reason.CREATE).build(); + + // The home must be set directly on the island object (not via user UUID lookup). + // Using the island-based overload guarantees the correct island is targeted even when + // a concurrent creation has changed the player's primary island. + verify(im).setHomeLocation(island, spawnLoc, ""); + // The user-based overload must never be called during island creation + verify(im, never()).setHomeLocation(eq(user), any()); + } + } \ No newline at end of file