Archived
0

Updated /seen to work with 1.13 statistics.

Also, Reverted /seen message structural change
This commit is contained in:
Minenash
2018-11-12 14:36:12 -05:00
parent 779aa95bc5
commit 99264ae65f

View File

@@ -2,6 +2,7 @@ package com.redstoner.modules.seen;
import java.io.File; import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
@@ -59,7 +60,7 @@ public class Seen implements Module, Listener
@Command(hook = "seen2", async = AsyncType.ALWAYS) @Command(hook = "seen2", async = AsyncType.ALWAYS)
public boolean seen(CommandSender sender, String player, boolean show_ips) public boolean seen(CommandSender sender, String player, boolean show_ips)
{ {
Message m = new Message(sender, null); ArrayList<String> message = new ArrayList<>();
OfflinePlayer p; OfflinePlayer p;
if (Utils.isUUID(player)) if (Utils.isUUID(player))
p = Bukkit.getOfflinePlayer(UUID.fromString(player)); p = Bukkit.getOfflinePlayer(UUID.fromString(player));
@@ -92,22 +93,22 @@ public class Seen implements Module, Listener
timestamp = (long) DataManager.getOrDefault(p.getUniqueId().toString(), "lastquit", p.getLastPlayed()); timestamp = (long) DataManager.getOrDefault(p.getUniqueId().toString(), "lastquit", p.getLastPlayed());
} }
String time = DateUtil.formatDateDiff(timestamp); String time = DateUtil.formatDateDiff(timestamp);
m.appendText("&e" + p.getName() + " &7has been " + state + " &7for &e" + time + "&7."); message.add("&e" + p.getName() + " &7has been " + state + " &7for &e" + time + "&7.");
JSONArray _names; JSONArray _names;
if (online) if (online)
{ {
if (DataManager.getState((Player) p, "afk")) if (DataManager.getState((Player) p, "afk"))
{ {
m.appendText("\nThey're currently &eAFK&7:"); message.add("They're currently &eAFK&7:");
String reason = (String) DataManager.getOrDefault(p.getUniqueId().toString(), "AFK", "afk_reason", ""); String reason = (String) DataManager.getOrDefault(p.getUniqueId().toString(), "AFK", "afk_reason", "");
Long timeAFK = (Long) DataManager.getOrDefault(p.getUniqueId().toString(), "AFK", "afk_time", 0L); Long timeAFK = (Long) DataManager.getOrDefault(p.getUniqueId().toString(), "AFK", "afk_time", 0L);
m.appendText("\n &7Duration: &e" + DateUtil.formatDateDiff(timeAFK)); message.add(" &7Duration: &e" + DateUtil.formatDateDiff(timeAFK));
if (reason.length() >= 1) if (reason.length() >= 1)
m.appendText("\n &7Reason: &e" + reason); message.add(" &7Reason: &e" + reason);
} }
if (DataManager.getState((Player) p, "vanished")) if (DataManager.getState((Player) p, "vanished"))
m.appendText("\nThey're currently &evanished&7!"); message.add("They're currently &evanished&7!");
_names = names.get(p.getUniqueId()); _names = names.get(p.getUniqueId());
} }
else else
@@ -115,7 +116,7 @@ public class Seen implements Module, Listener
_names = loadNames(p.getUniqueId()); _names = loadNames(p.getUniqueId());
} }
if (_names != null && _names.size() > 1) if (_names != null && _names.size() > 1)
m.appendText("\nThey've also been known as: &e" message.add("They've also been known as: &e"
+ _names.toJSONString().replaceAll("[\"\\[\\]]", "").replace(",", "&7, &e")); + _names.toJSONString().replaceAll("[\"\\[\\]]", "").replace(",", "&7, &e"));
if (sender.hasPermission("utils.seen.ip")) if (sender.hasPermission("utils.seen.ip"))
{ {
@@ -127,13 +128,12 @@ public class Seen implements Module, Listener
else else
_ips = loadIPs(p.getUniqueId()); _ips = loadIPs(p.getUniqueId());
if (_ips != null && _ips.size() > 0) if (_ips != null && _ips.size() > 0)
m.appendText("\nThey've joined with the following IPs: &e" message.add("They've joined with the following IPs: &e"
+ _ips.toJSONString().replaceAll("[\"\\[\\]]", "").replace(",", "&7, &e")); + _ips.toJSONString().replaceAll("[\"\\[\\]]", "").replace(",", "&7, &e"));
} }
m.appendText("\n" + message.add("Their current IP is: &a" + DataManager.getOrDefault(p.getUniqueId().toString(), "ip", "unknown"));
"Their current IP is: &a" + DataManager.getOrDefault(p.getUniqueId().toString(), "ip", "unknown"));
} }
m.send(); getLogger().message(sender, message.toArray(new String[] {}));
return true; return true;
} }
@@ -258,30 +258,27 @@ public class Seen implements Module, Listener
return true; return true;
} }
int ticks_lived = player.getStatistic(Statistic.PLAY_ONE_TICK); int ticks_lived = player.getStatistic(Statistic.PLAY_ONE_MINUTE);
int days = ticks_lived / 1728000; int days = ticks_lived / 1728000;
int hours = (ticks_lived % 1728000) / 72000; int hours = (ticks_lived % 1728000) / 72000;
int minutes = (ticks_lived % 72000) / 1200; int minutes = (ticks_lived % 72000) / 1200;
int seconds = ticks_lived % 1200;
if (sender.getName().equals(name)) if (sender.getName().equals(name))
{ {
getLogger().message(sender, "You have played for &b" getLogger().message(sender, "You have played for a total of: &e"
+ (days == 0 && hours == 0 && minutes == 0 ? seconds + (days == 0 && hours == 0 && minutes == 0 ? "< 1m"
: ("a total of: &e" : (days != 0 ? days + "d " : "")
+ (days != 0 ? days + "d " : "") + (hours != 0 || days != 0 ? hours + "h " : "")
+ (hours != 0 || days != 0 ? hours + "h " : "") + (minutes != 0 || hours != 0 || days != 0 ? minutes + "m" : ""))
+ (minutes != 0 || hours != 0 || days != 0 ? minutes + "m" : "")))
+ "&7."); + "&7.");
} }
else else
{ {
getLogger().message(sender, "&3" + Utils.getName(player) + " &7has played for " getLogger().message(sender, "&3" + Utils.getName(player) + " &7has played for a total of: &e"
+ (days == 0 && hours == 0 && minutes == 0 ? seconds + (days == 0 && hours == 0 && minutes == 0 ? "< 1m"
: ("a total of: &e" : (days != 0 ? days + "d " : "")
+ (days != 0 ? days + "d " : "") + (hours != 0 || days != 0 ? hours + "h " : "")
+ (hours != 0 || days != 0 ? hours + "h " : "") + (minutes != 0 || hours != 0 || days != 0 ? minutes + "m" : ""))
+ (minutes != 0 || hours != 0 || days != 0 ? minutes + "m" : "")))
+ "&7."); + "&7.");
} }
return true; return true;