-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed Player to User argument in spent time command.
Moved catch git exception to UpdateService.
- Loading branch information
Showing
4 changed files
with
74 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/github/imdmk/spenttime/command/argument/UserArgument.java
This file contains 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,36 @@ | ||
package com.github.imdmk.spenttime.command.argument; | ||
|
||
import com.github.imdmk.spenttime.configuration.MessageConfiguration; | ||
import com.github.imdmk.spenttime.user.User; | ||
import com.github.imdmk.spenttime.user.UserManager; | ||
import dev.rollczi.litecommands.argument.simple.OneArgument; | ||
import dev.rollczi.litecommands.command.LiteInvocation; | ||
import dev.rollczi.litecommands.suggestion.Suggestion; | ||
import panda.std.Result; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class UserArgument implements OneArgument<User> { | ||
|
||
private final MessageConfiguration messageConfiguration; | ||
private final UserManager userManager; | ||
|
||
public UserArgument(MessageConfiguration messageConfiguration, UserManager userManager) { | ||
this.messageConfiguration = messageConfiguration; | ||
this.userManager = userManager; | ||
} | ||
|
||
@Override | ||
public Result<User, ?> parse(LiteInvocation liteInvocation, String argument) { | ||
Optional<User> userOptional = this.userManager.getOrFindUser(argument); | ||
|
||
return userOptional.map(Result::ok) | ||
.orElseGet(() -> Result.error(this.messageConfiguration.playerNotFoundNotification)); | ||
} | ||
|
||
@Override | ||
public List<Suggestion> suggest(LiteInvocation invocation) { | ||
return Suggestion.of(this.userManager.getNameUserCache()); | ||
} | ||
} |
This file contains 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