From e3340453649b75583790074ef43c4b3ccb15f8f1 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 10 Oct 2020 15:43:09 +0200 Subject: [PATCH 1/4] Add Whois show Playtime --- src/de/steamwar/bungeecore/BungeeCore.java | 2 +- .../bungeecore/commands/WhoisCommand.java | 52 +++++++++++++++++++ .../steamwar/bungeecore/sql/SteamwarUser.java | 13 +++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 56760a1..2b3854b 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -214,7 +214,7 @@ public class BungeeCore extends Plugin { return; } config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); - }catch(IOException e){ + }catch(Exception e){ log("Could not save/load config.yml", e); ProxyServer.getInstance().stop(); return; diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 72dad55..11d93bf 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -51,6 +51,7 @@ public class WhoisCommand extends BasicCommand { BungeeCore.send(player, "§7Username§8: §e" + user.getUserName()); BungeeCore.send(player, "§7UUID§8: §e" + user.getUuid().toString(), "", new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, user.getUuid().toString())); BungeeCore.send(player, "§7ID§8: §e" + user.getId()); + BungeeCore.send(player, "§7Online Time§8: §e" + parseTime(user.getOnlinetime())); Team team = Team.get(user.getTeam()); BungeeCore.send(player, "§7Team§8: §e" + team.getTeamName()); @@ -62,4 +63,55 @@ public class WhoisCommand extends BasicCommand { player.sendMessage(user.muteMessage()); } } + + public static String parseTime(int seconds) { + if (seconds < 60) { + return seconds + "s"; + } + int minutes = seconds / 60; + int s = 60 * minutes; + int secondsLeft = seconds - s; + if (minutes < 60) { + if (secondsLeft > 0) { + return String.valueOf(minutes + "m" + " " + secondsLeft + "s"); + } + return String.valueOf(minutes + "m"); + } + if (minutes < 1440) { + String time = ""; + int hours = minutes / 60; + time = hours + "h"; + int inMins = 60 * hours; + int leftOver = minutes - inMins; + if (leftOver >= 1) { + time = time + " " + leftOver + "m"; + } + if (secondsLeft > 0) { + time = time + " " + secondsLeft + "s"; + } + return time; + } + String time = ""; + int days = minutes / 1440; + time = days + "d"; + int inMins = 1440 * days; + int leftOver = minutes - inMins; + if (leftOver >= 1) { + if (leftOver < 60) { + time = time + " " + leftOver + "m"; + } else { + int hours = leftOver / 60; + time = time + " " + hours + "h"; + int hoursInMins = 60 * hours; + int minsLeft = leftOver - hoursInMins; + if (leftOver >= 1) { + time = time + " " + minsLeft + "m"; + } + } + } + if (secondsLeft > 0) { + time = time + " " + secondsLeft + "s"; + } + return time; + } } diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index cb26003..dc68f52 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -233,4 +233,17 @@ public class SteamwarUser { throw new SecurityException(e); } } + + public int getOnlinetime() { + ResultSet set = SQL.select("SELECT StartTime, EndTime FROM Session WHERE UserID = ?", id); + long mili = 0; + try { + while (set.next()) { + mili += (set.getTimestamp("EndTime").getTime() - set.getTimestamp("StartTime").getTime()); + } + }catch (SQLException e){ + e.printStackTrace(); + } + return (int) (mili / 1000); + } } -- 2.39.5 From de1243870ac6d4b78dc9dbe06998a2f0d3edd578 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 10 Oct 2020 23:49:12 +0200 Subject: [PATCH 2/4] Changed SQL Statement --- .../bungeecore/commands/WhoisCommand.java | 55 +------------------ .../steamwar/bungeecore/sql/SteamwarUser.java | 16 +++--- 2 files changed, 10 insertions(+), 61 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 11d93bf..75a4e87 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -26,6 +26,8 @@ import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.text.DecimalFormat; + public class WhoisCommand extends BasicCommand { public WhoisCommand(){ super("whois", "bungeecore.teamchat"); @@ -51,7 +53,7 @@ public class WhoisCommand extends BasicCommand { BungeeCore.send(player, "§7Username§8: §e" + user.getUserName()); BungeeCore.send(player, "§7UUID§8: §e" + user.getUuid().toString(), "", new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, user.getUuid().toString())); BungeeCore.send(player, "§7ID§8: §e" + user.getId()); - BungeeCore.send(player, "§7Online Time§8: §e" + parseTime(user.getOnlinetime())); + BungeeCore.send(player, "§7Online Time§8: §e" + new DecimalFormat("###.##").format(user.getOnlinetime() / (double) 3600) + "h"); Team team = Team.get(user.getTeam()); BungeeCore.send(player, "§7Team§8: §e" + team.getTeamName()); @@ -63,55 +65,4 @@ public class WhoisCommand extends BasicCommand { player.sendMessage(user.muteMessage()); } } - - public static String parseTime(int seconds) { - if (seconds < 60) { - return seconds + "s"; - } - int minutes = seconds / 60; - int s = 60 * minutes; - int secondsLeft = seconds - s; - if (minutes < 60) { - if (secondsLeft > 0) { - return String.valueOf(minutes + "m" + " " + secondsLeft + "s"); - } - return String.valueOf(minutes + "m"); - } - if (minutes < 1440) { - String time = ""; - int hours = minutes / 60; - time = hours + "h"; - int inMins = 60 * hours; - int leftOver = minutes - inMins; - if (leftOver >= 1) { - time = time + " " + leftOver + "m"; - } - if (secondsLeft > 0) { - time = time + " " + secondsLeft + "s"; - } - return time; - } - String time = ""; - int days = minutes / 1440; - time = days + "d"; - int inMins = 1440 * days; - int leftOver = minutes - inMins; - if (leftOver >= 1) { - if (leftOver < 60) { - time = time + " " + leftOver + "m"; - } else { - int hours = leftOver / 60; - time = time + " " + hours + "h"; - int hoursInMins = 60 * hours; - int minsLeft = leftOver - hoursInMins; - if (leftOver >= 1) { - time = time + " " + minsLeft + "m"; - } - } - } - if (secondsLeft > 0) { - time = time + " " + secondsLeft + "s"; - } - return time; - } } diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index dc68f52..86bc27c 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -234,16 +234,14 @@ public class SteamwarUser { } } - public int getOnlinetime() { - ResultSet set = SQL.select("SELECT StartTime, EndTime FROM Session WHERE UserID = ?", id); - long mili = 0; + public double getOnlinetime() { + ResultSet set = SQL.select("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?", id); try { - while (set.next()) { - mili += (set.getTimestamp("EndTime").getTime() - set.getTimestamp("StartTime").getTime()); - } - }catch (SQLException e){ - e.printStackTrace(); + set.next(); + return set.getBigDecimal("Playtime").doubleValue(); + } catch (SQLException throwables) { + throwables.printStackTrace(); } - return (int) (mili / 1000); + return 0; } } -- 2.39.5 From a19e5db5e66f39270ff96d48b2470317645f2f41 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 10 Oct 2020 23:58:34 +0200 Subject: [PATCH 3/4] Added Support for UserID --- .../bungeecore/commands/WhoisCommand.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 75a4e87..c3b6f8d 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -40,16 +40,27 @@ public class WhoisCommand extends BasicCommand { ProxiedPlayer player = (ProxiedPlayer) sender; if(args.length == 0){ - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§c/whois [Spieler]"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§c/whois [Spieler/ID]"); return; } SteamwarUser user = SteamwarUser.get(args[0]); if(user == null){ - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spieler."); + try { + int id = Integer.parseInt(args[0]); + user = SteamwarUser.get(id); + }catch (NumberFormatException ignored) {} + } + + if(user == null) { + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spieler!"); return; } + sendUserinfo(player, user); + } + + private static void sendUserinfo(ProxiedPlayer player, SteamwarUser user) { BungeeCore.send(player, "§7Username§8: §e" + user.getUserName()); BungeeCore.send(player, "§7UUID§8: §e" + user.getUuid().toString(), "", new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, user.getUuid().toString())); BungeeCore.send(player, "§7ID§8: §e" + user.getId()); -- 2.39.5 From eb9c7df29d59a2b23897e574272069ceaab3407e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 11 Oct 2020 13:37:40 +0200 Subject: [PATCH 4/4] Add First Join --- src/de/steamwar/bungeecore/commands/WhoisCommand.java | 1 + src/de/steamwar/bungeecore/sql/SteamwarUser.java | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index c3b6f8d..5bd83d6 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -64,6 +64,7 @@ public class WhoisCommand extends BasicCommand { BungeeCore.send(player, "§7Username§8: §e" + user.getUserName()); BungeeCore.send(player, "§7UUID§8: §e" + user.getUuid().toString(), "", new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, user.getUuid().toString())); BungeeCore.send(player, "§7ID§8: §e" + user.getId()); + BungeeCore.send(player, "§7Beigetreten am§8: §e" + user.getFirstjoin().toString()); BungeeCore.send(player, "§7Online Time§8: §e" + new DecimalFormat("###.##").format(user.getOnlinetime() / (double) 3600) + "h"); Team team = Team.get(user.getTeam()); diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 86bc27c..43d2398 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -244,4 +244,14 @@ public class SteamwarUser { } return 0; } + + public Timestamp getFirstjoin() { + ResultSet set = SQL.select("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?", id); + try { + set.next(); + return set.getTimestamp("FirstJoin"); + } catch (SQLException throwables) { + throw new SecurityException("Could not load First Join"); + } + } } -- 2.39.5