2929import org .spongepowered .api .profile .GameProfile ;
3030import org .spongepowered .api .profile .GameProfileManager ;
3131
32- import java .util .Collection ;
3332import java .util .Optional ;
3433import java .util .UUID ;
34+ import java .util .concurrent .CompletableFuture ;
3535import java .util .stream .Stream ;
3636
3737/**
3838 * Stores the persistent {@link User} data of a {@link Player}.
39+ *
40+ * <p>Any {@link User}s retrieved from this manager should not be stored, as
41+ * they may become invalid at any time.</p>
3942 */
4043public interface UserManager {
4144
@@ -45,7 +48,7 @@ public interface UserManager {
4548 * @param uniqueId The UUID of the user
4649 * @return {@link User} or Optional.empty() if not found
4750 */
48- Optional <User > find (UUID uniqueId );
51+ CompletableFuture < Optional <User >> load (UUID uniqueId );
4952
5053 /**
5154 * Gets the data of a {@link User} by their last known user name
@@ -57,58 +60,76 @@ public interface UserManager {
5760 * @param lastKnownName The user name
5861 * @return {@link User} or Optional.empty() if not found
5962 */
60- Optional <User > find (String lastKnownName );
63+ CompletableFuture < Optional <User >> load (String lastKnownName );
6164
6265 /**
6366 * Gets the data of a {@link User} by their {@link GameProfile}.
6467 *
6568 * @param profile The profile
6669 * @return {@link User} or Optional.empty() if not found
6770 */
68- Optional <User > find (GameProfile profile );
71+ CompletableFuture < Optional <User >> load (GameProfile profile );
6972
7073 /**
71- * Gets or creates a persistent {@link User} associated with the given
72- * {@link GameProfile}.
73- *
74- * <p>To obtain a {@link GameProfile}, use the {@link GameProfileManager}.
75- * </p>
74+ * Gets or creates a persistent {@link User} with the given UUID.
7675 *
77- * @param profile The profile
76+ * @param uuid The {@link UUID} of the player to load or create.
7877 * @return The user object
7978 */
80- User findOrCreate ( GameProfile profile );
79+ CompletableFuture < User > loadOrCreate ( UUID uuid );
8180
8281 /**
83- * Gets the collection of all {@link GameProfile}s with stored {@link User}
84- * data .
82+ * Deletes the data associated with a {@link User}, if the player is
83+ * offline .
8584 *
86- * <p>This method may be resource intensive, particularly for servers that
87- * have a large number of {@link User}s. If you require a subset of this
88- * {@link Collection}, use {@link #streamOfMatches(String)} or
89- * {@link #streamAll()} and use {@link Stream} operations for your queries
90- * instead.</p>
85+ * @param uuid The uuid of the user to delete
86+ * @return true if the deletion was successful
87+ */
88+ CompletableFuture <Boolean > delete (UUID uuid );
89+
90+ /**
91+ * If the implementation supports caching user objects, this will hint
92+ * to the implementation that the user with the given UUID should no
93+ * longer be cached. Any {@link User} objects held that this point
94+ * will become invalid (though developers should not be storing
95+ * users).
9196 *
92- * <p>This {@link Stream} may contain profiles that only hold a result for
93- * {@link GameProfile#uniqueId()}, that is, do not return a user's name.
94- * Such profiles should thus be treated as incomplete and are no more than
95- * an indicator that a {@link User} associated with the given {@link UUID}
96- * exists.</p>
97+ * <p>Be aware, any changes that have been made to the user may not
98+ * be saved.</p>
9799 *
98- * <p>Similarly, for {@link GameProfile}s that are filled and thus contain
99- * name data, the profile information is based on the latest information
100- * the server holds and no attempt is made to update this information.</p>
100+ * <p>Users that are online will not be affected by this call.</p>
101101 *
102- * <p>If you require up to date {@link GameProfile}s, use the appropriate
103- * methods on the {@link GameProfileManager} and/or its associated
104- * {@link GameProfileManager}.</p>
102+ * @param uuid The UUID of the user to save.
103+ * @return {@code true} if the user was removed from a cache.
104+ */
105+ boolean removeFromCache (UUID uuid );
106+
107+ /**
108+ * If the implementation supports caching user objects, this will hint
109+ * to the implementation that the user with the given UUID should be saved
110+ * to the disk immediately.
105111 *
106- * <p>Use {@link #find(GameProfile)} to load the {@link User} data associated
107- * with the associated {@link GameProfile}.</p>
112+ * <p>If an exception is encountered during save, the completed future
113+ * will be exceptional and the boolean will be {@code null}. It is therefore
114+ * recommended that you check for any exceptions this future holds.</p>
108115 *
109- * @return A {@link Stream} of {@link GameProfile}s
116+ * @param uuid The user to attempt to save.
117+ * @return A completed future that returns {@code true} if the implementation
118+ * saved the user.
119+ */
120+ CompletableFuture <Boolean > forceSave (UUID uuid );
121+
122+ /**
123+ * Returns whether data to create a {@link User} exists for a given
124+ * player with a specified {@link UUID}.
125+ *
126+ * <p>If this is {@code false}, then {@link #load(UUID)} will return
127+ * an {@linkplain Optional#empty() empty optional}.</p>
128+ *
129+ * @param playerUuid The {@link UUID} of the player to check.
130+ * @return If the player has existing user data that can be loaded.
110131 */
111- Collection < GameProfile > all ( );
132+ boolean exists ( UUID playerUuid );
112133
113134 /**
114135 * Gets a {@link Stream} that returns a {@link GameProfile} for each stored
@@ -128,33 +149,13 @@ public interface UserManager {
128149 * methods on the {@link GameProfileManager} and/or its associated
129150 * {@link GameProfileManager}.</p>
130151 *
131- * <p>Use {@link #find (GameProfile)} to load the {@link User} data associated
152+ * <p>Use {@link #load (GameProfile)} to load the {@link User} data associated
132153 * with the associated {@link GameProfile}.</p>
133154 *
134155 * @return A {@link Stream} of {@link GameProfile}s
135156 */
136157 Stream <GameProfile > streamAll ();
137158
138- /**
139- * Deletes the data associated with a {@link User}.
140- *
141- * <p>This may not work if the user is logged in.</p>
142- *
143- * @param profile The profile of the user to delete
144- * @return true if the deletion was successful
145- */
146- boolean delete (GameProfile profile );
147-
148- /**
149- * Deletes the data associated with a {@link User}.
150- *
151- * <p>This may not work if the user is logged in.</p>
152- *
153- * @param user The user to delete
154- * @return true if the deletion was successful
155- */
156- boolean delete (User user );
157-
158159 /**
159160 * Gets a {@link Stream} that returns a {@link GameProfile} for each stored
160161 * {@link User} whose last known user names start with the given string
@@ -168,7 +169,7 @@ public interface UserManager {
168169 * methods on the {@link GameProfileManager} and/or its associated
169170 * {@link GameProfileManager}.</p>
170171 *
171- * <p>Use {@link #find (GameProfile)} to load associated {@link User} data.
172+ * <p>Use {@link #load (GameProfile)} to load associated {@link User} data.
172173 * </p>
173174 *
174175 * @param lastKnownName The name to check for
0 commit comments