Fix local username closest-match resolution overriding global exact matches (#392)

This commit is contained in:
William authored and GitHub committed 2023-05-05 17:45:29 +01:00
1 parent b1bd44ac64
commit daa72182f8
11 files changed
+85 -23

No files matched your search

@@ -78,6 +78,31 @@ public interface HuskHomes extends TaskRunner, EventDispatcher, SafetyResolver {
@NotNull
List<OnlineUser> getOnlineUsers();
/**
* 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
*/
default Optional<OnlineUser> getOnlineUser(@NotNull String playerName) {
return getOnlineUserExact(playerName)
.or(() -> getOnlineUsers().stream()
.filter(user -> user.getUsername().toLowerCase().startsWith(playerName.toLowerCase()))
.findFirst());
}
/**
* Finds a local {@link OnlineUser} by their name.
*
* @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
*/
default Optional<OnlineUser> getOnlineUserExact(@NotNull String playerName) {
return getOnlineUsers().stream()
.filter(user -> user.getUsername().equalsIgnoreCase(playerName))
.findFirst();
}
@NotNull
Set<SavedUser> getSavedUsers();
@@ -111,22 +136,6 @@ public interface HuskHomes extends TaskRunner, EventDispatcher, SafetyResolver {
log(Level.INFO, "Successfully initialized " + name);
}
/**
* 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> findOnlinePlayer(@NotNull String playerName) {
return getOnlineUsers().stream()
.filter(user -> user.getUsername().equalsIgnoreCase(playerName))
.findFirst()
.or(() -> getOnlineUsers().stream()
.filter(user -> user.getUsername().toLowerCase().startsWith(playerName.toLowerCase()))
.findFirst());
}
/**
* The plugin {@link Settings} loaded from file
*