login process cleanup

This commit is contained in:
Gabriele C 2015-11-21 00:36:46 +01:00
parent 68ae6ee701
commit ada992785c

View File

@ -51,15 +51,16 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
protected void restoreOpState() { protected void restoreOpState() {
player.setOp(limbo.getOperator()); player.setOp(limbo.getOperator());
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { }
if (limbo.getGameMode() != GameMode.CREATIVE) {
player.setAllowFlight(limbo.isFlying()); protected void restoreFlyghtState() {
player.setFlying(limbo.isFlying()); if(Settings.isForceSurvivalModeEnabled) {
} else { player.setAllowFlight(false);
player.setAllowFlight(false); player.setFlying(false);
player.setFlying(false); return;
}
} }
player.setAllowFlight(limbo.isFlying());
player.setFlying(limbo.isFlying());
} }
protected void packQuitLocation() { protected void packQuitLocation() {
@ -107,28 +108,12 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
public void run() { public void run() {
// Limbo contains the State of the Player before /login // Limbo contains the State of the Player before /login
if (limbo != null) { if (limbo != null) {
// Op & Flying
restoreOpState();
/* // Restore Op state and Permission Group
* Restore Inventories and GameMode We need to restore them before restoreOpState();
* teleport the player Cause in AuthMePlayerListener, we call Utils.setGroup(player, GroupType.LOGGEDIN);
* ProtectInventoryEvent after Teleporting Also it's the current
* world inventory !
*/
player.setGameMode(limbo.getGameMode());
// Inventory - Make it after restore GameMode , cause we need to
// restore the
// right inventory in the right gamemode
if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
restoreInventory();
}
if (Settings.forceOnlyAfterLogin) {
player.setGameMode(GameMode.SURVIVAL);
}
if (!Settings.noTeleport) { if (!Settings.noTeleport) {
// Teleport
if (Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) { if (Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) { if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
packQuitLocation(); packQuitLocation();
@ -145,13 +130,17 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
} }
} }
// Re-Force Survival GameMode if we need due to world change if (Settings.isForceSurvivalModeEnabled && Settings.forceOnlyAfterLogin) {
// specification
if (Settings.isForceSurvivalModeEnabled)
Utils.forceGM(player); Utils.forceGM(player);
} else {
player.setGameMode(limbo.getGameMode());
}
restoreFlyghtState();
// Restore Permission Group if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
Utils.setGroup(player, GroupType.LOGGEDIN); restoreInventory();
}
// Cleanup no longer used temporary data // Cleanup no longer used temporary data
LimboCache.getInstance().deleteLimboPlayer(name); LimboCache.getInstance().deleteLimboPlayer(name);
@ -160,23 +149,28 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
} }
} }
// We can now display the join message // We can now display the join message (if delayed)
if (AuthMePlayerListener.joinMessage.containsKey(name) && AuthMePlayerListener.joinMessage.get(name) != null && !AuthMePlayerListener.joinMessage.get(name).isEmpty()) { String jm = AuthMePlayerListener.joinMessage.get(name);
for (Player p : Utils.getOnlinePlayers()) { if (jm != null) {
if (p.isOnline()) if(!jm.isEmpty()) {
p.sendMessage(AuthMePlayerListener.joinMessage.get(name)); for (Player p : Utils.getOnlinePlayers()) {
if (p.isOnline())
p.sendMessage(jm);
}
} }
AuthMePlayerListener.joinMessage.remove(name); AuthMePlayerListener.joinMessage.remove(name);
} }
if (Settings.applyBlindEffect) if (Settings.applyBlindEffect) {
player.removePotionEffect(PotionEffectType.BLINDNESS); player.removePotionEffect(PotionEffectType.BLINDNESS);
}
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) { if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
player.setWalkSpeed(0.2f); player.setWalkSpeed(0.2f);
player.setFlySpeed(0.1f); player.setFlySpeed(0.1f);
} }
// The Loginevent now fires (as intended) after everything is processed // The Login event now fires (as intended) after everything is processed
Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true)); Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true));
player.saveData(); player.saveData();