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.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.limbo.persistence.LimboPersistence;
|
import fr.xephi.authme.data.limbo.persistence.LimboPersistence;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -37,6 +39,9 @@ public class LimboService {
|
|||||||
@Inject
|
@Inject
|
||||||
private AuthGroupHandler authGroupHandler;
|
private AuthGroupHandler authGroupHandler;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private SpawnLoader spawnLoader;
|
||||||
|
|
||||||
LimboService() {
|
LimboService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +50,9 @@ public class LimboService {
|
|||||||
*
|
*
|
||||||
* @param player the player to process
|
* @param player the player to process
|
||||||
* @param isRegistered whether or not the player is registered
|
* @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();
|
final String name = player.getName().toLowerCase();
|
||||||
|
|
||||||
LimboPlayer limboFromDisk = persistence.getLimboPlayer(player);
|
LimboPlayer limboFromDisk = persistence.getLimboPlayer(player);
|
||||||
@ -61,7 +67,7 @@ public class LimboService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LimboPlayer limboPlayer = helper.merge(existingLimbo, limboFromDisk);
|
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.registerMessageTask(player, limboPlayer, isRegistered);
|
||||||
taskManager.registerTimeoutTask(player, limboPlayer);
|
taskManager.registerTimeoutTask(player, limboPlayer);
|
||||||
@ -72,6 +78,16 @@ public class LimboService {
|
|||||||
persistence.saveLimboPlayer(player, limboPlayer);
|
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.
|
* Returns the limbo player for the given name, or null otherwise.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -34,10 +34,10 @@ class LimboServiceHelper {
|
|||||||
*
|
*
|
||||||
* @param player the player to process
|
* @param player the player to process
|
||||||
* @param isRegistered whether the player is registered
|
* @param isRegistered whether the player is registered
|
||||||
|
* @param location the player location
|
||||||
* @return limbo player with the player's data
|
* @return limbo player with the player's data
|
||||||
*/
|
*/
|
||||||
LimboPlayer createLimboPlayer(Player player, boolean isRegistered) {
|
LimboPlayer createLimboPlayer(Player player, boolean isRegistered, Location location) {
|
||||||
Location location = spawnLoader.getPlayerLocationOrSpawn(player);
|
|
||||||
// For safety reasons an unregistered player should not have OP status after registration
|
// For safety reasons an unregistered player should not have OP status after registration
|
||||||
boolean isOperator = isRegistered && player.isOp();
|
boolean isOperator = isRegistered && player.isOp();
|
||||||
boolean flyEnabled = player.getAllowFlight();
|
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)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
if (!isPlayerSpawnLocationEventCalled) {
|
if (!isPlayerSpawnLocationEventCalled) {
|
||||||
teleportationService.teleportOnJoin(player);
|
teleportationService.teleportOnJoin(player);
|
||||||
|
management.performJoin(player, player.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
teleportationService.teleportNewPlayerToFirstSpawn(player);
|
teleportationService.teleportNewPlayerToFirstSpawn(player);
|
||||||
management.performJoin(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runOnJoinChecks(String name, String ip) throws FailedVerificationException {
|
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)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
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.register.executors.RegistrationParameters;
|
||||||
import fr.xephi.authme.process.unregister.AsynchronousUnregister;
|
import fr.xephi.authme.process.unregister.AsynchronousUnregister;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -73,8 +74,8 @@ public class Management {
|
|||||||
runTask(() -> asynchronousUnregister.adminUnregister(initiator, name, player));
|
runTask(() -> asynchronousUnregister.adminUnregister(initiator, name, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performJoin(Player player) {
|
public void performJoin(Player player, Location location) {
|
||||||
runTask(() -> asynchronousJoin.processJoin(player));
|
runTask(() -> asynchronousJoin.processJoin(player, location));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performQuit(Player player) {
|
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.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.PlayerUtils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
@ -77,8 +78,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
* Processes the given player that has just joined.
|
* Processes the given player that has just joined.
|
||||||
*
|
*
|
||||||
* @param player the player to process
|
* @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 name = player.getName().toLowerCase();
|
||||||
final String ip = PlayerUtils.getPlayerIp(player);
|
final String ip = PlayerUtils.getPlayerIp(player);
|
||||||
|
|
||||||
@ -131,7 +133,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
processJoinSync(player, isAuthAvailable);
|
processJoinSync(player, isAuthAvailable, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePlayerWithUnmetNameRestriction(Player player, String ip) {
|
private void handlePlayerWithUnmetNameRestriction(Player player, String ip) {
|
||||||
@ -149,12 +151,13 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
*
|
*
|
||||||
* @param player the player to process
|
* @param player the player to process
|
||||||
* @param isAuthAvailable true if the player is registered, false otherwise
|
* @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;
|
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||||
|
|
||||||
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> {
|
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> {
|
||||||
limboService.createLimboPlayer(player, isAuthAvailable);
|
limboService.createLimboPlayer(player, isAuthAvailable, location);
|
||||||
|
|
||||||
player.setNoDamageTicks(registrationTimeout);
|
player.setNoDamageTicks(registrationTimeout);
|
||||||
if (pluginHookService.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) {
|
if (pluginHookService.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) {
|
||||||
|
|||||||
@ -496,7 +496,7 @@ public class PlayerListenerTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(teleportationService).teleportNewPlayerToFirstSpawn(player);
|
verify(teleportationService).teleportNewPlayerToFirstSpawn(player);
|
||||||
verify(management).performJoin(player);
|
verify(management).performJoin(player, player.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user