mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-02-25 08:11:32 +01:00
Fix limbo player location on join
This commit is contained in:
parent
574fa9034d
commit
f45092bdd2
@ -3,6 +3,8 @@ package fr.xephi.authme.data.limbo;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.data.limbo.persistence.LimboPersistence;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -37,6 +39,9 @@ public class LimboService {
|
||||
@Inject
|
||||
private AuthGroupHandler authGroupHandler;
|
||||
|
||||
@Inject
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
LimboService() {
|
||||
}
|
||||
|
||||
@ -45,8 +50,9 @@ public class LimboService {
|
||||
*
|
||||
* @param player the player to process
|
||||
* @param isRegistered whether or not the player is registered
|
||||
* @param location the desired player location
|
||||
*/
|
||||
public void createLimboPlayer(Player player, boolean isRegistered) {
|
||||
public void createLimboPlayer(Player player, boolean isRegistered, Location location) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
|
||||
LimboPlayer limboFromDisk = persistence.getLimboPlayer(player);
|
||||
@ -61,7 +67,7 @@ public class LimboService {
|
||||
}
|
||||
|
||||
LimboPlayer limboPlayer = helper.merge(existingLimbo, limboFromDisk);
|
||||
limboPlayer = helper.merge(helper.createLimboPlayer(player, isRegistered), limboPlayer);
|
||||
limboPlayer = helper.merge(helper.createLimboPlayer(player, isRegistered, location), limboPlayer);
|
||||
|
||||
taskManager.registerMessageTask(player, limboPlayer, isRegistered);
|
||||
taskManager.registerTimeoutTask(player, limboPlayer);
|
||||
@ -72,6 +78,16 @@ public class LimboService {
|
||||
persistence.saveLimboPlayer(player, limboPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a LimboPlayer for the given player and revokes all "limbo data" from the player.
|
||||
*
|
||||
* @param player the player to process
|
||||
* @param isRegistered whether or not the player is registered
|
||||
*/
|
||||
public void createLimboPlayer(Player player, boolean isRegistered) {
|
||||
createLimboPlayer(player, isRegistered, spawnLoader.getPlayerLocationOrSpawn(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the limbo player for the given name, or null otherwise.
|
||||
*
|
||||
|
@ -34,10 +34,10 @@ class LimboServiceHelper {
|
||||
*
|
||||
* @param player the player to process
|
||||
* @param isRegistered whether the player is registered
|
||||
* @param location the player location
|
||||
* @return limbo player with the player's data
|
||||
*/
|
||||
LimboPlayer createLimboPlayer(Player player, boolean isRegistered) {
|
||||
Location location = spawnLoader.getPlayerLocationOrSpawn(player);
|
||||
LimboPlayer createLimboPlayer(Player player, boolean isRegistered, Location location) {
|
||||
// For safety reasons an unregistered player should not have OP status after registration
|
||||
boolean isOperator = isRegistered && player.isOp();
|
||||
boolean flyEnabled = player.getAllowFlight();
|
||||
|
@ -189,14 +189,31 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
// Note: the following event is called since MC1.9, in older versions we have to fallback on the PlayerJoinEvent
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerSpawn(PlayerSpawnLocationEvent event) {
|
||||
isPlayerSpawnLocationEventCalled = true;
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
management.performJoin(player, event.getSpawnLocation());
|
||||
|
||||
Location customSpawnLocation = teleportationService.prepareOnJoinSpawnLocation(player);
|
||||
if (customSpawnLocation != null) {
|
||||
event.setSpawnLocation(customSpawnLocation);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (!isPlayerSpawnLocationEventCalled) {
|
||||
teleportationService.teleportOnJoin(player);
|
||||
management.performJoin(player, player.getLocation());
|
||||
}
|
||||
|
||||
teleportationService.teleportNewPlayerToFirstSpawn(player);
|
||||
management.performJoin(player);
|
||||
}
|
||||
|
||||
private void runOnJoinChecks(String name, String ip) throws FailedVerificationException {
|
||||
@ -267,25 +284,6 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
// Note: the following event is called since MC1.9, in older versions we have to fallback on the PlayerJoinEvent
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerSpawn(PlayerSpawnLocationEvent event) {
|
||||
isPlayerSpawnLocationEventCalled = true;
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final String name = player.getName();
|
||||
|
||||
if (validationService.isUnrestricted(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location customSpawnLocation = teleportationService.prepareOnJoinSpawnLocation(player);
|
||||
if (customSpawnLocation != null) {
|
||||
event.setSpawnLocation(customSpawnLocation);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
@ -12,6 +12,7 @@ import fr.xephi.authme.process.register.executors.RegistrationMethod;
|
||||
import fr.xephi.authme.process.register.executors.RegistrationParameters;
|
||||
import fr.xephi.authme.process.unregister.AsynchronousUnregister;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -73,8 +74,8 @@ public class Management {
|
||||
runTask(() -> asynchronousUnregister.adminUnregister(initiator, name, player));
|
||||
}
|
||||
|
||||
public void performJoin(Player player) {
|
||||
runTask(() -> asynchronousJoin.processJoin(player));
|
||||
public void performJoin(Player player, Location location) {
|
||||
runTask(() -> asynchronousJoin.processJoin(player, location));
|
||||
}
|
||||
|
||||
public void performQuit(Player player) {
|
||||
|
@ -22,6 +22,7 @@ import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.util.PlayerUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
@ -77,8 +78,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
* Processes the given player that has just joined.
|
||||
*
|
||||
* @param player the player to process
|
||||
* @param location the desired player location, null if you want to use the current one
|
||||
*/
|
||||
public void processJoin(final Player player) {
|
||||
public void processJoin(final Player player, Location location) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
final String ip = PlayerUtils.getPlayerIp(player);
|
||||
|
||||
@ -131,7 +133,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
return;
|
||||
}
|
||||
|
||||
processJoinSync(player, isAuthAvailable);
|
||||
processJoinSync(player, isAuthAvailable, location);
|
||||
}
|
||||
|
||||
private void handlePlayerWithUnmetNameRestriction(Player player, String ip) {
|
||||
@ -149,12 +151,13 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
*
|
||||
* @param player the player to process
|
||||
* @param isAuthAvailable true if the player is registered, false otherwise
|
||||
* @param location the desired player location, null if you want to use the current one
|
||||
*/
|
||||
private void processJoinSync(Player player, boolean isAuthAvailable) {
|
||||
private void processJoinSync(Player player, boolean isAuthAvailable, Location location) {
|
||||
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
|
||||
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> {
|
||||
limboService.createLimboPlayer(player, isAuthAvailable);
|
||||
limboService.createLimboPlayer(player, isAuthAvailable, location);
|
||||
|
||||
player.setNoDamageTicks(registrationTimeout);
|
||||
if (pluginHookService.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) {
|
||||
|
@ -496,7 +496,7 @@ public class PlayerListenerTest {
|
||||
|
||||
// then
|
||||
verify(teleportationService).teleportNewPlayerToFirstSpawn(player);
|
||||
verify(management).performJoin(player);
|
||||
verify(management).performJoin(player, player.getLocation());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user