mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-16 23:35:24 +01:00
Fix unregistered players teleport to spawn with unforced registration
This commit is contained in:
parent
86cb2242e7
commit
c389105446
@ -13,6 +13,7 @@ import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -65,6 +66,12 @@ public class TeleportationService implements Reloadable {
|
||||
* @param player the player to process
|
||||
*/
|
||||
public void teleportOnJoin(final Player player) {
|
||||
if (!settings.getProperty(RegistrationSettings.FORCE)
|
||||
&& !dataSource.isAuthAvailable(player.getName())) {
|
||||
logger.debug("`{0}` is not registered, thus he will not get teleported on join.", player.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!settings.getProperty(RestrictionSettings.NO_TELEPORT)
|
||||
&& settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
|
||||
logger.debug("Teleport on join for player `{0}`", player.getName());
|
||||
@ -80,6 +87,12 @@ public class TeleportationService implements Reloadable {
|
||||
* @return the custom spawn location, null if the player should spawn at the original location
|
||||
*/
|
||||
public Location prepareOnJoinSpawnLocation(final Player player) {
|
||||
if (!settings.getProperty(RegistrationSettings.FORCE)
|
||||
&& !dataSource.isAuthAvailable(player.getName())) {
|
||||
logger.debug("`{0}` is not registered, thus he will not get teleported on join.", player.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!settings.getProperty(RestrictionSettings.NO_TELEPORT)
|
||||
&& settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
|
||||
final Location location = spawnLoader.getSpawnLocation(player);
|
||||
|
@ -7,6 +7,7 @@ import fr.xephi.authme.events.FirstSpawnTeleportEvent;
|
||||
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -71,6 +72,8 @@ public class TeleportationServiceTest {
|
||||
public void shouldNotTeleportPlayerOnJoin() {
|
||||
// given
|
||||
given(settings.getProperty(RestrictionSettings.NO_TELEPORT)).willReturn(true);
|
||||
given(settings.getProperty(RegistrationSettings.FORCE)).willReturn(true);
|
||||
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
@ -105,6 +108,8 @@ public class TeleportationServiceTest {
|
||||
public void shouldTeleportPlayerToSpawn() {
|
||||
// given
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
|
||||
given(settings.getProperty(RegistrationSettings.FORCE)).willReturn(true);
|
||||
|
||||
Player player = mock(Player.class);
|
||||
given(player.isOnline()).willReturn(true);
|
||||
Location spawn = mockLocation();
|
||||
@ -172,6 +177,8 @@ public class TeleportationServiceTest {
|
||||
Location spawn = mockLocation();
|
||||
given(spawnLoader.getSpawnLocation(player)).willReturn(spawn);
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
|
||||
given(settings.getProperty(RegistrationSettings.FORCE)).willReturn(true);
|
||||
|
||||
doAnswer(invocation -> {
|
||||
SpawnTeleportEvent event = (SpawnTeleportEvent) invocation.getArguments()[0];
|
||||
assertThat(event.getPlayer(), equalTo(player));
|
||||
@ -195,6 +202,8 @@ public class TeleportationServiceTest {
|
||||
Location spawn = mockLocation();
|
||||
given(spawnLoader.getSpawnLocation(player)).willReturn(spawn);
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
|
||||
given(settings.getProperty(RegistrationSettings.FORCE)).willReturn(true);
|
||||
|
||||
doAnswer(invocation -> {
|
||||
SpawnTeleportEvent event = (SpawnTeleportEvent) invocation.getArguments()[0];
|
||||
assertThat(event.getPlayer(), equalTo(player));
|
||||
|
Loading…
Reference in New Issue
Block a user