Various fixes for log commands

This commit is contained in:
Luck 2017-12-17 21:20:22 +00:00
parent cb47f9f94b
commit 765f140121
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
10 changed files with 50 additions and 17 deletions

View File

@ -130,7 +130,7 @@ public class ExtendedLogEntry implements LogEntry {
return acted.toString(); return acted.toString();
} }
} }
return String.valueOf(actorName); return String.valueOf(actedName);
} }
@Override @Override

View File

@ -50,7 +50,7 @@ public class Log {
throw new IllegalArgumentException("pageNo cannot be less than 1: " + pageNo); throw new IllegalArgumentException("pageNo cannot be less than 1: " + pageNo);
} }
int minimumEntries = ((pageNo * 5) - entries) + 1; int minimumEntries = ((pageNo * entries) - entries) + 1;
if (set.size() < minimumEntries) { if (set.size() < minimumEntries) {
throw new IllegalStateException("Log does not contain that many entries. " + throw new IllegalStateException("Log does not contain that many entries. " +
"Requested: " + minimumEntries + ", Log Count: " + set.size()); "Requested: " + minimumEntries + ", Log Count: " + set.size());
@ -73,8 +73,8 @@ public class Log {
return out; return out;
} }
private static int getMaxPages(long size, int entries) { private static int getMaxPages(int size, int entries) {
return (int) Math.ceil((double) size / entries); return (int) Math.ceil((double) size / (double) entries);
} }
@Getter @Getter
@ -109,7 +109,7 @@ public class Log {
public int getRecentMaxPages(UUID actor, int entriesPerPage) { public int getRecentMaxPages(UUID actor, int entriesPerPage) {
return getMaxPages(content.stream() return getMaxPages(content.stream()
.filter(e -> e.getActor().equals(actor)) .filter(e -> e.getActor().equals(actor))
.count(), entriesPerPage); .mapToInt(x -> 1).sum(), entriesPerPage);
} }
public SortedSet<ExtendedLogEntry> getUserHistory(UUID uuid) { public SortedSet<ExtendedLogEntry> getUserHistory(UUID uuid) {
@ -129,7 +129,7 @@ public class Log {
.filter(e -> e.getType() == LogEntry.Type.USER) .filter(e -> e.getType() == LogEntry.Type.USER)
.filter(e -> e.getActed().isPresent()) .filter(e -> e.getActed().isPresent())
.filter(e -> e.getActed().get().equals(uuid)) .filter(e -> e.getActed().get().equals(uuid))
.count(), entriesPerPage); .mapToInt(x -> 1).sum(), entriesPerPage);
} }
public SortedSet<ExtendedLogEntry> getGroupHistory(String name) { public SortedSet<ExtendedLogEntry> getGroupHistory(String name) {
@ -147,7 +147,7 @@ public class Log {
return getMaxPages(content.stream() return getMaxPages(content.stream()
.filter(e -> e.getType() == LogEntry.Type.GROUP) .filter(e -> e.getType() == LogEntry.Type.GROUP)
.filter(e -> e.getActedName().equals(name)) .filter(e -> e.getActedName().equals(name))
.count(), entriesPerPage); .mapToInt(x -> 1).sum(), entriesPerPage);
} }
public SortedSet<ExtendedLogEntry> getTrackHistory(String name) { public SortedSet<ExtendedLogEntry> getTrackHistory(String name) {
@ -165,7 +165,7 @@ public class Log {
return getMaxPages(content.stream() return getMaxPages(content.stream()
.filter(e -> e.getType() == LogEntry.Type.TRACK) .filter(e -> e.getType() == LogEntry.Type.TRACK)
.filter(e -> e.getActedName().equals(name)) .filter(e -> e.getActedName().equals(name))
.count(), entriesPerPage); .mapToInt(x -> 1).sum(), entriesPerPage);
} }
public SortedSet<ExtendedLogEntry> getSearch(String query) { public SortedSet<ExtendedLogEntry> getSearch(String query) {
@ -181,7 +181,7 @@ public class Log {
public int getSearchMaxPages(String query, int entriesPerPage) { public int getSearchMaxPages(String query, int entriesPerPage) {
return getMaxPages(content.stream() return getMaxPages(content.stream()
.filter(e -> e.matchesSearch(query)) .filter(e -> e.matchesSearch(query))
.count(), entriesPerPage); .mapToInt(x -> 1).sum(), entriesPerPage);
} }
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")

View File

@ -95,7 +95,7 @@ public class LogGroupHistory extends SubCommand<Log> {
long time = e.getValue().getTimestamp(); long time = e.getValue().getTimestamp();
Message.LOG_ENTRY.send(sender, Message.LOG_ENTRY.send(sender,
e.getKey(), e.getKey(),
DateUtil.formatTimeShort(now - time), DateUtil.formatTimeBrief(now - time),
e.getValue().getActorFriendlyString(), e.getValue().getActorFriendlyString(),
Character.toString(e.getValue().getType().getCode()), Character.toString(e.getValue().getType().getCode()),
e.getValue().getActedFriendlyString(), e.getValue().getActedFriendlyString(),

View File

@ -145,7 +145,7 @@ public class LogRecent extends SubCommand<Log> {
long time = e.getValue().getTimestamp(); long time = e.getValue().getTimestamp();
Message.LOG_ENTRY.send(sender, Message.LOG_ENTRY.send(sender,
e.getKey(), e.getKey(),
DateUtil.formatTimeShort(now - time), DateUtil.formatTimeBrief(now - time),
e.getValue().getActorFriendlyString(), e.getValue().getActorFriendlyString(),
Character.toString(e.getValue().getType().getCode()), Character.toString(e.getValue().getType().getCode()),
e.getValue().getActedFriendlyString(), e.getValue().getActedFriendlyString(),

View File

@ -87,7 +87,7 @@ public class LogSearch extends SubCommand<Log> {
long time = e.getValue().getTimestamp(); long time = e.getValue().getTimestamp();
Message.LOG_ENTRY.send(sender, Message.LOG_ENTRY.send(sender,
e.getKey(), e.getKey(),
DateUtil.formatTimeShort(now - time), DateUtil.formatTimeBrief(now - time),
e.getValue().getActorFriendlyString(), e.getValue().getActorFriendlyString(),
Character.toString(e.getValue().getType().getCode()), Character.toString(e.getValue().getType().getCode()),
e.getValue().getActedFriendlyString(), e.getValue().getActedFriendlyString(),

View File

@ -95,7 +95,7 @@ public class LogTrackHistory extends SubCommand<Log> {
long time = e.getValue().getTimestamp(); long time = e.getValue().getTimestamp();
Message.LOG_ENTRY.send(sender, Message.LOG_ENTRY.send(sender,
e.getKey(), e.getKey(),
DateUtil.formatTimeShort(now - time), DateUtil.formatTimeBrief(now - time),
e.getValue().getActorFriendlyString(), e.getValue().getActorFriendlyString(),
Character.toString(e.getValue().getType().getCode()), Character.toString(e.getValue().getType().getCode()),
e.getValue().getActedFriendlyString(), e.getValue().getActedFriendlyString(),

View File

@ -125,7 +125,7 @@ public class LogUserHistory extends SubCommand<Log> {
long time = e.getValue().getTimestamp(); long time = e.getValue().getTimestamp();
Message.LOG_ENTRY.send(sender, Message.LOG_ENTRY.send(sender,
e.getKey(), e.getKey(),
DateUtil.formatTimeShort(now - time), DateUtil.formatTimeBrief(now - time),
e.getValue().getActorFriendlyString(), e.getValue().getActorFriendlyString(),
Character.toString(e.getValue().getType().getCode()), Character.toString(e.getValue().getType().getCode()),
e.getValue().getActedFriendlyString(), e.getValue().getActedFriendlyString(),

View File

@ -72,7 +72,7 @@ public class InfoCommand extends SingleCommand {
plugin.getContextManager().getStaticContextString().orElse("None"), plugin.getContextManager().getStaticContextString().orElse("None"),
plugin.getPlayerCount(), plugin.getPlayerCount(),
plugin.getUniqueConnections().size(), plugin.getUniqueConnections().size(),
DateUtil.formatTimeShort((System.currentTimeMillis() - plugin.getStartTime()) / 1000L), DateUtil.formatTimeBrief((System.currentTimeMillis() - plugin.getStartTime()) / 1000L),
plugin.getUserManager().getAll().size(), plugin.getUserManager().getAll().size(),
plugin.getGroupManager().getAll().size(), plugin.getGroupManager().getAll().size(),
plugin.getTrackManager().getAll().size(), plugin.getTrackManager().getAll().size(),

View File

@ -62,7 +62,11 @@ public enum Message {
LOG_INFO("&7&l[&bL&3P&7&l] &3{}", false), LOG_INFO("&7&l[&bL&3P&7&l] &3{}", false),
LOG_WARN("&7&l[&bLuck&3Perms&7&l] &c[WARN] {}", false), LOG_WARN("&7&l[&bLuck&3Perms&7&l] &c[WARN] {}", false),
LOG_ERROR("&7&l[&bLuck&3Perms&7&l] &4[ERROR] {}", false), LOG_ERROR("&7&l[&bLuck&3Perms&7&l] &4[ERROR] {}", false),
LOG("&3LOG &3&l> &8(&e{}&8) [&a{}&8] (&b{}&8)&f: {}", true), LOG(
"{PREFIX}&3LOG &3&l> &8(&e{}&8) [&a{}&8] (&b{}&8)" + "\n" +
"{PREFIX}&3LOG &3&l> &f{}",
false
),
VERBOSE_LOG("&3VB &3&l> {}", true), VERBOSE_LOG("&3VB &3&l> {}", true),
EXPORT_LOG("&3EXPORT &3&l> &f{}", true), EXPORT_LOG("&3EXPORT &3&l> &f{}", true),
EXPORT_LOG_PROGRESS("&3EXPORT &3&l> &7{}", true), EXPORT_LOG_PROGRESS("&3EXPORT &3&l> &7{}", true),
@ -390,7 +394,7 @@ public enum Message {
LOG_ENTRY( LOG_ENTRY(
"{PREFIX}&b#{} &8(&7{} ago&8) &8(&e{}&8) [&a{}&8] (&b{}&8)" + "\n" + "{PREFIX}&b#{} &8(&7{} ago&8) &8(&e{}&8) [&a{}&8] (&b{}&8)" + "\n" +
"{PERFIX}&7> &f{}", "{PREFIX}&7> &f{}",
false false
), ),

View File

@ -199,6 +199,35 @@ public class DateUtil {
return time.toString().trim(); return time.toString().trim();
} }
public static String formatTimeBrief(long seconds) {
if (seconds <= 0) {
return "0s";
}
long minute = seconds / 60;
seconds = seconds % 60;
long hour = minute / 60;
minute = minute % 60;
long day = hour / 24;
hour = hour % 24;
StringBuilder time = new StringBuilder();
if (day != 0) {
time.append(day).append("d ");
time.append(hour).append("h ");
} else if (hour != 0) {
time.append(hour).append("h ");
time.append(minute).append("m ");
} else if (minute != 0) {
time.append(minute).append("m ");
time.append(seconds).append("s");
} else if (seconds != 0) {
time.append(seconds).append("s");
}
return time.toString().trim();
}
private static String formatDateDiff(Calendar fromDate, Calendar toDate) { private static String formatDateDiff(Calendar fromDate, Calendar toDate) {
boolean future = false; boolean future = false;
if (toDate.equals(fromDate)) { if (toDate.equals(fromDate)) {