-
Notifications
You must be signed in to change notification settings - Fork 560
Expand file tree
/
Copy pathLimboPlayer.java
More file actions
149 lines (129 loc) · 3.94 KB
/
LimboPlayer.java
File metadata and controls
149 lines (129 loc) · 3.94 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package fr.xephi.authme.data.limbo;
import fr.xephi.authme.task.MessageTask;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.scheduler.BukkitTask;
import java.util.ArrayList;
import java.util.Collection;
/**
* Represents a player which is not logged in and keeps track of certain states (like OP status, flying)
* which may be revoked from the player until he has logged in or registered.
*/
public class LimboPlayer {
public static final float DEFAULT_WALK_SPEED = 0.2f;
public static final float DEFAULT_FLY_SPEED = 0.1f;
private final boolean canFly;
private final boolean operator;
private final Collection<UserGroup> groups;
private final Location loc;
private final float walkSpeed;
private final float flySpeed;
private final GameMode gameMode;
private BukkitTask timeoutTask = null;
private MessageTask messageTask = null;
private LimboPlayerState state = LimboPlayerState.PASSWORD_REQUIRED;
public LimboPlayer(Location loc, boolean operator, Collection<UserGroup> groups, boolean fly, float walkSpeed,
float flySpeed, GameMode gameMode) {
this.loc = loc;
this.operator = operator;
this.groups = new ArrayList<>(groups); // prevent bug #2413
this.canFly = fly;
this.walkSpeed = walkSpeed;
this.flySpeed = flySpeed;
this.gameMode = gameMode;
}
/**
* Return the player's original location.
*
* @return The player's location
*/
public Location getLocation() {
return loc;
}
/**
* Return the player's original gamemode.
*
* @return The player's gamemode
*/
public GameMode getGameMode() {
return gameMode;
}
/**
* Return whether the player is an operator or not (i.e. whether he is an OP).
*
* @return True if the player has OP status, false otherwise
*/
public boolean isOperator() {
return operator;
}
/**
* Return the player's permissions groups.
*
* @return The permissions groups the player belongs to
*/
public Collection<UserGroup> getGroups() {
return groups;
}
public boolean isCanFly() {
return canFly;
}
public float getWalkSpeed() {
return walkSpeed;
}
public float getFlySpeed() {
return flySpeed;
}
/**
* Return the timeout task, which kicks the player if he hasn't registered or logged in
* after a configurable amount of time.
*
* @return The timeout task associated to the player
*/
public BukkitTask getTimeoutTask() {
return timeoutTask;
}
/**
* Set the timeout task of the player. The timeout task kicks the player after a configurable
* amount of time if he hasn't logged in or registered.
*
* @param timeoutTask The task to set
*/
public void setTimeoutTask(BukkitTask timeoutTask) {
if (this.timeoutTask != null) {
this.timeoutTask.cancel();
}
this.timeoutTask = timeoutTask;
}
/**
* Return the message task reminding the player to log in or register.
*
* @return The task responsible for sending the message regularly
*/
public MessageTask getMessageTask() {
return messageTask;
}
/**
* Set the messages task responsible for telling the player to log in or register.
*
* @param messageTask The message task to set
*/
public void setMessageTask(MessageTask messageTask) {
if (this.messageTask != null) {
this.messageTask.cancel();
}
this.messageTask = messageTask;
}
/**
* Clears all tasks associated to the player.
*/
public void clearTasks() {
setMessageTask(null);
setTimeoutTask(null);
}
public LimboPlayerState getState() {
return state;
}
public void setState(LimboPlayerState state) {
this.state = state;
}
}