From 80381799071e310fddc62c55f704203f4d641b84 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sun, 29 Jan 2023 11:18:13 -0800 Subject: [PATCH] properly handle username changes when the user has no previous changes --- .../hangar/service/internal/auth/SSOService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/io/papermc/hangar/service/internal/auth/SSOService.java b/backend/src/main/java/io/papermc/hangar/service/internal/auth/SSOService.java index 1eed8492c..02d798e83 100644 --- a/backend/src/main/java/io/papermc/hangar/service/internal/auth/SSOService.java +++ b/backend/src/main/java/io/papermc/hangar/service/internal/auth/SSOService.java @@ -168,10 +168,12 @@ public class SSOService { } // check that last change was long ago final List userNameHistory = this.userDAO.getUserNameHistory(user.getUuid()); - userNameHistory.sort(Comparator.comparing(UserNameChange::date).reversed()); - final OffsetDateTime nextChange = userNameHistory.get(0).date().plus(this.hangarConfig.user.nameChangeInterval(), ChronoUnit.DAYS); - if (!userNameHistory.isEmpty() && nextChange.isAfter(OffsetDateTime.now())) { - throw WebHookException.of("You can't change your name that soon! You have to wait till " + nextChange.format(DateTimeFormatter.RFC_1123_DATE_TIME)); + if (!userNameHistory.isEmpty()) { + userNameHistory.sort(Comparator.comparing(UserNameChange::date).reversed()); + final OffsetDateTime nextChange = userNameHistory.get(0).date().plus(this.hangarConfig.user.nameChangeInterval(), ChronoUnit.DAYS); + if (nextChange.isAfter(OffsetDateTime.now())) { + throw WebHookException.of("You can't change your name that soon! You have to wait till " + nextChange.format(DateTimeFormatter.RFC_1123_DATE_TIME)); + } } // record the change into the db this.userDAO.recordNameChange(user.getUuid(), user.getName(), newName);