-
-
Notifications
You must be signed in to change notification settings - Fork 20
GH-1147 Make UserManager use UserRepository #1147
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
CitralFlo
wants to merge
16
commits into
master
Choose a base branch
from
user-manager-database
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.
+219
−385
Open
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
92868fe
Add database for users, add batch fetching, update tests
CitralFlo 1a7dd18
Codestyle fixes
CitralFlo 3c6ad2a
Resolve gemini review
CitralFlo 7d3ee9e
Resolve @sadcenter and @Jakubk15 reviews
CitralFlo 9414f7d
wip
Rollczi b3efc5f
wip2
CitralFlo 2050371
Merge remote-tracking branch 'origin/user-manager-database' into user…
CitralFlo 0cdf8b2
wip
CitralFlo 11813d4
Update methods and failsafe for cache
CitralFlo 14a95d6
Merge branch 'master' into user-manager-database
vLuckyyy c3aa70a
Merge branch 'master' into user-manager-database
vLuckyyy 80730a5
Refactor `UserManager` and related classes to improve database integr…
vLuckyyy 2e0a7e1
Remove MySQL and Testcontainers integration, refactor database config…
vLuckyyy 5cebc63
CR
Rollczi 5f086ae
Remove `created` and `lastLogin` fields from `User`, cleanup related …
vLuckyyy d42de10
Remove `IntegrationTestSpec` and `TestScheduler` utilities as they ar…
vLuckyyy 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
Some comments aren't visible on the classic Files Changed page.
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
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,9 +13,9 @@ | |||||||
| import com.google.common.cache.CacheBuilder; | ||||||||
| import java.time.Duration; | ||||||||
| import java.util.HashSet; | ||||||||
| import java.util.Optional; | ||||||||
| import java.util.Set; | ||||||||
| import java.util.UUID; | ||||||||
| import org.bukkit.Server; | ||||||||
| import org.bukkit.entity.Player; | ||||||||
|
|
||||||||
| @Service | ||||||||
|
|
@@ -27,6 +27,7 @@ class MsgServiceImpl implements MsgService { | |||||||
| private final MsgPresenter presenter; | ||||||||
| private final EventCaller eventCaller; | ||||||||
| private final MsgToggleService msgToggleService; | ||||||||
| private final Server server; | ||||||||
|
|
||||||||
| private final Cache<UUID, UUID> replies = CacheBuilder.newBuilder() | ||||||||
| .expireAfterWrite(Duration.ofHours(1)) | ||||||||
|
|
@@ -40,7 +41,7 @@ class MsgServiceImpl implements MsgService { | |||||||
| IgnoreService ignoreService, | ||||||||
| UserManager userManager, | ||||||||
| EventCaller eventCaller, | ||||||||
| MsgToggleService msgToggleService | ||||||||
| MsgToggleService msgToggleService, Server server | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| ) { | ||||||||
| this.noticeService = noticeService; | ||||||||
| this.ignoreService = ignoreService; | ||||||||
|
|
@@ -49,15 +50,10 @@ class MsgServiceImpl implements MsgService { | |||||||
| this.msgToggleService = msgToggleService; | ||||||||
|
|
||||||||
| this.presenter = new MsgPresenter(noticeService); | ||||||||
| this.server = server; | ||||||||
| } | ||||||||
|
|
||||||||
| void privateMessage(User sender, User target, String message) { | ||||||||
| if (target.getClientSettings().isOffline()) { | ||||||||
| this.noticeService.player(sender.getUniqueId(), translation -> translation.argument().offlinePlayer()); | ||||||||
|
|
||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| UUID uniqueId = target.getUniqueId(); | ||||||||
|
|
||||||||
| this.msgToggleService.getState(uniqueId).thenAccept(msgState -> { | ||||||||
|
|
@@ -89,17 +85,14 @@ void reply(User sender, String message) { | |||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| Optional<User> targetOption = this.userManager.getUser(uuid); | ||||||||
|
|
||||||||
| if (targetOption.isEmpty()) { | ||||||||
| Player target = this.server.getPlayer(uuid); | ||||||||
| if (target == null) { | ||||||||
| this.noticeService.player(sender.getUniqueId(), translation -> translation.argument().offlinePlayer()); | ||||||||
|
|
||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| User target = targetOption.get(); | ||||||||
|
|
||||||||
| this.privateMessage(sender, target, message); | ||||||||
| this.privateMessage(sender, toUser(target), message); | ||||||||
| } | ||||||||
|
|
||||||||
| @Override | ||||||||
|
|
@@ -119,12 +112,18 @@ public boolean isSpy(UUID player) { | |||||||
|
|
||||||||
| @Override | ||||||||
| public void reply(Player sender, String message) { | ||||||||
| this.reply(this.userManager.getOrCreate(sender.getUniqueId(), sender.getName()), message); | ||||||||
| this.reply(toUser(sender), message); | ||||||||
| } | ||||||||
|
|
||||||||
| @Override | ||||||||
| public void sendMessage(Player sender, Player target, String message) { | ||||||||
| User user = this.userManager.getOrCreate(target.getUniqueId(), target.getName()); | ||||||||
| this.privateMessage(this.userManager.getOrCreate(sender.getUniqueId(), sender.getName()), user, message); | ||||||||
| User user = toUser(target); | ||||||||
| this.privateMessage(toUser(sender), user, message); | ||||||||
| } | ||||||||
|
|
||||||||
| private User toUser(Player target) { | ||||||||
| return this.userManager.getUser(target.getUniqueId()).get(); | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
| } | ||||||||
34 changes: 0 additions & 34 deletions
34
eternalcore-core/src/main/java/com/eternalcode/core/user/LoadUserController.java
This file was deleted.
Oops, something went wrong.
53 changes: 0 additions & 53 deletions
53
eternalcore-core/src/main/java/com/eternalcode/core/user/PrepareUserController.java
This file was deleted.
Oops, something went wrong.
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
44 changes: 0 additions & 44 deletions
44
eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientBukkitSettings.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientNoneSettings.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientSettings.java
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
eternalcore-core/src/main/java/com/eternalcode/core/user/UserController.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,55 @@ | ||
| package com.eternalcode.core.user; | ||
|
|
||
| import com.eternalcode.core.injector.annotations.Inject; | ||
| import com.eternalcode.core.injector.annotations.component.Controller; | ||
| import org.bukkit.Server; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.player.PlayerJoinEvent; | ||
| import org.bukkit.event.player.PlayerQuitEvent; | ||
| import org.bukkit.event.server.ServerLoadEvent; | ||
|
|
||
| @Controller | ||
| public class UserController implements Listener { | ||
|
|
||
| private final UserManager userManager; | ||
| private final Server server; | ||
|
|
||
| @Inject | ||
| public UserController(UserManager userManager, Server server) { | ||
| this.userManager = userManager; | ||
| this.server = server; | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.LOWEST) | ||
| public void onJoin(PlayerJoinEvent event) { | ||
| Player player = event.getPlayer(); | ||
| this.userManager.findOrCreate(player.getUniqueId(), player.getName()) | ||
| .exceptionally(throwable -> { | ||
| player.kickPlayer("Failed to load user data. Please try again."); | ||
| throw new RuntimeException("Failed to load user: " + player.getName(), throwable); | ||
| }); | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR) | ||
| public void onQuit(PlayerQuitEvent event) { | ||
| Player player = event.getPlayer(); | ||
| this.userManager.updateLastSeen(player.getUniqueId(), player.getName()) | ||
| .exceptionally(throwable -> { | ||
| throw new RuntimeException("Failed to update user: " + player.getName(), throwable); | ||
| }); | ||
| } | ||
|
|
||
| @EventHandler | ||
| void onReload(ServerLoadEvent event) { | ||
| if (event.getType() != ServerLoadEvent.LoadType.RELOAD) { | ||
| return; | ||
| } | ||
|
|
||
| for (Player player : this.server.getOnlinePlayers()) { | ||
| this.userManager.findOrCreate(player.getUniqueId(), player.getName()); | ||
| } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.