mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 14:38:53 +00:00
fix: get exact OnlineUser if name matches globally, close #700
This commit is contained in:
2 files changed
+8
-3
No files matched your search
@@ -146,7 +146,10 @@ public class RequestsManager {
|
||||
final long expiry = Instant.now().getEpochSecond()
|
||||
+ plugin.getSettings().getGeneral().getTeleportRequestExpiryTime();
|
||||
final TeleportRequest request = new TeleportRequest(requester, type, expiry);
|
||||
final Optional<OnlineUser> localTarget = plugin.getOnlineUser(targetUser);
|
||||
|
||||
// Lookup the user locally first. If there's a username match globally, perform an exact local check
|
||||
final Optional<OnlineUser> localTarget = plugin.isUserOnlineGlobally(targetUser)
|
||||
? plugin.getOnlineUserExact(targetUser) : plugin.getOnlineUser(targetUser);
|
||||
if (localTarget.isPresent()) {
|
||||
if (localTarget.get().equals(requester)) {
|
||||
throw new IllegalArgumentException("Cannot send a teleport request to yourself");
|
||||
|
||||
@@ -68,8 +68,10 @@ public interface UserProvider {
|
||||
getGlobalUserList().put(server, players);
|
||||
}
|
||||
|
||||
default boolean isUserOnline(@NotNull User user) {
|
||||
return getOnlineUserMap().containsKey(user.getUuid());
|
||||
default boolean isUserOnlineGlobally(@NotNull String playerName) {
|
||||
return getUserList().stream()
|
||||
.map(u -> u.getName().toLowerCase(Locale.ENGLISH))
|
||||
.anyMatch(u -> u.equals(playerName.toLowerCase(Locale.ENGLISH)));
|
||||
}
|
||||
|
||||
default Optional<OnlineUser> getOnlineUser(@NotNull String playerName) {
|
||||
|
||||
Reference in new issue
Block a user