Custom date time format support for /<admin> info <player> (#1783)

Fixes #1720
This commit is contained in:
Justin 2021-07-06 13:33:10 -07:00 committed by GitHub
parent 7de6563ece
commit f88b8d4d6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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()));

View File

@ -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:"