Change log output format, refactor log pagination

This commit is contained in:
Luck 2017-12-17 17:47:10 +00:00
parent d0fb9f6aee
commit cb47f9f94b
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
11 changed files with 158 additions and 95 deletions

View File

@ -54,6 +54,10 @@
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
</exclusion> </exclusion>
<exclusion>
<groupId>net.kyori</groupId>
<artifactId>blizzard</artifactId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<!-- configurate --> <!-- configurate -->

View File

@ -30,6 +30,7 @@ import lombok.AllArgsConstructor;
import lombok.ToString; import lombok.ToString;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
@ -60,8 +61,6 @@ import java.util.stream.Collectors;
@AllArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor(access = AccessLevel.PRIVATE)
public class ExtendedLogEntry implements LogEntry { public class ExtendedLogEntry implements LogEntry {
private static final String FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s";
private static final Comparator<LogEntry> COMPARATOR = Comparator private static final Comparator<LogEntry> COMPARATOR = Comparator
.comparingLong(LogEntry::getTimestamp) .comparingLong(LogEntry::getTimestamp)
.thenComparing(LogEntry::getActor) .thenComparing(LogEntry::getActor)
@ -103,6 +102,13 @@ public class ExtendedLogEntry implements LogEntry {
return actorName; return actorName;
} }
public String getActorFriendlyString() {
if (Strings.isNullOrEmpty(actorName) || actorName.equals("null")) {
return actor.toString();
}
return actorName;
}
@Override @Override
public Type getType() { public Type getType() {
return type; return type;
@ -118,6 +124,15 @@ public class ExtendedLogEntry implements LogEntry {
return actedName; return actedName;
} }
public String getActedFriendlyString() {
if (Strings.isNullOrEmpty(actedName) || actedName.equals("null")) {
if (acted != null) {
return acted.toString();
}
}
return String.valueOf(actorName);
}
@Override @Override
public String getAction() { public String getAction() {
return action; return action;
@ -136,15 +151,6 @@ public class ExtendedLogEntry implements LogEntry {
action.toLowerCase().contains(query); action.toLowerCase().contains(query);
} }
public String getFormatted() {
return String.format(FORMAT,
String.valueOf(actorName).equals("null") ? actor.toString() : actorName,
Character.toString(type.getCode()),
String.valueOf(actedName).equals("null") && acted != null ? acted.toString() : actedName,
action
);
}
public void submit(LuckPermsPlugin plugin, Sender sender) { public void submit(LuckPermsPlugin plugin, Sender sender) {
plugin.getLogDispatcher().dispatch(this, sender); plugin.getLogDispatcher().dispatch(this, sender);
} }

View File

@ -40,7 +40,6 @@ import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Log { public class Log {
private static final int PAGE_ENTRIES = 5;
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
@ -74,10 +73,6 @@ public class Log {
return out; return out;
} }
private static int getMaxPages(int size, int entries) {
return (int) Math.ceil((double) size / entries);
}
private static int getMaxPages(long size, int entries) { private static int getMaxPages(long size, int entries) {
return (int) Math.ceil((double) size / entries); return (int) Math.ceil((double) size / entries);
} }
@ -93,12 +88,12 @@ public class Log {
return content; return content;
} }
public SortedMap<Integer, ExtendedLogEntry> getRecent(int pageNo) { public SortedMap<Integer, ExtendedLogEntry> getRecent(int pageNo, int entriesPerPage) {
return getPage(content, pageNo, PAGE_ENTRIES); return getPage(content, pageNo, entriesPerPage);
} }
public int getRecentMaxPages() { public int getRecentMaxPages(int entriesPerPage) {
return getMaxPages(content.size(), PAGE_ENTRIES); return getMaxPages(content.size(), entriesPerPage);
} }
public SortedSet<ExtendedLogEntry> getRecent(UUID actor) { public SortedSet<ExtendedLogEntry> getRecent(UUID actor) {
@ -107,14 +102,14 @@ public class Log {
.collect(Collectors.toCollection(TreeSet::new)); .collect(Collectors.toCollection(TreeSet::new));
} }
public SortedMap<Integer, ExtendedLogEntry> getRecent(int pageNo, UUID actor) { public SortedMap<Integer, ExtendedLogEntry> getRecent(int pageNo, UUID actor, int entriesPerPage) {
return getPage(getRecent(actor), pageNo, PAGE_ENTRIES); return getPage(getRecent(actor), pageNo, entriesPerPage);
} }
public int getRecentMaxPages(UUID actor) { 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(), PAGE_ENTRIES); .count(), entriesPerPage);
} }
public SortedSet<ExtendedLogEntry> getUserHistory(UUID uuid) { public SortedSet<ExtendedLogEntry> getUserHistory(UUID uuid) {
@ -125,16 +120,16 @@ public class Log {
.collect(Collectors.toCollection(TreeSet::new)); .collect(Collectors.toCollection(TreeSet::new));
} }
public SortedMap<Integer, ExtendedLogEntry> getUserHistory(int pageNo, UUID uuid) { public SortedMap<Integer, ExtendedLogEntry> getUserHistory(int pageNo, UUID uuid, int entriesPerPage) {
return getPage(getUserHistory(uuid), pageNo, PAGE_ENTRIES); return getPage(getUserHistory(uuid), pageNo, entriesPerPage);
} }
public int getUserHistoryMaxPages(UUID uuid) { public int getUserHistoryMaxPages(UUID uuid, int entriesPerPage) {
return getMaxPages(content.stream() return getMaxPages(content.stream()
.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(), PAGE_ENTRIES); .count(), entriesPerPage);
} }
public SortedSet<ExtendedLogEntry> getGroupHistory(String name) { public SortedSet<ExtendedLogEntry> getGroupHistory(String name) {
@ -144,15 +139,15 @@ public class Log {
.collect(Collectors.toCollection(TreeSet::new)); .collect(Collectors.toCollection(TreeSet::new));
} }
public SortedMap<Integer, ExtendedLogEntry> getGroupHistory(int pageNo, String name) { public SortedMap<Integer, ExtendedLogEntry> getGroupHistory(int pageNo, String name, int entriesPerPage) {
return getPage(getGroupHistory(name), pageNo, PAGE_ENTRIES); return getPage(getGroupHistory(name), pageNo, entriesPerPage);
} }
public int getGroupHistoryMaxPages(String name) { public int getGroupHistoryMaxPages(String name, int entriesPerPage) {
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(), PAGE_ENTRIES); .count(), entriesPerPage);
} }
public SortedSet<ExtendedLogEntry> getTrackHistory(String name) { public SortedSet<ExtendedLogEntry> getTrackHistory(String name) {
@ -162,15 +157,15 @@ public class Log {
.collect(Collectors.toCollection(TreeSet::new)); .collect(Collectors.toCollection(TreeSet::new));
} }
public SortedMap<Integer, ExtendedLogEntry> getTrackHistory(int pageNo, String name) { public SortedMap<Integer, ExtendedLogEntry> getTrackHistory(int pageNo, String name, int entriesPerPage) {
return getPage(getTrackHistory(name), pageNo, PAGE_ENTRIES); return getPage(getTrackHistory(name), pageNo, entriesPerPage);
} }
public int getTrackHistoryMaxPages(String name) { public int getTrackHistoryMaxPages(String name, int entriesPerPage) {
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(), PAGE_ENTRIES); .count(), entriesPerPage);
} }
public SortedSet<ExtendedLogEntry> getSearch(String query) { public SortedSet<ExtendedLogEntry> getSearch(String query) {
@ -179,14 +174,14 @@ public class Log {
.collect(Collectors.toCollection(TreeSet::new)); .collect(Collectors.toCollection(TreeSet::new));
} }
public SortedMap<Integer, ExtendedLogEntry> getSearch(int pageNo, String query) { public SortedMap<Integer, ExtendedLogEntry> getSearch(int pageNo, String query, int entriesPerPage) {
return getPage(getSearch(query), pageNo, PAGE_ENTRIES); return getPage(getSearch(query), pageNo, entriesPerPage);
} }
public int getSearchMaxPages(String query) { 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(), PAGE_ENTRIES); .count(), entriesPerPage);
} }
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")

View File

@ -59,13 +59,16 @@ public class LogDispatcher {
} }
if (!plugin.getApiProvider().getEventFactory().handleLogBroadcast(!plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY), entry, LogBroadcastEvent.Origin.LOCAL)) { if (!plugin.getApiProvider().getEventFactory().handleLogBroadcast(!plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY), entry, LogBroadcastEvent.Origin.LOCAL)) {
final String msg = entry.getFormatted();
plugin.getOnlineSenders() plugin.getOnlineSenders()
.filter(CommandPermission.LOG_NOTIFY::isAuthorized) .filter(CommandPermission.LOG_NOTIFY::isAuthorized)
.filter(s -> !LogNotify.isIgnoring(plugin, s.getUuid())) .filter(s -> !LogNotify.isIgnoring(plugin, s.getUuid()))
.filter(s -> !s.getUuid().equals(sender.getUuid())) .filter(s -> !s.getUuid().equals(sender.getUuid()))
.forEach(s -> Message.LOG.send(s, msg)); .forEach(s -> Message.LOG.send(s,
entry.getActorFriendlyString(),
Character.toString(entry.getType().getCode()),
entry.getActedFriendlyString(),
entry.getAction()
));
} }
} }
@ -75,12 +78,15 @@ public class LogDispatcher {
} }
if (!plugin.getApiProvider().getEventFactory().handleLogBroadcast(!plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY), entry, LogBroadcastEvent.Origin.REMOTE)) { if (!plugin.getApiProvider().getEventFactory().handleLogBroadcast(!plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY), entry, LogBroadcastEvent.Origin.REMOTE)) {
final String msg = entry.getFormatted();
plugin.getOnlineSenders() plugin.getOnlineSenders()
.filter(CommandPermission.LOG_NOTIFY::isAuthorized) .filter(CommandPermission.LOG_NOTIFY::isAuthorized)
.filter(s -> !LogNotify.isIgnoring(plugin, s.getUuid())) .filter(s -> !LogNotify.isIgnoring(plugin, s.getUuid()))
.forEach(s -> Message.LOG.send(s, msg)); .forEach(s -> Message.LOG.send(s,
entry.getActorFriendlyString(),
Character.toString(entry.getType().getCode()),
entry.getActedFriendlyString(),
entry.getAction()
));
} }
} }
} }

View File

@ -40,6 +40,7 @@ import static me.lucko.luckperms.common.api.ApiUtils.checkName;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@AllArgsConstructor @AllArgsConstructor
public class ApiLog implements Log { public class ApiLog implements Log {
private static final int ENTRIES_PER_PAGE = 5;
private final me.lucko.luckperms.common.actionlog.Log handle; private final me.lucko.luckperms.common.actionlog.Log handle;
@Override @Override
@ -54,12 +55,12 @@ public class ApiLog implements Log {
@Override @Override
public SortedMap<Integer, LogEntry> getRecent(int pageNo) { public SortedMap<Integer, LogEntry> getRecent(int pageNo) {
return (SortedMap) handle.getRecent(pageNo); return (SortedMap) handle.getRecent(pageNo, ENTRIES_PER_PAGE);
} }
@Override @Override
public int getRecentMaxPages() { public int getRecentMaxPages() {
return handle.getRecentMaxPages(); return handle.getRecentMaxPages(ENTRIES_PER_PAGE);
} }
@Override @Override
@ -69,12 +70,12 @@ public class ApiLog implements Log {
@Override @Override
public SortedMap<Integer, LogEntry> getRecent(int pageNo, @NonNull UUID actor) { public SortedMap<Integer, LogEntry> getRecent(int pageNo, @NonNull UUID actor) {
return (SortedMap) handle.getRecent(pageNo, actor); return (SortedMap) handle.getRecent(pageNo, actor, ENTRIES_PER_PAGE);
} }
@Override @Override
public int getRecentMaxPages(@NonNull UUID actor) { public int getRecentMaxPages(@NonNull UUID actor) {
return handle.getRecentMaxPages(actor); return handle.getRecentMaxPages(actor, ENTRIES_PER_PAGE);
} }
@Override @Override
@ -84,12 +85,12 @@ public class ApiLog implements Log {
@Override @Override
public SortedMap<Integer, LogEntry> getUserHistory(int pageNo, @NonNull UUID uuid) { public SortedMap<Integer, LogEntry> getUserHistory(int pageNo, @NonNull UUID uuid) {
return (SortedMap) handle.getUserHistory(pageNo, uuid); return (SortedMap) handle.getUserHistory(pageNo, uuid, ENTRIES_PER_PAGE);
} }
@Override @Override
public int getUserHistoryMaxPages(@NonNull UUID uuid) { public int getUserHistoryMaxPages(@NonNull UUID uuid) {
return handle.getUserHistoryMaxPages(uuid); return handle.getUserHistoryMaxPages(uuid, ENTRIES_PER_PAGE);
} }
@Override @Override
@ -99,12 +100,12 @@ public class ApiLog implements Log {
@Override @Override
public SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, @NonNull String name) { public SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, @NonNull String name) {
return (SortedMap) handle.getGroupHistory(pageNo, checkName(name)); return (SortedMap) handle.getGroupHistory(pageNo, checkName(name), ENTRIES_PER_PAGE);
} }
@Override @Override
public int getGroupHistoryMaxPages(@NonNull String name) { public int getGroupHistoryMaxPages(@NonNull String name) {
return handle.getGroupHistoryMaxPages(checkName(name)); return handle.getGroupHistoryMaxPages(checkName(name), ENTRIES_PER_PAGE);
} }
@Override @Override
@ -114,12 +115,12 @@ public class ApiLog implements Log {
@Override @Override
public SortedMap<Integer, LogEntry> getTrackHistory(int pageNo, @NonNull String name) { public SortedMap<Integer, LogEntry> getTrackHistory(int pageNo, @NonNull String name) {
return (SortedMap) handle.getTrackHistory(pageNo, checkName(name)); return (SortedMap) handle.getTrackHistory(pageNo, checkName(name), ENTRIES_PER_PAGE);
} }
@Override @Override
public int getTrackHistoryMaxPages(@NonNull String name) { public int getTrackHistoryMaxPages(@NonNull String name) {
return handle.getTrackHistoryMaxPages(checkName(name)); return handle.getTrackHistoryMaxPages(checkName(name), ENTRIES_PER_PAGE);
} }
@Override @Override
@ -129,11 +130,11 @@ public class ApiLog implements Log {
@Override @Override
public SortedMap<Integer, LogEntry> getSearch(int pageNo, @NonNull String query) { public SortedMap<Integer, LogEntry> getSearch(int pageNo, @NonNull String query) {
return (SortedMap) handle.getSearch(pageNo, query); return (SortedMap) handle.getSearch(pageNo, query, ENTRIES_PER_PAGE);
} }
@Override @Override
public int getSearchMaxPages(@NonNull String query) { public int getSearchMaxPages(@NonNull String query) {
return handle.getSearchMaxPages(query); return handle.getSearchMaxPages(query, ENTRIES_PER_PAGE);
} }
} }

View File

@ -45,6 +45,8 @@ import java.util.Map;
import java.util.SortedMap; import java.util.SortedMap;
public class LogGroupHistory extends SubCommand<Log> { public class LogGroupHistory extends SubCommand<Log> {
private static final int ENTRIES_PER_PAGE = 10;
public LogGroupHistory(LocaleManager locale) { public LogGroupHistory(LocaleManager locale) {
super(CommandSpec.LOG_GROUP_HISTORY.spec(locale), "grouphistory", CommandPermission.LOG_GROUP_HISTORY, Predicates.notInRange(1, 2)); super(CommandSpec.LOG_GROUP_HISTORY.spec(locale), "grouphistory", CommandPermission.LOG_GROUP_HISTORY, Predicates.notInRange(1, 2));
} }
@ -69,7 +71,7 @@ public class LogGroupHistory extends SubCommand<Log> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
int maxPage = log.getGroupHistoryMaxPages(group); int maxPage = log.getGroupHistoryMaxPages(group, ENTRIES_PER_PAGE);
if (maxPage == 0) { if (maxPage == 0) {
Message.LOG_NO_ENTRIES.send(sender); Message.LOG_NO_ENTRIES.send(sender);
return CommandResult.STATE_ERROR; return CommandResult.STATE_ERROR;
@ -84,14 +86,21 @@ public class LogGroupHistory extends SubCommand<Log> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
SortedMap<Integer, ExtendedLogEntry> entries = log.getGroupHistory(page, group); SortedMap<Integer, ExtendedLogEntry> entries = log.getGroupHistory(page, group, ENTRIES_PER_PAGE);
String name = entries.values().stream().findAny().get().getActedName(); String name = entries.values().stream().findAny().get().getActedName();
Message.LOG_HISTORY_GROUP_HEADER.send(sender, name, page, maxPage); Message.LOG_HISTORY_GROUP_HEADER.send(sender, name, page, maxPage);
long now = DateUtil.unixSecondsNow();
for (Map.Entry<Integer, ExtendedLogEntry> e : entries.entrySet()) { for (Map.Entry<Integer, ExtendedLogEntry> e : entries.entrySet()) {
long time = e.getValue().getTimestamp(); long time = e.getValue().getTimestamp();
long now = DateUtil.unixSecondsNow(); Message.LOG_ENTRY.send(sender,
Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatTimeShort(now - time), e.getValue().getFormatted()); e.getKey(),
DateUtil.formatTimeShort(now - time),
e.getValue().getActorFriendlyString(),
Character.toString(e.getValue().getType().getCode()),
e.getValue().getActedFriendlyString(),
e.getValue().getAction()
);
} }
return CommandResult.SUCCESS; return CommandResult.SUCCESS;

View File

@ -48,6 +48,8 @@ import java.util.SortedMap;
import java.util.UUID; import java.util.UUID;
public class LogRecent extends SubCommand<Log> { public class LogRecent extends SubCommand<Log> {
private static final int ENTRIES_PER_PAGE = 10;
public LogRecent(LocaleManager locale) { public LogRecent(LocaleManager locale) {
super(CommandSpec.LOG_RECENT.spec(locale), "recent", CommandPermission.LOG_RECENT, Predicates.notInRange(0, 2)); super(CommandSpec.LOG_RECENT.spec(locale), "recent", CommandPermission.LOG_RECENT, Predicates.notInRange(0, 2));
} }
@ -56,7 +58,7 @@ public class LogRecent extends SubCommand<Log> {
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) throws CommandException {
if (args.size() == 0) { if (args.size() == 0) {
// No page or user // No page or user
return showLog(log.getRecentMaxPages(), null, sender, log); return showLog(log.getRecentMaxPages(ENTRIES_PER_PAGE), null, sender, log);
} }
if (args.size() == 1) { if (args.size() == 1) {
@ -102,7 +104,7 @@ public class LogRecent extends SubCommand<Log> {
if (args.size() != 2) { if (args.size() != 2) {
// Just user // Just user
return showLog(log.getRecentMaxPages(uuid), uuid, sender, log); return showLog(log.getRecentMaxPages(uuid, ENTRIES_PER_PAGE), uuid, sender, log);
} else { } else {
try { try {
int p = Integer.parseInt(args.get(1)); int p = Integer.parseInt(args.get(1));
@ -116,7 +118,7 @@ public class LogRecent extends SubCommand<Log> {
} }
private static CommandResult showLog(int page, UUID filter, Sender sender, Log log) { private static CommandResult showLog(int page, UUID filter, Sender sender, Log log) {
int maxPage = (filter != null) ? log.getRecentMaxPages(filter) : log.getRecentMaxPages(); int maxPage = (filter != null) ? log.getRecentMaxPages(filter, ENTRIES_PER_PAGE) : log.getRecentMaxPages(ENTRIES_PER_PAGE);
if (maxPage == 0) { if (maxPage == 0) {
Message.LOG_NO_ENTRIES.send(sender); Message.LOG_NO_ENTRIES.send(sender);
return CommandResult.STATE_ERROR; return CommandResult.STATE_ERROR;
@ -127,18 +129,28 @@ public class LogRecent extends SubCommand<Log> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
SortedMap<Integer, ExtendedLogEntry> entries = (filter != null) ? log.getRecent(page, filter) : log.getRecent(page); SortedMap<Integer, ExtendedLogEntry> entries = (filter != null) ? log.getRecent(page, filter, ENTRIES_PER_PAGE) : log.getRecent(page, ENTRIES_PER_PAGE);
if (filter != null) { if (filter != null) {
String name = entries.values().stream().findAny().get().getActorName(); String name = entries.values().stream().findAny().get().getActorName();
if (name.contains("@")) {
name = name.split("@")[0];
}
Message.LOG_RECENT_BY_HEADER.send(sender, name, page, maxPage); Message.LOG_RECENT_BY_HEADER.send(sender, name, page, maxPage);
} else { } else {
Message.LOG_RECENT_HEADER.send(sender, page, maxPage); Message.LOG_RECENT_HEADER.send(sender, page, maxPage);
} }
long now = DateUtil.unixSecondsNow();
for (Map.Entry<Integer, ExtendedLogEntry> e : entries.entrySet()) { for (Map.Entry<Integer, ExtendedLogEntry> e : entries.entrySet()) {
long time = e.getValue().getTimestamp(); long time = e.getValue().getTimestamp();
long now = DateUtil.unixSecondsNow(); Message.LOG_ENTRY.send(sender,
Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatTimeShort(now - time), e.getValue().getFormatted()); e.getKey(),
DateUtil.formatTimeShort(now - time),
e.getValue().getActorFriendlyString(),
Character.toString(e.getValue().getType().getCode()),
e.getValue().getActedFriendlyString(),
e.getValue().getAction()
);
} }
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }

View File

@ -45,6 +45,8 @@ import java.util.SortedMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class LogSearch extends SubCommand<Log> { public class LogSearch extends SubCommand<Log> {
private static final int ENTRIES_PER_PAGE = 10;
public LogSearch(LocaleManager locale) { public LogSearch(LocaleManager locale) {
super(CommandSpec.LOG_SEARCH.spec(locale), "search", CommandPermission.LOG_SEARCH, Predicates.is(0)); super(CommandSpec.LOG_SEARCH.spec(locale), "search", CommandPermission.LOG_SEARCH, Predicates.is(0));
} }
@ -62,7 +64,7 @@ public class LogSearch extends SubCommand<Log> {
final String query = args.stream().collect(Collectors.joining(" ")); final String query = args.stream().collect(Collectors.joining(" "));
int maxPage = log.getSearchMaxPages(query); int maxPage = log.getSearchMaxPages(query, ENTRIES_PER_PAGE);
if (maxPage == 0) { if (maxPage == 0) {
Message.LOG_NO_ENTRIES.send(sender); Message.LOG_NO_ENTRIES.send(sender);
return CommandResult.STATE_ERROR; return CommandResult.STATE_ERROR;
@ -77,13 +79,20 @@ public class LogSearch extends SubCommand<Log> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
SortedMap<Integer, ExtendedLogEntry> entries = log.getSearch(page, query); SortedMap<Integer, ExtendedLogEntry> entries = log.getSearch(page, query, ENTRIES_PER_PAGE);
Message.LOG_SEARCH_HEADER.send(sender, query, page, maxPage); Message.LOG_SEARCH_HEADER.send(sender, query, page, maxPage);
long now = DateUtil.unixSecondsNow();
for (Map.Entry<Integer, ExtendedLogEntry> e : entries.entrySet()) { for (Map.Entry<Integer, ExtendedLogEntry> e : entries.entrySet()) {
long time = e.getValue().getTimestamp(); long time = e.getValue().getTimestamp();
long now = DateUtil.unixSecondsNow(); Message.LOG_ENTRY.send(sender,
Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatTimeShort(now - time), e.getValue().getFormatted()); e.getKey(),
DateUtil.formatTimeShort(now - time),
e.getValue().getActorFriendlyString(),
Character.toString(e.getValue().getType().getCode()),
e.getValue().getActedFriendlyString(),
e.getValue().getAction()
);
} }
return CommandResult.SUCCESS; return CommandResult.SUCCESS;

View File

@ -45,6 +45,8 @@ import java.util.Map;
import java.util.SortedMap; import java.util.SortedMap;
public class LogTrackHistory extends SubCommand<Log> { public class LogTrackHistory extends SubCommand<Log> {
private static final int ENTRIES_PER_PAGE = 10;
public LogTrackHistory(LocaleManager locale) { public LogTrackHistory(LocaleManager locale) {
super(CommandSpec.LOG_TRACK_HISTORY.spec(locale), "trackhistory", CommandPermission.LOG_TRACK_HISTORY, Predicates.notInRange(1, 2)); super(CommandSpec.LOG_TRACK_HISTORY.spec(locale), "trackhistory", CommandPermission.LOG_TRACK_HISTORY, Predicates.notInRange(1, 2));
} }
@ -69,7 +71,7 @@ public class LogTrackHistory extends SubCommand<Log> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
int maxPage = log.getTrackHistoryMaxPages(track); int maxPage = log.getTrackHistoryMaxPages(track, ENTRIES_PER_PAGE);
if (maxPage == 0) { if (maxPage == 0) {
Message.LOG_NO_ENTRIES.send(sender); Message.LOG_NO_ENTRIES.send(sender);
return CommandResult.STATE_ERROR; return CommandResult.STATE_ERROR;
@ -84,14 +86,21 @@ public class LogTrackHistory extends SubCommand<Log> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
SortedMap<Integer, ExtendedLogEntry> entries = log.getTrackHistory(page, track); SortedMap<Integer, ExtendedLogEntry> entries = log.getTrackHistory(page, track, ENTRIES_PER_PAGE);
String name = entries.values().stream().findAny().get().getActedName(); String name = entries.values().stream().findAny().get().getActedName();
Message.LOG_HISTORY_TRACK_HEADER.send(sender, name, page, maxPage); Message.LOG_HISTORY_TRACK_HEADER.send(sender, name, page, maxPage);
long now = DateUtil.unixSecondsNow();
for (Map.Entry<Integer, ExtendedLogEntry> e : entries.entrySet()) { for (Map.Entry<Integer, ExtendedLogEntry> e : entries.entrySet()) {
long time = e.getValue().getTimestamp(); long time = e.getValue().getTimestamp();
long now = DateUtil.unixSecondsNow(); Message.LOG_ENTRY.send(sender,
Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatTimeShort(now - time), e.getValue().getFormatted()); e.getKey(),
DateUtil.formatTimeShort(now - time),
e.getValue().getActorFriendlyString(),
Character.toString(e.getValue().getType().getCode()),
e.getValue().getActedFriendlyString(),
e.getValue().getAction()
);
} }
return CommandResult.SUCCESS; return CommandResult.SUCCESS;

View File

@ -48,6 +48,8 @@ import java.util.SortedMap;
import java.util.UUID; import java.util.UUID;
public class LogUserHistory extends SubCommand<Log> { public class LogUserHistory extends SubCommand<Log> {
private static final int ENTRIES_PER_PAGE = 10;
public LogUserHistory(LocaleManager locale) { public LogUserHistory(LocaleManager locale) {
super(CommandSpec.LOG_USER_HISTORY.spec(locale), "userhistory", CommandPermission.LOG_USER_HISTORY, Predicates.notInRange(1, 2)); super(CommandSpec.LOG_USER_HISTORY.spec(locale), "userhistory", CommandPermission.LOG_USER_HISTORY, Predicates.notInRange(1, 2));
} }
@ -96,14 +98,14 @@ public class LogUserHistory extends SubCommand<Log> {
} }
if (page == Integer.MIN_VALUE) { if (page == Integer.MIN_VALUE) {
page = log.getUserHistoryMaxPages(uuid); page = log.getUserHistoryMaxPages(uuid, ENTRIES_PER_PAGE);
} }
return showLog(page, uuid, sender, log); return showLog(page, uuid, sender, log);
} }
private static CommandResult showLog(int page, UUID user, Sender sender, Log log) { private static CommandResult showLog(int page, UUID user, Sender sender, Log log) {
int maxPage = log.getUserHistoryMaxPages(user); int maxPage = log.getUserHistoryMaxPages(user, ENTRIES_PER_PAGE);
if (maxPage == 0) { if (maxPage == 0) {
Message.LOG_NO_ENTRIES.send(sender); Message.LOG_NO_ENTRIES.send(sender);
return CommandResult.STATE_ERROR; return CommandResult.STATE_ERROR;
@ -114,14 +116,21 @@ public class LogUserHistory extends SubCommand<Log> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
SortedMap<Integer, ExtendedLogEntry> entries = log.getUserHistory(page, user); SortedMap<Integer, ExtendedLogEntry> entries = log.getUserHistory(page, user, ENTRIES_PER_PAGE);
String name = entries.values().stream().findAny().get().getActedName(); String name = entries.values().stream().findAny().get().getActedName();
Message.LOG_HISTORY_USER_HEADER.send(sender, name, page, maxPage); Message.LOG_HISTORY_USER_HEADER.send(sender, name, page, maxPage);
long now = DateUtil.unixSecondsNow();
for (Map.Entry<Integer, ExtendedLogEntry> e : entries.entrySet()) { for (Map.Entry<Integer, ExtendedLogEntry> e : entries.entrySet()) {
long time = e.getValue().getTimestamp(); long time = e.getValue().getTimestamp();
long now = DateUtil.unixSecondsNow(); Message.LOG_ENTRY.send(sender,
Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatTimeShort(now - time), e.getValue().getFormatted()); e.getKey(),
DateUtil.formatTimeShort(now - time),
e.getValue().getActorFriendlyString(),
Character.toString(e.getValue().getType().getCode()),
e.getValue().getActedFriendlyString(),
e.getValue().getAction()
);
} }
return CommandResult.SUCCESS; return CommandResult.SUCCESS;

View File

@ -62,7 +62,7 @@ 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> {}", true), LOG("&3LOG &3&l> &8(&e{}&8) [&a{}&8] (&b{}&8)&f: {}", true),
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),
@ -117,8 +117,8 @@ public enum Message {
SEARCH_SEARCHING_MEMBERS("&aSearching for users and groups who inherit from &b{}&a...", true), SEARCH_SEARCHING_MEMBERS("&aSearching for users and groups who inherit from &b{}&a...", true),
SEARCH_RESULT("&aFound &b{}&a entries from &b{}&a users and &b{}&a groups.", true), SEARCH_RESULT("&aFound &b{}&a entries from &b{}&a users and &b{}&a groups.", true),
SEARCH_SHOWING_USERS("&bShowing user entries: &7(showing page &f{}&7 of &f{}&7 - &f{}&7 entries)", true), SEARCH_SHOWING_USERS("&bShowing user entries: &7(page &f{}&7 of &f{}&7 - &f{}&7 entries)", true),
SEARCH_SHOWING_GROUPS("&bShowing group entries: &7(showing page &f{}&7 of &f{}&7 - &f{}&7 entries)", true), SEARCH_SHOWING_GROUPS("&bShowing group entries: &7(page &f{}&7 of &f{}&7 - &f{}&7 entries)", true),
APPLY_EDITS_INVALID_CODE("&cInvalid code. &7({})", true), APPLY_EDITS_INVALID_CODE("&cInvalid code. &7({})", true),
APPLY_EDITS_UNABLE_TO_READ("&cUnable to read data using the given code. &7({})", true), APPLY_EDITS_UNABLE_TO_READ("&cUnable to read data using the given code. &7({})", true),
@ -202,10 +202,10 @@ public enum Message {
TRACKS_LIST("&aTracks: {}", true), TRACKS_LIST("&aTracks: {}", true),
PERMISSION_INFO("&b{}'s Permissions: &7(showing page &f{}&7 of &f{}&7 - &f{}&7 entries)", true), PERMISSION_INFO("&b{}'s Permissions: &7(page &f{}&7 of &f{}&7 - &f{}&7 entries)", true),
PERMISSION_INFO_NO_DATA("&b{}&a does not have any permissions set.", true), PERMISSION_INFO_NO_DATA("&b{}&a does not have any permissions set.", true),
PARENT_INFO("&b{}'s Parents: &7(showing page &f{}&7 of &f{}&7 - &f{}&7 entries)", true), PARENT_INFO("&b{}'s Parents: &7(page &f{}&7 of &f{}&7 - &f{}&7 entries)", true),
PARENT_INFO_NO_DATA("&b{}&a does not have any parents defined.", true), PARENT_INFO_NO_DATA("&b{}&a does not have any parents defined.", true),
LIST_TRACKS("&b{}'s Tracks:", true), LIST_TRACKS("&b{}'s Tracks:", true),
@ -387,7 +387,12 @@ public enum Message {
LOG_INVALID_PAGE("&cInvalid page number.", true), LOG_INVALID_PAGE("&cInvalid page number.", true),
LOG_INVALID_PAGE_RANGE("&cInvalid page number. Please enter a value between &41&c and &4{}&c.", true), LOG_INVALID_PAGE_RANGE("&cInvalid page number. Please enter a value between &41&c and &4{}&c.", true),
LOG_NO_ENTRIES("&bNo log entries to show.", true), LOG_NO_ENTRIES("&bNo log entries to show.", true),
LOG_ENTRY("&b#{} -> &8(&7{} ago&8) {}", true),
LOG_ENTRY(
"{PREFIX}&b#{} &8(&7{} ago&8) &8(&e{}&8) [&a{}&8] (&b{}&8)" + "\n" +
"{PERFIX}&7> &f{}",
false
),
LOG_NOTIFY_CONSOLE("&cCannot toggle notifications for console.", true), LOG_NOTIFY_CONSOLE("&cCannot toggle notifications for console.", true),
LOG_NOTIFY_TOGGLE_ON("&aEnabled&b logging output.", true), LOG_NOTIFY_TOGGLE_ON("&aEnabled&b logging output.", true),
@ -396,14 +401,12 @@ public enum Message {
LOG_NOTIFY_ALREADY_OFF("&cYou aren't currently receiving notifications.", true), LOG_NOTIFY_ALREADY_OFF("&cYou aren't currently receiving notifications.", true),
LOG_NOTIFY_UNKNOWN("&cState unknown. Expecting \"on\" or \"off\".", true), LOG_NOTIFY_UNKNOWN("&cState unknown. Expecting \"on\" or \"off\".", true),
LOG_SEARCH_HEADER("&aShowing recent actions for query &b{} &a(page &f{}&a of &f{}&a)", true), LOG_SEARCH_HEADER("&aShowing recent actions for query &b{} &7(page &f{}&7 of &f{}&7)", true),
LOG_RECENT_HEADER("&aShowing recent actions &7(page &f{}&7 of &f{}&7)", true),
LOG_RECENT_HEADER("&aShowing recent actions (page &f{}&a of &f{}&a)", true), LOG_RECENT_BY_HEADER("&aShowing recent actions by &b{} &7(page &f{}&7 of &f{}&7)", true),
LOG_RECENT_BY_HEADER("&aShowing recent actions by &b{} &a(page &f{}&a of &f{}&a)", true), LOG_HISTORY_USER_HEADER("&aShowing history for user &b{} &7(page &f{}&7 of &f{}&7)", true),
LOG_HISTORY_GROUP_HEADER("&aShowing history for group &b{} &7(page &f{}&7 of &f{}&7)", true),
LOG_HISTORY_USER_HEADER("&aShowing history for user &b{} &a(page &f{}&a of &f{}&a)", true), LOG_HISTORY_TRACK_HEADER("&aShowing history for track &b{} &7(page &f{}&7 of &f{}&7)", true),
LOG_HISTORY_GROUP_HEADER("&aShowing history for group &b{} &a(page &f{}&a of &f{}&a)", true),
LOG_HISTORY_TRACK_HEADER("&aShowing history for track &b{} &a(page &f{}&a of &f{}&a)", true),
LOG_EXPORT_ALREADY_EXISTS("&cError: File &4{}&c already exists.", true), LOG_EXPORT_ALREADY_EXISTS("&cError: File &4{}&c already exists.", true),
LOG_EXPORT_NOT_WRITABLE("&cError: File &4{}&c is not writable.", true), LOG_EXPORT_NOT_WRITABLE("&cError: File &4{}&c is not writable.", true),