Fix unregistered players teleport to spawn with unforced registration

This commit is contained in:
Kongolan 2019-09-17 21:24:17 +02:00
parent 86cb2242e7
commit c389105446
2 changed files with 22 additions and 0 deletions

View File

@ -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);

View File

@ -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));