Fix player always teleport to spawn on join.

This commit is contained in:
DNx5 2016-06-29 22:02:45 +07:00
parent 56d6fd81b4
commit 5726b0d326
4 changed files with 53 additions and 44 deletions

View File

@ -194,6 +194,7 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer();
teleportationService.teleportOnJoin(player);
management.performJoin(player);
}
@ -232,7 +233,7 @@ public class AuthMePlayerListener implements Listener {
}
antiBot.handlePlayerJoin(player);
teleportationService.teleportOnJoin(player);
teleportationService.teleportOnLoginEvent(player);
}
@EventHandler(priority = EventPriority.HIGHEST)

View File

@ -8,8 +8,7 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.entity.Player;
import javax.inject.Inject;
@ -31,10 +30,8 @@ public class AsynchronousLogout implements AsynchronousProcess {
@Inject
private SyncProcessManager syncProcessManager;
@Inject
private BukkitService bukkitService;
AsynchronousLogout() { }
AsynchronousLogout() {
}
public void logout(final Player player) {
final String name = player.getName().toLowerCase();
@ -42,23 +39,20 @@ public class AsynchronousLogout implements AsynchronousProcess {
service.send(player, MessageKey.NOT_LOGGED_IN);
return;
}
PlayerAuth auth = playerCache.getAuth(name);
database.updateSession(auth);
auth.setQuitLocX(player.getLocation().getX());
auth.setQuitLocY(player.getLocation().getY());
auth.setQuitLocZ(player.getLocation().getZ());
auth.setWorld(player.getWorld().getName());
database.updateQuitLoc(auth);
if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
auth.setQuitLocX(player.getLocation().getX());
auth.setQuitLocY(player.getLocation().getY());
auth.setQuitLocZ(player.getLocation().getZ());
auth.setWorld(player.getWorld().getName());
database.updateQuitLoc(auth);
}
limboCache.updateLimboPlayer(player);
playerCache.removePlayer(name);
database.setUnlogged(name);
bukkitService.scheduleSyncDelayedTask(new Runnable() {
@Override
public void run() {
Utils.teleportToSpawn(player);
}
});
limboCache.updateLimboPlayer(player);
syncProcessManager.processSyncPlayerLogout(player);
}
}

View File

@ -69,22 +69,7 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
limboPlayerTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, true);
if (player.isInsideVehicle() && player.getVehicle() != null) {
player.getVehicle().eject();
}
final int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
}
service.setGroup(player, AuthGroupType.NOT_LOGGED_IN);
player.setOp(false);
// Remove speed
if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)
&& service.getProperty(RestrictionSettings.REMOVE_SPEED)) {
player.setFlySpeed(0.0f);
player.setWalkSpeed(0.0f);
}
applyLogoutEffect(player);
// Player is now logout... Time to fire event !
bukkitService.callEvent(new LogoutEvent(player));
@ -95,4 +80,28 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
ConsoleLogger.info(player.getName() + " logged out");
}
private void applyLogoutEffect(Player player) {
// dismount player
if (player.isInsideVehicle() && player.getVehicle() != null) {
player.getVehicle().eject();
}
// Apply Blindness effect
final int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
}
// Set player's data to unauthenticated
service.setGroup(player, AuthGroupType.NOT_LOGGED_IN);
player.setOp(false);
player.setAllowFlight(false);
// Remove speed
if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)
&& service.getProperty(RestrictionSettings.REMOVE_SPEED)) {
player.setFlySpeed(0.0f);
player.setWalkSpeed(0.0f);
}
}
}

View File

@ -41,8 +41,12 @@ public class TeleportationService implements Reloadable {
private Set<String> spawnOnLoginWorlds;
TeleportationService() { }
TeleportationService() {
}
private static boolean isEventValid(AbstractTeleportEvent event) {
return !event.isCancelled() && event.getTo() != null && event.getTo().getWorld() != null;
}
@PostConstruct
@Override
@ -51,11 +55,9 @@ public class TeleportationService implements Reloadable {
spawnOnLoginWorlds = new HashSet<>(settings.getProperty(RestrictionSettings.FORCE_SPAWN_ON_WORLDS));
}
public void teleportOnJoin(final Player player) {
public void teleportOnLoginEvent(final Player player) {
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
return;
} else if (teleportToFirstSpawn(player)) {
return;
}
if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN) || mustForceSpawnAfterLogin(player.getWorld().getName())) {
@ -63,6 +65,13 @@ public class TeleportationService implements Reloadable {
}
}
public void teleportOnJoin(final Player player) {
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
return;
}
teleportToFirstSpawn(player);
}
public void teleportOnLogin(final Player player, PlayerAuth auth, LimboPlayer limbo) {
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
return;
@ -122,7 +131,7 @@ public class TeleportationService implements Reloadable {
* by external listeners). Note that not teleportation is performed if the event's location is empty.
*
* @param player the player to teleport
* @param event the event to emit and according to which to teleport
* @param event the event to emit and according to which to teleport
*/
private void performTeleportation(final Player player, final AbstractTeleportEvent event) {
bukkitService.scheduleSyncDelayedTask(new Runnable() {
@ -135,8 +144,4 @@ public class TeleportationService implements Reloadable {
}
});
}
private static boolean isEventValid(AbstractTeleportEvent event) {
return !event.isCancelled() && event.getTo() != null && event.getTo().getWorld() != null;
}
}