From 8fb21c5fb4039282d13356081926b98eb098b9c4 Mon Sep 17 00:00:00 2001 From: Drc-DEV <33911680+Drc-DEV@users.noreply.github.com> Date: Fri, 24 Jan 2020 23:09:28 +0100 Subject: [PATCH] Add method to get the registration date to the API (#1993) * Add method to get the registration date to the API * Removed unnecessary check * Add method to get the registration IP to the API --- .../fr/xephi/authme/api/v3/AuthMeApi.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java b/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java index 7dcf137c..93204275 100644 --- a/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java +++ b/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java @@ -132,6 +132,23 @@ public class AuthMeApi { return null; } + /** + * Get the registration ip address of a player. + * + * @param playerName The name of the player to process + * @return The registration ip address of the player + */ + public String getRegistrationIp(String playerName) { + PlayerAuth auth = playerCache.getAuth(playerName); + if (auth == null) { + auth = dataSource.getAuth(playerName); + } + if (auth != null) { + return auth.getRegistrationIp(); + } + return null; + } + /** * Get the last ip address of a player. * @@ -196,6 +213,29 @@ public class AuthMeApi { return null; } + /** + * Get the registration (AuthMe) timestamp of a player. + * + * @param playerName The name of the player to process + * + * @return The timestamp of when the player was registered, or null if the player doesn't exist or is not registered + */ + public Instant getRegistrationTime(String playerName) { + Long registrationDate = getRegistrationMillis(playerName); + return registrationDate == null ? null : Instant.ofEpochMilli(registrationDate); + } + + private Long getRegistrationMillis(String playerName) { + PlayerAuth auth = playerCache.getAuth(playerName); + if (auth == null) { + auth = dataSource.getAuth(playerName); + } + if (auth != null) { + return auth.getRegistrationDate(); + } + return null; + } + /** * Return whether the player is registered. *