-
Notifications
You must be signed in to change notification settings - Fork 557
Expand file tree
/
Copy pathProcessSyncPlayerLogin.java
More file actions
129 lines (101 loc) · 4.4 KB
/
ProcessSyncPlayerLogin.java
File metadata and controls
129 lines (101 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package fr.xephi.authme.process.login;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboPlayer;
import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RestoreInventoryEvent;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.JoinMessageService;
import fr.xephi.authme.service.SpectateLoginService;
import fr.xephi.authme.service.TeleportationService;
import fr.xephi.authme.service.bungeecord.BungeeSender;
import fr.xephi.authme.settings.WelcomeMessageConfiguration;
import fr.xephi.authme.settings.commandconfig.CommandManager;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import javax.inject.Inject;
import java.util.List;
import java.util.Locale;
import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN;
public class ProcessSyncPlayerLogin implements SynchronousProcess {
@Inject
private BungeeSender bungeeSender;
@Inject
private LimboService limboService;
@Inject
private BukkitService bukkitService;
@Inject
private TeleportationService teleportationService;
@Inject
private PlayerCache playerCache;
@Inject
private CommandManager commandManager;
@Inject
private CommonService commonService;
@Inject
private WelcomeMessageConfiguration welcomeMessageConfiguration;
@Inject
private JoinMessageService joinMessageService;
@Inject
private PermissionsManager permissionsManager;
@Inject
private SpectateLoginService spectateLoginService;
ProcessSyncPlayerLogin() {
}
private void restoreInventory(Player player) {
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
bukkitService.callEvent(event);
if (!event.isCancelled()) {
player.updateInventory();
}
}
/**
* Performs operations in sync mode for a player that has just logged in.
*
* @param player the player that was logged in
* @param isFirstLogin true if this is the first time the player logged in
* @param authsWithSameIp registered names with the same IP address as the player's
*/
public void processPlayerLogin(Player player, boolean isFirstLogin, List<String> authsWithSameIp) {
final String name = player.getName().toLowerCase(Locale.ROOT);
final LimboPlayer limbo = limboService.getLimboPlayer(name);
// Limbo contains the State of the Player before /login
if (limbo != null) {
limboService.restoreData(player);
}
if (commonService.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
restoreInventory(player);
}
final PlayerAuth auth = playerCache.getAuth(name);
teleportationService.teleportOnLogin(player, auth, limbo);
// We can now display the join message (if delayed)
joinMessageService.sendMessage(name);
if (commonService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
player.removePotionEffect(PotionEffectType.BLINDNESS);
}
if (commonService.getProperty(RestrictionSettings.SPECTATE_STAND_LOGIN)
|| spectateLoginService.hasStand(player)) {
spectateLoginService.removeStand(player);
}
// The Login event now fires (as intended) after everything is processed
bukkitService.callEvent(new LoginEvent(player));
// Login is done, display welcome message
welcomeMessageConfiguration.sendWelcomeMessage(player);
// Login is now finished; we can force all commands
if (isFirstLogin) {
commandManager.runCommandsOnFirstLogin(player, authsWithSameIp);
}
commandManager.runCommandsOnLogin(player, authsWithSameIp);
if (!permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_BUNGEE_SEND)) {
// Send Bungee stuff. The service will check if it is enabled or not.
bungeeSender.connectPlayerOnLogin(player);
}
}
}