From 41459ad404cd269e9928759a32866e1633263dc9 Mon Sep 17 00:00:00 2001 From: Taah Date: Tue, 19 Apr 2022 14:45:35 -0700 Subject: [PATCH] update to use zoned date time --- .../java/dev/plex/request/impl/AdminsEndpoint.java | 11 ++++++----- .../dev/plex/request/impl/PunishmentsEndpoint.java | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/dev/plex/request/impl/AdminsEndpoint.java b/src/main/java/dev/plex/request/impl/AdminsEndpoint.java index 5f8b111..492c056 100644 --- a/src/main/java/dev/plex/request/impl/AdminsEndpoint.java +++ b/src/main/java/dev/plex/request/impl/AdminsEndpoint.java @@ -10,9 +10,10 @@ import dev.plex.rank.enums.Rank; import dev.plex.request.AbstractServlet; import dev.plex.request.GetMapping; import dev.plex.util.PlexLog; -import dev.plex.util.adapter.LocalDateTimeSerializer; +import dev.plex.util.adapter.ZonedDateTimeSerializer; import jakarta.servlet.http.HttpServletRequest; import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.util.stream.Collectors; import jakarta.servlet.http.HttpServletResponse; @@ -35,7 +36,7 @@ public class AdminsEndpoint extends AbstractServlet if (player == null) { // This likely means they've never joined the server before. That's okay. We can just not return IPs. - return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers().stream().peek(plexPlayer -> plexPlayer.setIps(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setPunishments(Lists.newArrayList())).collect(Collectors.toList())); + return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers().stream().peek(plexPlayer -> plexPlayer.setIps(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setPunishments(Lists.newArrayList())).collect(Collectors.toList())); } if (Plex.get().getSystem().equalsIgnoreCase("ranks")) { @@ -43,7 +44,7 @@ public class AdminsEndpoint extends AbstractServlet if (!player.getRankFromString().isAtLeast(Rank.ADMIN)) { // Don't return IPs either if the person is not an Admin or above. - return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers().stream().peek(plexPlayer -> plexPlayer.setIps(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setPunishments(Lists.newArrayList())).collect(Collectors.toList())); + return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers().stream().peek(plexPlayer -> plexPlayer.setIps(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setPunishments(Lists.newArrayList())).collect(Collectors.toList())); } } else if (Plex.get().getSystem().equalsIgnoreCase("permissions")) @@ -53,10 +54,10 @@ public class AdminsEndpoint extends AbstractServlet if (!HTTPDModule.getPermissions().playerHas(null, offlinePlayer, "plex.httpd.admins.access")) { // If the person doesn't have permission, don't return IPs - return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers().stream().peek(plexPlayer -> plexPlayer.setIps(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setPunishments(Lists.newArrayList())).collect(Collectors.toList())); + return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers().stream().peek(plexPlayer -> plexPlayer.setIps(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setPunishments(Lists.newArrayList())).collect(Collectors.toList())); } } - return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers()); + return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers()); } private String adminsHTML(String message) diff --git a/src/main/java/dev/plex/request/impl/PunishmentsEndpoint.java b/src/main/java/dev/plex/request/impl/PunishmentsEndpoint.java index 243163e..3d168d7 100644 --- a/src/main/java/dev/plex/request/impl/PunishmentsEndpoint.java +++ b/src/main/java/dev/plex/request/impl/PunishmentsEndpoint.java @@ -9,9 +9,10 @@ import dev.plex.rank.enums.Rank; import dev.plex.request.AbstractServlet; import dev.plex.request.GetMapping; import dev.plex.util.PlexLog; -import dev.plex.util.adapter.LocalDateTimeSerializer; +import dev.plex.util.adapter.ZonedDateTimeSerializer; import jakarta.servlet.http.HttpServletRequest; import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.util.UUID; import jakarta.servlet.http.HttpServletResponse; @@ -58,7 +59,7 @@ public class PunishmentsEndpoint extends AbstractServlet if (player == null) { // If the player is null, give it to them without the IPs - return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList()); + return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList()); } if (Plex.get().getSystem().equalsIgnoreCase("ranks")) { @@ -66,7 +67,7 @@ public class PunishmentsEndpoint extends AbstractServlet if (!player.getRankFromString().isAtLeast(Rank.ADMIN)) { // Don't return IPs either if the person is not an Admin or above. - return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList()); + return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList()); } } else if (Plex.get().getSystem().equalsIgnoreCase("permissions")) @@ -76,10 +77,10 @@ public class PunishmentsEndpoint extends AbstractServlet if (!HTTPDModule.getPermissions().playerHas(null, offlinePlayer, "plex.httpd.punishments.access")) { // If the person doesn't have permission, don't return IPs - return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList()); + return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList()); } } - return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().toList()); + return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().toList()); } private String punishmentsHTML(String message)