From ab456550dbef2c0bb4f577d01ac451bf46fff164 Mon Sep 17 00:00:00 2001 From: Rishabh Venu Date: Sat, 10 Oct 2026 05:30:10 -0400 Subject: [PATCH] fix(folia): use the teleport adapter in /authme spawn and firstspawn SpawnCommand and FirstSpawnCommand called Player#teleport directly. Folia rejects that with "Must use teleportAsync while in region threading", so both commands failed with an unexpected error there. Go through TeleportAdapter#teleportPlayer as the other teleports do. The Paper and Folia adapters use teleportAsync, the Spigot ones keep the synchronous teleport. Fixes #3161 --- .../command/executable/authme/FirstSpawnCommand.java | 6 +++++- .../command/executable/authme/SpawnCommand.java | 6 +++++- .../executable/authme/FirstSpawnCommandTest.java | 11 +++++++---- .../command/executable/authme/SpawnCommandTest.java | 11 +++++++---- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/authme-core/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java b/authme-core/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java index a93749c7c0..fd44430e4f 100644 --- a/authme-core/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java +++ b/authme-core/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java @@ -2,6 +2,7 @@ import fr.xephi.authme.command.PlayerCommand; import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.platform.TeleportAdapter; import fr.xephi.authme.settings.SpawnLoader; import org.bukkit.entity.Player; @@ -16,12 +17,15 @@ public class FirstSpawnCommand extends PlayerCommand { @Inject private SpawnLoader spawnLoader; + @Inject + private TeleportAdapter teleportAdapter; + @Override public void runCommand(Player player, List arguments) { if (spawnLoader.getFirstSpawn() == null) { messages.send(player, MessageKey.FIRST_SPAWN_NOT_DEFINED); } else { - player.teleport(spawnLoader.getFirstSpawn()); + teleportAdapter.teleportPlayer(player, spawnLoader.getFirstSpawn()); } } } diff --git a/authme-core/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java b/authme-core/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java index 75f7371a86..2a1aa22f6d 100644 --- a/authme-core/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java +++ b/authme-core/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java @@ -2,6 +2,7 @@ import fr.xephi.authme.command.PlayerCommand; import fr.xephi.authme.message.MessageKey; +import fr.xephi.authme.platform.TeleportAdapter; import fr.xephi.authme.settings.SpawnLoader; import org.bukkit.entity.Player; @@ -13,12 +14,15 @@ public class SpawnCommand extends PlayerCommand { @Inject private SpawnLoader spawnLoader; + @Inject + private TeleportAdapter teleportAdapter; + @Override public void runCommand(Player player, List arguments) { if (spawnLoader.getSpawn() == null) { messages.send(player, MessageKey.SPAWN_NOT_DEFINED); } else { - player.teleport(spawnLoader.getSpawn()); + teleportAdapter.teleportPlayer(player, spawnLoader.getSpawn()); } } } diff --git a/authme-core/src/test/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommandTest.java b/authme-core/src/test/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommandTest.java index 989198bf8d..211b487052 100644 --- a/authme-core/src/test/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommandTest.java +++ b/authme-core/src/test/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommandTest.java @@ -2,6 +2,7 @@ import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.message.Messages; +import fr.xephi.authme.platform.TeleportAdapter; import fr.xephi.authme.settings.SpawnLoader; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -13,12 +14,11 @@ import java.util.Collections; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; /** * Test for {@link FirstSpawnCommand}. @@ -35,6 +35,9 @@ class FirstSpawnCommandTest { @Mock private Messages messages; + @Mock + private TeleportAdapter teleportAdapter; + @Test void shouldTeleportToFirstSpawn() { // given @@ -46,7 +49,7 @@ void shouldTeleportToFirstSpawn() { command.executeCommand(player, Collections.emptyList()); // then - verify(player).teleport(firstSpawn); + verify(teleportAdapter).teleportPlayer(player, firstSpawn); verify(spawnLoader, atLeastOnce()).getFirstSpawn(); } @@ -61,6 +64,6 @@ void shouldHandleMissingFirstSpawn() { // then verify(messages).send(player, MessageKey.FIRST_SPAWN_NOT_DEFINED); - verify(player, never()).teleport(any(Location.class)); + verifyNoInteractions(teleportAdapter); } } diff --git a/authme-core/src/test/java/fr/xephi/authme/command/executable/authme/SpawnCommandTest.java b/authme-core/src/test/java/fr/xephi/authme/command/executable/authme/SpawnCommandTest.java index de7eeb3e0c..665a62f967 100644 --- a/authme-core/src/test/java/fr/xephi/authme/command/executable/authme/SpawnCommandTest.java +++ b/authme-core/src/test/java/fr/xephi/authme/command/executable/authme/SpawnCommandTest.java @@ -2,6 +2,7 @@ import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.message.Messages; +import fr.xephi.authme.platform.TeleportAdapter; import fr.xephi.authme.settings.SpawnLoader; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -13,12 +14,11 @@ import java.util.Collections; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; /** * Test for {@link SpawnCommand}. @@ -35,6 +35,9 @@ class SpawnCommandTest { @Mock private Messages messages; + @Mock + private TeleportAdapter teleportAdapter; + @Test void shouldTeleportToSpawn() { // given @@ -46,7 +49,7 @@ void shouldTeleportToSpawn() { command.executeCommand(player, Collections.emptyList()); // then - verify(player).teleport(spawn); + verify(teleportAdapter).teleportPlayer(player, spawn); verify(spawnLoader, atLeastOnce()).getSpawn(); } @@ -61,6 +64,6 @@ void shouldHandleMissingSpawn() { // then verify(messages).send(player, MessageKey.SPAWN_NOT_DEFINED); - verify(player, never()).teleport(any(Location.class)); + verifyNoInteractions(teleportAdapter); } }