2020-07-15 04:23:26 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
|
|
|
|
import java.time.Instant;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
2020-08-15 06:44:57 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.staff.ActivityLogEntry;
|
2020-07-15 04:23:26 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2020-08-15 06:44:57 +00:00
|
|
|
@CommandPermissions(level = Rank.TRIAL_MOD, source = SourceType.ONLY_IN_GAME)
|
2020-07-15 04:23:26 +00:00
|
|
|
@CommandParameters(description = "Gets your playtime statistics.", usage = "/<command>")
|
|
|
|
public class Command_playtime extends FreedomCommand
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
|
|
|
|
{
|
|
|
|
ActivityLogEntry entry = plugin.acl.getActivityLog(playerSender);
|
|
|
|
int seconds = entry.getTotalSecondsPlayed();
|
|
|
|
int minutes = 0;
|
|
|
|
int hours = 0;
|
|
|
|
while (seconds >= 60)
|
|
|
|
{
|
|
|
|
seconds -= 60;
|
|
|
|
minutes += 1;
|
|
|
|
}
|
|
|
|
while (minutes >= 60)
|
|
|
|
{
|
|
|
|
minutes -= 60;
|
|
|
|
hours += 1;
|
|
|
|
}
|
|
|
|
if (entry.getTimestamps().size() == 0)
|
|
|
|
{
|
|
|
|
entry.addLogin();
|
|
|
|
}
|
|
|
|
String lastLoginString = entry.getTimestamps().get(entry.getTimestamps().size() - 1);
|
|
|
|
Date currentTime = Date.from(Instant.now());
|
|
|
|
lastLoginString = lastLoginString.replace("Login: ", "");
|
|
|
|
Date lastLogin = FUtil.stringToDate(lastLoginString);
|
|
|
|
|
|
|
|
long duration = currentTime.getTime() - lastLogin.getTime();
|
|
|
|
long cseconds = duration / 1000 % 60;
|
|
|
|
long cminutes = duration / (60 * 1000) % 60;
|
|
|
|
long chours = duration / (60 * 60 * 1000);
|
|
|
|
StringBuilder sb = new StringBuilder()
|
|
|
|
.append("Playtime - " + sender.getName() + "\n")
|
|
|
|
.append("Current Session: " + chours + " hours, " + cminutes + " minutes, and " + cseconds + " seconds" + "\n")
|
|
|
|
.append("Overall: " + hours + " hours, " + minutes + " minutes, and " + seconds + " seconds" + "\n");
|
|
|
|
List<String> durations = entry.getDurations();
|
|
|
|
if (durations.size() >= 3)
|
|
|
|
{
|
|
|
|
sb.append("Recent Sessions:");
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
sb.append("\n" + " - " + durations.get((durations.size() - 1) - i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msg(sb.toString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|