randomized gradients and /playtime

This commit is contained in:
Super_ 2020-07-15 00:23:26 -04:00
parent 067180d2cf
commit 114567a302
6 changed files with 128 additions and 6 deletions

View File

@ -119,6 +119,19 @@ public class ActivityLogEntry implements IConfig
ips.clear();
}
public int getTotalSecondsPlayed()
{
int result = 0;
for (String duration : durations)
{
String[] spl = duration.split(" ");
result += Integer.parseInt(spl[0]) * 60 * 60;
result += Integer.parseInt(spl[2]) * 60;
result += Integer.parseInt(spl[5]);
}
return result;
}
@Override
public boolean isValid()
{

View File

@ -45,10 +45,25 @@ public class Command_nickgradient extends FreedomCommand
}
}
String from = "", to = "";
java.awt.Color awt1, awt2;
try
{
if (args[0].equalsIgnoreCase("random") ||
args[0].equalsIgnoreCase("r"))
{
awt1 = FUtil.getRandomAWTColor();
from = " (From: " + FUtil.getHexStringOfAWTColor(awt1) + ")";
}
else
awt1 = java.awt.Color.decode(args[0]);
if (args[1].equalsIgnoreCase("random") ||
args[1].equalsIgnoreCase("r"))
{
awt2 = FUtil.getRandomAWTColor();
to = " (To: " + FUtil.getHexStringOfAWTColor(awt2) + ")";
}
else
awt2 = java.awt.Color.decode(args[1]);
}
catch (NumberFormatException ex)
@ -69,7 +84,7 @@ public class Command_nickgradient extends FreedomCommand
plugin.esb.setNickname(sender.getName(), outputNick);
msg("Your nickname is now: " + outputNick);
msg("Your nickname is now: '" + outputNick + ChatColor.GRAY + "'" + from + to);
return true;
}

View File

@ -0,0 +1,63 @@
package me.totalfreedom.totalfreedommod.command;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import me.totalfreedom.totalfreedommod.admin.ActivityLogEntry;
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;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
@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;
}
}

View File

@ -183,10 +183,25 @@ public class Command_tag extends FreedomCommand
}
else if (args[0].equalsIgnoreCase("gradient"))
{
String from = "", to = "";
java.awt.Color awt1, awt2;
try
{
if (args[1].equalsIgnoreCase("random") ||
args[1].equalsIgnoreCase("r"))
{
awt1 = FUtil.getRandomAWTColor();
from = " (From: " + FUtil.getHexStringOfAWTColor(awt1) + ")";
}
else
awt1 = java.awt.Color.decode(args[1]);
if (args[2].equalsIgnoreCase("random") ||
args[2].equalsIgnoreCase("r"))
{
awt2 = FUtil.getRandomAWTColor();
to = " (To: " + FUtil.getHexStringOfAWTColor(awt2) + ")";
}
else
awt2 = java.awt.Color.decode(args[2]);
}
catch (NumberFormatException ex)
@ -233,7 +248,7 @@ public class Command_tag extends FreedomCommand
{
save(playerSender, tag);
}
msg("Tag set to '" + outputTag + ChatColor.GRAY + "'." + (save ? " (Saved)" : ""));
msg("Tag set to '" + outputTag + ChatColor.GRAY + "'." + (save ? " (Saved)" : "") + from + to);
return true;
}

View File

@ -7,6 +7,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;

View File

@ -779,6 +779,21 @@ public class FUtil
return new java.awt.Color(color.getRed(), color.getGreen(), color.getBlue());
}
public static java.awt.Color getRandomAWTColor()
{
return new java.awt.Color(randomInteger(0, 255), randomInteger(0, 255), randomInteger(0, 255));
}
public static String getHexStringOfAWTColor(java.awt.Color color)
{
String hex = Integer.toHexString(color.getRGB() & 0xFFFFFF);
if (hex.length() < 6)
{
hex = "0" + hex;
}
return "#" + hex;
}
public static void createExplosionOnDelay(Location location, float power, int delay)
{
new BukkitRunnable()