diff --git a/build.gradle b/build.gradle index d34cad5..d671b8c 100644 --- a/build.gradle +++ b/build.gradle @@ -50,7 +50,6 @@ dependencies { implementation 'org.yaml:snakeyaml:2.0' implementation 'org.luaj:luaj-jse:3.0.1' implementation 'net.dv8tion:JDA:5.0.0-beta.12' - implementation 'joda-time:joda-time:2.12.4' implementation 'net.kyori:adventure-text-serializer-legacy:4.15.0' implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.20.0' implementation 'io.socket:socket.io-client:2.1.0' diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/MailCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/MailCommand.java index 2d2f274..6be6939 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/MailCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/MailCommand.java @@ -16,14 +16,15 @@ import me.chayapak1.chomens_bot.util.PersistentDataUtilities; import me.chayapak1.chomens_bot.util.UUIDUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; -import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; import java.time.Instant; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -174,8 +175,12 @@ public class MailCommand extends Command { if (!mail.sentTo.equals(sender.profile.getName())) continue; - final DateTimeFormatter formatter = DateTimeFormat.forPattern("MMMM d, YYYY, hh:mm:ss a Z"); - final String formattedTime = formatter.print(mail.timeSent); + final Instant instant = Instant.ofEpochMilli(mail.timeSent); + final ZoneId zoneId = ZoneId.systemDefault(); + final OffsetDateTime localDateTime = OffsetDateTime.ofInstant(instant, zoneId); + + final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d, yyyy, hh:mm:ss a Z"); + final String formattedTime = localDateTime.format(formatter); mailsComponent.add( Component.translatable( diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/SeenCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/SeenCommand.java index 257733e..fad77a1 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/SeenCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/SeenCommand.java @@ -12,11 +12,9 @@ import me.chayapak1.chomens_bot.util.ColorUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.format.NamedTextColor; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; +import java.time.*; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; @@ -70,10 +68,12 @@ public class SeenCommand extends Command { if (time == null) throw new CommandException(Component.text("This player does not have the `lastSeen.time` entry in the database for some reason.")); - final DateTime dateTime = new DateTime(time.getAsLong(), DateTimeZone.UTC); + final Instant instant = Instant.ofEpochMilli(time.getAsLong()); + final ZoneId zoneId = ZoneId.of("UTC"); // should i be doing this? + final OffsetDateTime localDateTime = OffsetDateTime.ofInstant(instant, zoneId); - final DateTimeFormatter formatter = DateTimeFormat.forPattern("EEEE, MMMM d, YYYY, hh:mm:ss a z"); - final String formattedTime = formatter.print(dateTime); + final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE, MMMM d, yyyy, hh:mm:ss a Z"); + final String formattedTime = localDateTime.format(formatter); final String server = lastSeen.get("server").getAsString(); diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/TimeCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/TimeCommand.java index 3b58c3c..8bfd391 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/TimeCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/TimeCommand.java @@ -8,10 +8,11 @@ import me.chayapak1.chomens_bot.command.TrustLevel; import me.chayapak1.chomens_bot.util.ColorUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; + +import java.time.DateTimeException; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; public class TimeCommand extends Command { public TimeCommand () { @@ -27,26 +28,24 @@ public class TimeCommand extends Command { @Override public Component execute(CommandContext context) throws CommandException { - final Bot bot = context.bot; - - final String timezone = context.getString(true, true); - - DateTimeZone zone; try { - zone = DateTimeZone.forID(timezone); - } catch (IllegalArgumentException ignored) { + final Bot bot = context.bot; + + final String timezone = context.getString(true, true); + + final ZoneId zoneId = ZoneId.of(timezone); + final ZonedDateTime zonedDateTime = ZonedDateTime.now(zoneId); + + final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE, MMMM d, yyyy, hh:mm:ss a"); + final String formattedTime = zonedDateTime.format(formatter); + + return Component.translatable( + "The current time for %s is: %s", + Component.text(timezone).color(ColorUtilities.getColorByString(bot.config.colorPalette.string)), + Component.text(formattedTime).color(NamedTextColor.GREEN) + ).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)); + } catch (DateTimeException e) { throw new CommandException(Component.text("Invalid timezone (case-sensitive)")); } - - final DateTime dateTime = new DateTime(zone); - - final DateTimeFormatter formatter = DateTimeFormat.forPattern("EEEE, MMMM d, YYYY, hh:mm:ss a"); - final String formattedTime = formatter.print(dateTime); - - return Component.translatable( - "The current time for %s is: %s", - Component.text(timezone).color(ColorUtilities.getColorByString(bot.config.colorPalette.string)), - Component.text(formattedTime).color(NamedTextColor.GREEN) - ).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)); } } diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/WeatherCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/WeatherCommand.java index 110bd96..94ab52d 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/WeatherCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/WeatherCommand.java @@ -11,14 +11,13 @@ import me.chayapak1.chomens_bot.util.ColorUtilities; import me.chayapak1.chomens_bot.util.HttpUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; public class WeatherCommand extends Command { public WeatherCommand () { @@ -53,13 +52,11 @@ public class WeatherCommand extends Command { final JsonObject jsonObject = gson.fromJson(jsonOutput, JsonObject.class); - final DateTimeFormatter formatter = DateTimeFormat.forPattern("hh:mm:ss a"); + final ZoneId zoneId = ZoneId.of(jsonObject.get("location").getAsJsonObject().get("tz_id").getAsString()); + final ZonedDateTime zonedDateTime = ZonedDateTime.now(zoneId); - final DateTimeZone zone = DateTimeZone.forID(jsonObject.get("location").getAsJsonObject().get("tz_id").getAsString()); - - final DateTime dateTime = new DateTime(zone); - - final String time = formatter.print(dateTime); + final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm:ss a"); + final String time = zonedDateTime.format(formatter); return Component.translatable( "Weather forecast for %s, %s:\n%s (%s), feels like %s (%s)\nTime: %s", diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/TrustedPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/TrustedPlugin.java index 3ea0ff6..16e1a90 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/TrustedPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/TrustedPlugin.java @@ -5,10 +5,9 @@ import me.chayapak1.chomens_bot.data.PlayerEntry; import me.chayapak1.chomens_bot.util.ColorUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import org.joda.time.DateTime; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; import java.util.UUID; @@ -64,10 +63,10 @@ public class TrustedPlugin extends PlayersPlugin.Listener { Component.text(target.profile.getName()).color(ColorUtilities.getColorByString(bot.config.colorPalette.username)) ).color(NamedTextColor.GREEN); } else { - final DateTime now = DateTime.now(); + final LocalDateTime now = LocalDateTime.now(); - final DateTimeFormatter formatter = DateTimeFormat.forPattern("hh:mm:ss a"); - final String formattedTime = formatter.print(now); + final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm:ss a"); + final String formattedTime = now.format(formatter); component = Component.translatable( """