mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Fix tphere not returning an error for unresolved players
This commit is contained in:
1 parent
8854d3569f
commit
10b398b783
9 files changed
+56
-24
No files matched your search
@@ -53,13 +53,13 @@ public interface HuskHomes {
|
||||
List<OnlineUser> getOnlinePlayers();
|
||||
|
||||
/**
|
||||
* Finds a {@link OnlineUser} by their name. Auto-completes partially typed names for the closest match
|
||||
* Finds a local {@link OnlineUser} by their name. Auto-completes partially typed names for the closest match
|
||||
*
|
||||
* @param playerName the name of the player to find
|
||||
* @return an {@link Optional} containing the {@link OnlineUser} if found, or an empty {@link Optional} if not found
|
||||
*/
|
||||
@NotNull
|
||||
default Optional<OnlineUser> findPlayer(@NotNull String playerName) {
|
||||
default Optional<OnlineUser> findOnlinePlayer(@NotNull String playerName) {
|
||||
return getOnlinePlayers().stream()
|
||||
.filter(user -> user.username.equalsIgnoreCase(playerName))
|
||||
.findFirst()
|
||||
@@ -68,6 +68,29 @@ public interface HuskHomes {
|
||||
.findFirst());
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for a player logged in either on this server or the network of connected servers, by approximate name.
|
||||
* Auto-completes partially typed names for the closest match.
|
||||
*
|
||||
* @param requester the player requesting the player to be found
|
||||
* @param targetPlayerName the name of the player to find
|
||||
* @return an {@link Optional} containing the {@link OnlineUser} if found, or an empty {@link Optional} if not found
|
||||
*/
|
||||
@NotNull
|
||||
default CompletableFuture<Optional<String>> findPlayer(@NotNull OnlineUser requester, @NotNull String targetPlayerName) {
|
||||
if (requester.username.equalsIgnoreCase(targetPlayerName)) {
|
||||
return CompletableFuture.completedFuture(Optional.of(requester.username));
|
||||
}
|
||||
final Optional<OnlineUser> localPlayer = findOnlinePlayer(targetPlayerName);
|
||||
if (localPlayer.isPresent()) {
|
||||
return CompletableFuture.completedFuture(Optional.of(localPlayer.get().username));
|
||||
}
|
||||
if (getSettings().crossServer) {
|
||||
return getNetworkMessenger().findPlayer(requester, targetPlayerName);
|
||||
}
|
||||
return CompletableFuture.completedFuture(Optional.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin {@link Settings} loaded from file
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user