From 08c8393abcd0d73ff55277883e9a54ff89a08e05 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 01:50:46 +0100 Subject: [PATCH] Fix ArrayIndexOutOfBounds when a newly added admin leaves the game --- .../totalfreedommod/admin/ActivityLogEntry.java | 9 +++++++-- .../me/totalfreedom/totalfreedommod/admin/AdminList.java | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java index eb056fcb..037f8548 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java @@ -66,8 +66,13 @@ public class ActivityLogEntry implements IConfig public void addLogin() { - Date currentTime = Date.from(Instant.now()); - timestamps.add("Login: " + FUtil.dateToString(currentTime)); + this.addLogin(System.currentTimeMillis()); + } + + public void addLogin(final long timestamp) + { + Date time = Date.from(Instant.ofEpochMilli(timestamp)); + timestamps.add("Login: " + FUtil.dateToString(time)); } public void addLogout() diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java index 84ec6d15..23715310 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java @@ -194,6 +194,15 @@ public class AdminList extends FreedomService // Save admin plugin.sql.addAdmin(admin); + // Add login time + UUID uuid = admin.getUuid(); + Player player = Bukkit.getPlayer(uuid); + + if (player != null) + { + plugin.acl.getActivityLog(player).addLogin(player.getLastLogin()); + } + return true; }