Merge pull request 'Add LastOnline to WhoisCommand' (#90) from VelocityCore/LastOnlineTime into main

Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/90
Reviewed-by: Lixfel <lixfel@steamwar.de>
This commit is contained in:
2024-12-26 22:23:01 +01:00
4 changed files with 17 additions and 3 deletions
@@ -73,6 +73,7 @@ public class SteamwarUser {
private static final Statement getPlaytime = new Statement("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?");
private static final Statement getFirstjoin = new Statement("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?");
private static final Statement getLastonline = new Statement("SELECT MAX(EndTime) AS LastOnline FROM Session WHERE UserID = ?");
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
@@ -276,6 +277,14 @@ public class SteamwarUser {
}, id);
}
public Timestamp getLastOnline() {
return getLastonline.select(rs -> {
if (rs.next())
return rs.getTimestamp("LastOnline");
return null;
}, id);
}
public void punish(Punishment.PunishmentType punishment, Timestamp time, String banReason, int from, boolean perma) {
initPunishments();
punishments.remove(punishment);
@@ -626,6 +626,7 @@ WHOIS_ID=§7ID§8: §e{0}
WHOIS_PERMS=§7Perms§8: §7{0}
WHOIS_DISCORD_ID=§7Discord-ID§8: §e{0}
WHOIS_JOINED_FIRST=§7Joined on§8: §e{0}
WHOIS_LAST_ONLINE=§7Last on§8: §e{0}
WHOIS_HOURS_PLAYED=§7Online Time§8: §e{0}h
WHOIS_CURRENT_PLAYED=§7Current Online Time§8: §e{0}m
WHOIS_CURRENT_SERVER=§7Current Server§8: §e{0}
@@ -602,6 +602,7 @@ WHOIS_UUID_HOVER=§eUUID Kopieren
WHOIS_ID=§7ID§8: §e{0}
WHOIS_DISCORD_ID=§7Discord-ID§8: §e{0}
WHOIS_JOINED_FIRST=§7Beigetreten am§8: §e{0}
WHOIS_LAST_ONLINE=§7Zuletzt online§8: §e{0}
WHOIS_HOURS_PLAYED=§7Spielzeit§8: §e{0}h
WHOIS_CURRENT_PLAYED=§7Aktuell online§8: §e{0}m
WHOIS_CURRENT_SERVER=§7Aktueller Server§8: §e{0}
@@ -20,15 +20,15 @@
package de.steamwar.velocitycore.commands;
import com.velocitypowered.api.proxy.Player;
import de.steamwar.persistent.Storage;
import de.steamwar.velocitycore.VelocityCore;
import de.steamwar.velocitycore.mods.ModUtils;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.messages.Chatter;
import de.steamwar.messages.Message;
import de.steamwar.persistent.Storage;
import de.steamwar.sql.*;
import de.steamwar.velocitycore.VelocityCore;
import de.steamwar.velocitycore.mods.ModUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.kyori.adventure.text.event.ClickEvent;
@@ -86,9 +86,12 @@ public class WhoisCommand extends SWCommand {
if(firstJoin == null && target != null) {
firstJoin = Storage.sessions.get(target);
}
Timestamp lastOnline = user.getLastOnline();
if(firstJoin != null)
sender.system("WHOIS_JOINED_FIRST", firstJoin.toString());
if (lastOnline != null)
sender.system("WHOIS_LAST_ONLINE", lastOnline.toString());
sender.system("WHOIS_HOURS_PLAYED", new DecimalFormat("###.##").format(onlineTime / 3600d));
if(target != null) {