Search in sources :

Example 1 with LoggedAction

use of me.lucko.luckperms.common.actionlog.LoggedAction in project LuckPerms by lucko.

the class MongoStorage method getLog.

@Override
public Log getLog() {
    Log.Builder log = Log.builder();
    MongoCollection<Document> c = this.database.getCollection(this.prefix + "action");
    try (MongoCursor<Document> cursor = c.find().iterator()) {
        while (cursor.hasNext()) {
            Document d = cursor.next();
            if (d.containsKey("source")) {
                // new format
                Document source = d.get("source", Document.class);
                Document target = d.get("target", Document.class);
                UUID targetUniqueId = null;
                if (target.containsKey("uniqueId")) {
                    targetUniqueId = target.get("uniqueId", UUID.class);
                }
                LoggedAction e = LoggedAction.build().timestamp(Instant.ofEpochSecond(d.getLong("timestamp"))).source(source.get("uniqueId", UUID.class)).sourceName(source.getString("name")).targetType(LoggedAction.parseType(target.getString("type"))).target(targetUniqueId).targetName(target.getString("name")).description(d.getString("description")).build();
                log.add(e);
            } else {
                // old format
                UUID actedUuid = null;
                if (d.containsKey("acted")) {
                    actedUuid = d.get("acted", UUID.class);
                }
                LoggedAction e = LoggedAction.build().timestamp(Instant.ofEpochSecond(d.getLong("timestamp"))).source(d.get("actor", UUID.class)).sourceName(d.getString("actorName")).targetType(LoggedAction.parseTypeCharacter(d.getString("type").charAt(0))).target(actedUuid).targetName(d.getString("actedName")).description(d.getString("action")).build();
                log.add(e);
            }
        }
    }
    return log.build();
}
Also used : Log(me.lucko.luckperms.common.actionlog.Log) Document(org.bson.Document) UUID(java.util.UUID) LoggedAction(me.lucko.luckperms.common.actionlog.LoggedAction)

Example 2 with LoggedAction

use of me.lucko.luckperms.common.actionlog.LoggedAction in project LuckPerms by lucko.

the class LogRecent method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, Log log, ArgumentList args, String label) {
    if (args.isEmpty()) {
        // No page or user
        Paginated<LoggedAction> content = new Paginated<>(log.getContent());
        showLog(content.getMaxPages(ENTRIES_PER_PAGE), false, sender, content);
        return;
    }
    int page = args.getIntOrDefault(0, Integer.MIN_VALUE);
    if (page != Integer.MIN_VALUE) {
        Paginated<LoggedAction> content = new Paginated<>(log.getContent());
        showLog(page, false, sender, content);
        return;
    }
    // User and possibly page
    UUID uuid = args.getUserTarget(0, plugin, sender);
    if (uuid == null) {
        return;
    }
    Paginated<LoggedAction> content = new Paginated<>(log.getContent(uuid));
    page = args.getIntOrDefault(1, Integer.MIN_VALUE);
    if (page != Integer.MIN_VALUE) {
        showLog(page, true, sender, content);
    } else {
        showLog(content.getMaxPages(ENTRIES_PER_PAGE), true, sender, content);
    }
}
Also used : Paginated(me.lucko.luckperms.common.util.Paginated) UUID(java.util.UUID) LoggedAction(me.lucko.luckperms.common.actionlog.LoggedAction)

Example 3 with LoggedAction

use of me.lucko.luckperms.common.actionlog.LoggedAction in project LuckPerms by lucko.

the class LogUserHistory method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, Log log, ArgumentList args, String label) {
    UUID uuid = args.getUserTarget(0, plugin, sender);
    if (uuid == null) {
        return;
    }
    Paginated<LoggedAction> content = new Paginated<>(log.getUserHistory(uuid));
    int page = args.getIntOrDefault(1, Integer.MIN_VALUE);
    if (page != Integer.MIN_VALUE) {
        showLog(page, sender, content);
    } else {
        showLog(content.getMaxPages(ENTRIES_PER_PAGE), sender, content);
    }
}
Also used : Paginated(me.lucko.luckperms.common.util.Paginated) UUID(java.util.UUID) LoggedAction(me.lucko.luckperms.common.actionlog.LoggedAction)

Aggregations

UUID (java.util.UUID)3 LoggedAction (me.lucko.luckperms.common.actionlog.LoggedAction)3 Paginated (me.lucko.luckperms.common.util.Paginated)2 Log (me.lucko.luckperms.common.actionlog.Log)1 Document (org.bson.Document)1