-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlayerUUIDCacheAPI.java
More file actions
310 lines (287 loc) · 12.9 KB
/
PlayerUUIDCacheAPI.java
File metadata and controls
310 lines (287 loc) · 12.9 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
package de.iani.playerUUIDCache;
import com.destroystokyo.paper.profile.PlayerProfile;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Future;
import org.bukkit.OfflinePlayer;
public interface PlayerUUIDCacheAPI {
/**
* Gets a CachedPlayer for an OfflinePlayer. The result may be null if this player is not found in the cache.
* This method will never block for querying Mojang.
* This method can be called from any thread.
*
* @param player
* the player to lookup
* @return the CachedPlayer or null
*/
CachedPlayer getPlayer(OfflinePlayer player);
/**
* Gets a CachedPlayer for a name.
* The result may be null if this player is not found in the cache.
* This method can be called from any thread.
*
* @param playerName
* the name of the player
* @return the CachedPlayer or null
*/
CachedPlayer getPlayer(String playerName);
/**
* Gets a CachedPlayer for a name.
* If no entry is found in the cache this method will query Mojang if queryMojangIfUnknown is true. This
* query is blocking, so avoid calling it in the main thread if possible.
* The result may be null if this player is not found in the cache.
* This method can be called from any thread.
*
* @param playerName
* the name of the player
* @param queryMojangIfUnknown
* query Mojang if this parameter is true and no entry is found in the cache
* @return the CachedPlayer or null
*/
CachedPlayer getPlayer(String playerName, boolean queryMojangIfUnknown);
/**
* Gets a CachedPlayer for a name asyncronously.
* If no entry is found in the cache this method will query Mojang. When the result is available,
* the callback is executed in the main thread. This query is not blocking the main thread.
* The callback will be called with null, if this player is not found.
* This method can be called from any thread.
*
* @param playerName
* the name of the player
* @param synchronousCallback
* a callback to execute when the result of the query to Mojang is completed
* @return the CachedPlayer or null
*/
void getPlayerAsynchronously(String playerName, Callback<CachedPlayer> synchronousCallback);
/**
* Gets a CachedPlayer for a name from Mojang.
* This method will not query the cache but will always send a request to Mojang. If possible,
* you should call Future.get() in a seperate thread to avoid blocking the main thread.
* This method can be called from any thread.
*
* The Future will return null, if this player is not found.
*
* @param playerName
* the name of the player
* @return a Future to query the result
*/
Future<CachedPlayer> loadPlayerAsynchronously(String playerName);
/**
* Gets multiple CachedPlayers by their name.
* This method will query Mojang if queryMojangIfUnknown is true and some players are not in the cache.
* This query is blocking, so avoid calling it in the main thread if possible.
* The result will only contain the players found.
* This method can be called from any thread.
*
* @param playerNames
* a Collection of player names
* @param queryMojangIfUnknown
* query Mojang if this parameter is true and not all players are found in the cache
* @return a Collection of CachedPlayers
*/
Collection<CachedPlayer> getPlayers(Collection<String> playerNames, boolean queryMojangIfUnknown);
/**
* Gets a CachedPlayer for a UUID.
* The result may be null if this player is not found in the cache.
*
* @param playerUUID
* the UUID of the player
* @return the CachedPlayer or null
*/
CachedPlayer getPlayer(UUID playerUUID);
/**
* Gets a CachedPlayer for a UUID.
* If no entry is found in the cache this method will query Mojang if queryMojangIfUnknown is true. This
* query is blocking, so avoid calling it in the main thread if possible.
* The result may be null if this player is not found in the cache.
* This method can be called from any thread.
*
* @param playerUUID
* the UUID of the player
* @param queryMojangIfUnknown
* query Mojang if this parameter is true and no entry is found in the cache
* @return the CachedPlayer or null
*/
CachedPlayer getPlayer(UUID playerUUID, boolean queryMojangIfUnknown);
/**
* Gets a CachedPlayer for a UUID asyncronously.
* If no entry is found in the cache this method will query Mojang. When the result is available,
* the callback is executed in the main thread. This query is not blocking the main thread.
* The callback will be called with null, if this player is not found.
* This method can be called from any thread.
*
* @param playerUUID
* the UUID of the player
* @param synchronousCallback
* a callback to execute when the result of the query to Mojang is completed
* @return the CachedPlayer or null
*/
void getPlayerAsynchronously(UUID playerUUID, Callback<CachedPlayer> synchronousCallback);
/**
* Gets a CachedPlayer for a UUID from Mojang.
* This method will not query the cache but will always send a request to Mojang. If possible,
* you should call Future.get() in a seperate thread to avoid blocking the main thread.
* This method can be called from any thread.
*
* The Future will return null, if this player is not found.
*
* @param playerUUID
* the UUID of the player
* @return a Future to query the result
*/
Future<CachedPlayer> loadPlayerAsynchronously(UUID playerUUID);
/**
* Gets a CachedPlayer for a name or UUID. This method detects if the perameter is a valid UUID
* and will try to use that for the lookup if possible. Otherwise it will try to use the String as a name.
* The result may be null if this player is not found in the cache.
* This method can be called from any thread.
*
* @param playerNameOrUUID
* the player to lookup - either the name or the UUID
* @return the CachedPlayer or null
*/
CachedPlayer getPlayerFromNameOrUUID(String playerNameOrUUID);
/**
* Gets a CachedPlayer for a name or UUID. This method detects if the perameter is a valid UUID
* and will try to use that for the lookup if possible. Otherwise it will try to use the String as a name.
* If no entry is found in the cache this method will query Mojang if queryMojangIfUnknown is true. This
* query is blocking, so avoid calling it in the main thread if possible.
* The result may be null if this player is not found.
* This method can be called from any thread.
*
* @param playerNameOrUUID
* the player to lookup - either the name or the UUID
* @param queryMojangIfUnknown
* query Mojang if this parameter is true and no entry is found in the cache
* @return the CachedPlayer or null
*/
CachedPlayer getPlayerFromNameOrUUID(String playerNameOrUUID, boolean queryMojangIfUnknown);
/**
* Searches for all known players whose names contain the given string. If a database is present, it will be used.
* If no database is present, or if the database query fails, the local cache will be used. If no local cache is
* present, null will be returned. This will never query Mojang. The resulting list is ordered by when the players
* were last seen on the server, with players seen more recently coming first.
*
* @param partialName
* a part of a name to search for
* @return a List of CachedPlayers whose names contain that part
*/
List<CachedPlayer> searchPlayersByPartialName(String partialName);
/**
* Loads all players from the database into the local cache. If not database is present, this method has no effect.
*/
void loadAllPlayersFromDatabase();
/**
* Gets a NameHistory for a UUID.
* The result may be null if this player's history is not found in the cache.
*
* @param playerUUID
* the UUID of the player
* @return the NameHistory or null
*/
NameHistory getNameHistory(UUID playerUUID);
/**
* Gets a NameHistory for a player.
* The result may be null if this player's history is not found in the cache.
* The PlayerProfile must return a UUID.
*
* @param player
* the player
* @return the NameHistory or null
*/
default NameHistory getNameHistory(PlayerProfile player) {
return getNameHistory(player.getId());
}
/**
* Gets a NameHistory for a player.
* The result may be null if this player's history is not found in the cache.
* The OfflinePlayer must return a UUID.
*
* @param player
* the player
* @return the NameHistory or null
*/
default NameHistory getNameHistory(OfflinePlayer player) {
return getNameHistory(player.getUniqueId());
}
/**
* Gets a NameHistory for a UUID.
* <s>If no entry is found in the cache this method will query Mojang if queryMojangIfUnknown is true. This
* query is blocking, so avoid calling it in the main thread if possible.</s>
* The result may be null if this player's history is not found in the cache.
* This method can be called from any thread.
*
* @param playerUUID
* the UUID of the player
* @param queryMojangIfUnknown
* <s>query Mojang if this parameter is true and no entry is found in the cache</s>
* @return the NameHistory or null
* @deprecated Mojang has removed the required API
*/
@Deprecated(forRemoval = true)
NameHistory getNameHistory(UUID playerUUID, boolean queryMojangIfUnknown);
/**
* Gets a NameHistory for a player.
* <s>If no entry is found in the cache this method will query Mojang if queryMojangIfUnknown is true. This
* query is blocking, so avoid calling it in the main thread if possible.</s>
* The result may be null if this player's history is not found in the cache.
* This method can be called from any thread.
* The OfflinePlayer must return a UUID.
*
* @param player
* the player
* @param queryMojangIfUnknown
* <s>query Mojang if this parameter is true and no entry is found in the cache</s>
* @return the NameHistory or null
* @deprecated Mojang has removed the required API
*/
@Deprecated(forRemoval = true)
default NameHistory getNameHistory(OfflinePlayer player, boolean queryMojangIfUnknown) {
return getNameHistory(player.getUniqueId());
}
/**
* Gets a NameHistory for a UUID asyncronously.
* <s>If no entry is found in the cache this method will query Mojang.</s> When the result is available,
* the callback is executed in the main thread. <s>This query is not blocking the main thread.</s>
* The callback will be called with null, if this player is not found.
* This method can be called from any thread.
*
* @param playerUUID
* the UUID of the player
* @param synchronousCallback
* a callback to execute when the result of the query to Mojang is completed
* @return the NameHistory or null
* @deprecated Mojang has removed the required API
*/
@Deprecated(forRemoval = true)
void getNameHistoryAsynchronously(UUID playerUUID, Callback<NameHistory> synchronousCallback);
/**
* <s>Gets a NameHistory for a UUID from Mojang.
* This method will not query the cache but will always send a request to Mojang. If possible,
* you should call Future.get() in a seperate thread to avoid blocking the main thread.
* This method can be called from any thread.</s>
*
* The Future will return null<s>, if this player is not found</s>.
*
* @param playerUUID
* the UUID of the player
* @return a Future to query the result
* @deprecated Mojang has removed the required API
*/
@Deprecated(forRemoval = true)
Future<NameHistory> loadNameHistoryAsynchronously(UUID playerUUID);
/**
* Returns the UUIDs of all player known to have used the given name in the past or present.
* This method will never query mojang. If no players are found, an empty set is returned.
*
* This method will usually query the database. If no database is present, it will iterate
* over the entire memory cache. Expect according performance.
*
* @param name
* the name to search for
* @return a set of all known players associated with that name
*/
Set<UUID> getCurrentAndPreviousPlayers(String name);
}