Add Whois show Playtime #126
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
Lixfel
hat
Nope, das machst du schön alles per SQL, wir müssen doch hier nicht hunderte an Datensätzen runterladen! Nope, das machst du schön alles per SQL, wir müssen doch hier nicht hunderte an Datensätzen runterladen!
Lixfel
hat
Nutze dazu SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ? Nutze dazu SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?
|
||||
}
|
||||
return (int) (mili / 1000);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Bitte einen normalen String-Formatter oder vgl.bares nutzen und nix selbstgebasteltes. Notfalls halt immer in Spielstunden angeben.