From f88b8d4d6dc99495f434c090b1b144b416265483 Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 6 Jul 2021 13:33:10 -0700 Subject: [PATCH] Custom date time format support for / info (#1783) Fixes #1720 --- .../bentobox/bentobox/database/objects/Island.java | 10 +++++++++- src/main/resources/locales/en-US.yml | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/bentobox/database/objects/Island.java b/src/main/java/world/bentobox/bentobox/database/objects/Island.java index 57554ada4..40927e278 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/Island.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/Island.java @@ -1,6 +1,7 @@ package world.bentobox.bentobox.database.objects; import java.io.IOException; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.EnumMap; import java.util.HashMap; @@ -1075,7 +1076,14 @@ public class Island implements DataObject, MetaDataAble { // Fixes #getLastPlayed() returning 0 when it is the owner's first connection. long lastPlayed = (Bukkit.getServer().getOfflinePlayer(getOwner()).getLastPlayed() != 0) ? Bukkit.getServer().getOfflinePlayer(getOwner()).getLastPlayed() : Bukkit.getServer().getOfflinePlayer(getOwner()).getFirstPlayed(); - user.sendMessage("commands.admin.info.last-login","[date]", new Date(lastPlayed).toString()); + String formattedDate; + try { + String dateTimeFormat = plugin.getLocalesManager().get("commands.admin.info.last-login-date-time-format"); + formattedDate = new SimpleDateFormat(dateTimeFormat).format(new Date(lastPlayed)); + } catch (NullPointerException | IllegalArgumentException ignored) { + formattedDate = new Date(lastPlayed).toString(); + } + user.sendMessage("commands.admin.info.last-login","[date]", formattedDate); user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(getWorld(), getOwner()))); String resets = String.valueOf(plugin.getPlayers().getResets(getWorld(), getOwner())); diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 10578d84e..ed207d26d 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -188,6 +188,7 @@ commands: island-uuid: "UUID: [uuid]" owner: "Owner: [owner] ([uuid])" last-login: "Last login: [date]" + last-login-date-time-format: "EEE MMM dd HH:mm:ss zzz yyyy" deaths: "Deaths: [number]" resets-left: "Resets: [number] (Max: [total])" team-members-title: "Team members:"