Repository navigation
GH-1467 Expose user management through public API #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
P1otrulla
wants to merge
3
commits into
master
Choose a base branch
from
ficzer/improve-user-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+287
−174
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
eternalcore-api/src/main/java/com/eternalcode/core/user/User.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.eternalcode.core.user; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * Immutable snapshot of a player's EternalCore account data. | ||
| */ | ||
| public interface User { | ||
|
|
||
| UUID getUniqueId(); | ||
|
|
||
| String getName(); | ||
|
|
||
| Instant getLastSeen(); | ||
|
|
||
| Instant getAccountCreated(); | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
eternalcore-api/src/main/java/com/eternalcode/core/user/UserManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.eternalcode.core.user; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| public interface UserManager { | ||
|
|
||
| /** | ||
| * Returns the cached user with the given unique id. | ||
| */ | ||
| Optional<User> getUser(UUID uniqueId); | ||
|
|
||
| /** | ||
| * Returns the cached user with the given name. | ||
| */ | ||
| Optional<User> getUser(String name); | ||
|
|
||
| /** | ||
| * Loads the user from cache or database, creating a new one if it does not exist. | ||
| * Refreshes the user's name and last seen time. | ||
| */ | ||
| CompletableFuture<User> findOrCreate(UUID uniqueId, String name); | ||
|
|
||
| /** | ||
| * Returns an immutable snapshot of all cached users. | ||
| */ | ||
| Collection<User> getUsers(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 0 additions & 68 deletions
68
eternalcore-core/src/main/java/com/eternalcode/core/user/User.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
eternalcore-core/src/main/java/com/eternalcode/core/user/UserImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package com.eternalcode.core.user; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.Objects; | ||
| import java.util.UUID; | ||
|
|
||
| public final class UserImpl implements User { | ||
|
|
||
| private final UUID uniqueId; | ||
| private final String name; | ||
| private final Instant lastSeen; | ||
| private final Instant accountCreated; | ||
|
|
||
| public UserImpl(UUID uniqueId, String name, Instant lastSeen, Instant accountCreated) { | ||
| this.uniqueId = uniqueId; | ||
| this.name = name; | ||
| this.lastSeen = lastSeen; | ||
| this.accountCreated = accountCreated; | ||
| } | ||
|
|
||
| static UserImpl create(UUID uniqueId, String name, Instant lastSeen, Instant accountCreated) { | ||
| return new UserImpl(uniqueId, name, lastSeen, accountCreated); | ||
| } | ||
|
|
||
| @Override | ||
| public UUID getUniqueId() { | ||
| return this.uniqueId; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return this.name; | ||
| } | ||
|
|
||
| @Override | ||
| public Instant getLastSeen() { | ||
| return this.lastSeen; | ||
| } | ||
|
|
||
| @Override | ||
| public Instant getAccountCreated() { | ||
| return this.accountCreated; | ||
| } | ||
|
|
||
| UserImpl withName(String name) { | ||
| return new UserImpl(this.uniqueId, name, this.lastSeen, this.accountCreated); | ||
| } | ||
|
|
||
| UserImpl withLastSeen(Instant lastSeen) { | ||
| return new UserImpl(this.uniqueId, this.name, lastSeen, this.accountCreated); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (o == null || this.getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| UserImpl user = (UserImpl) o; | ||
|
|
||
| return Objects.equals(this.uniqueId, user.uniqueId) | ||
| && Objects.equals(this.name, user.name) | ||
| && Objects.equals(this.lastSeen, user.lastSeen) | ||
| && Objects.equals(this.accountCreated, user.accountCreated); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(this.uniqueId, this.name, this.lastSeen, this.accountCreated); | ||
| } | ||
| } |
89 changes: 0 additions & 89 deletions
89
eternalcore-core/src/main/java/com/eternalcode/core/user/UserManager.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.