Refactor April 1st date check in ChatListener

Removed the more complex date logic used to check for April 1st in the ChatListener class. This check checked if it was April 1st in any timezone. Replaced it with a simpler check using LocalDate's methods for month and day comparison. This only checks if it's April 1st in UTC. This aims to enhance code readability and simplify date handling.
This commit is contained in:
Teriuihi 2024-03-31 10:56:21 +02:00
parent ab98222f06
commit a7e029b0a1

View File

@ -60,14 +60,6 @@ public class ChatListener implements Listener {
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
}
ZonedDateTime aprilFirstUTCMidnight = ZonedDateTime.of(LocalDate.now().getYear(), 4, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
ZonedDateTime aprilFirstStart = aprilFirstUTCMidnight.minusHours(24);
ZonedDateTime aprilFirstEnd = aprilFirstUTCMidnight.plusHours(24);
private boolean isWithinApril1st() {
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
return now.isAfter(aprilFirstStart) && now.isBefore(aprilFirstEnd);
}
private final Component mention = MiniMessage.miniMessage().deserialize(Config.MENTIONPLAYERTAG);
@EventHandler(ignoreCancelled = true)
public void onPlayerChat(AsyncChatEvent event) {
@ -116,7 +108,8 @@ public class ChatListener implements Listener {
Set<Player> playersToPing = new HashSet<>();
pingPlayers(playersToPing, modifiableString, player);
if (isWithinApril1st()) {
LocalDate now = LocalDate.now();
if (now.getMonth().equals(Month.APRIL) && now.getDayOfMonth() == 1) {
if (modifiableString.string().startsWith(Config.APRIL_FOOLS_RESET + " ")) {
modifiableString.removeStringAtStart(Config.APRIL_FOOLS_RESET + " ");
} else {