Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unregistered players teleport to spawn with unforced registration #1913

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/fr/xephi/authme/service/TeleportationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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;
Expand Down Expand Up @@ -65,6 +66,12 @@ public void reload() {
* @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());
Expand All @@ -80,6 +87,12 @@ public void teleportOnJoin(final Player player) {
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -71,6 +72,8 @@ public void setUpForcedWorlds() {
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
Expand Down Expand Up @@ -105,6 +108,8 @@ public void shouldTeleportPlayerToFirstSpawn() {
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();
Expand Down Expand Up @@ -172,6 +177,8 @@ public void shouldNotTeleportPlayerForRemovedLocationInEvent() {
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));
Expand All @@ -195,6 +202,8 @@ public void shouldNotTeleportPlayerForCanceledEvent() {
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));
Expand Down