diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 56760a1e..2b3854b8 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 72dad550..5bd83d6a 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"); @@ -38,19 +40,32 @@ 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()); + 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()); BungeeCore.send(player, "§7Team§8: §e" + team.getTeamName()); diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index cb260031..43d23981 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -233,4 +233,25 @@ public class SteamwarUser { throw new SecurityException(e); } } + + public double getOnlinetime() { + ResultSet set = SQL.select("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?", id); + try { + set.next(); + return set.getBigDecimal("Playtime").doubleValue(); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + 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"); + } + } }