Search in sources :

Example 1 with User

use of org.cubeengine.libcube.service.user.User in project modules-extra by CubeEngine.

the class LookupCommands method readUser.

private boolean readUser(QueryParameter params, String userString, User sender) {
    if (userString == null) {
        return true;
    }
    String[] users = StringUtils.explode(",", userString);
    for (String name : users) {
        boolean negate = name.startsWith("!");
        if (negate) {
            name = name.substring(1);
        }
        User user = this.module.getCore().getUserManager().findExactUser(name);
        if (user == null) {
            sender.sendTranslated(NEGATIVE, "User {user} not found!", name);
            return false;
        }
        if (negate) {
            params.excludeUser(user.getUniqueId());
        } else {
            params.includeUser(user.getUniqueId());
        }
    }
    return true;
}
Also used : User(org.cubeengine.libcube.service.user.User)

Example 2 with User

use of org.cubeengine.libcube.service.user.User in project modules-extra by CubeEngine.

the class LookupCommands method readRadius.

private boolean readRadius(QueryParameter params, String radiusString, User user) {
    if (radiusString == null) {
        return true;
    }
    if (radiusString.equalsIgnoreCase("selection") || radiusString.equalsIgnoreCase("sel")) {
        LogAttachment logAttachment = user.attachOrGet(LogAttachment.class, this.module);
        if (!logAttachment.applySelection(params)) {
            user.sendTranslated(NEGATIVE, "You have to select a region first!");
            if (module.hasWorldEdit()) {
                user.sendTranslated(NEUTRAL, "Use worldedit to select a cuboid region!");
            } else {
                user.sendTranslated(NEUTRAL, "Use this selection wand.");
                LogCommands.giveSelectionTool(user);
            }
            return false;
        }
    } else if (radiusString.equalsIgnoreCase("global") || radiusString.equalsIgnoreCase("g")) {
        params.setWorld(user.getWorld());
    } else {
        User radiusUser = null;
        Integer radius;
        if (radiusString.contains(":")) {
            radiusUser = this.module.getCore().getUserManager().findUser(radiusString.substring(0, radiusString.indexOf(":")));
            if (radiusUser == null) {
                user.sendTranslated(NEGATIVE, "Invalid radius/location selection");
                user.sendTranslated(POSITIVE, "The radius parameter can be: <radius> | selection | global | <player>[:<radius>]");
                return false;
            }
            radiusString = radiusString.substring(radiusString.indexOf(":") + 1);
        }
        try {
            radius = Integer.parseInt(radiusString);
            if (radiusUser == null) {
                radiusUser = user;
            }
            params.setLocationRadius(radiusUser.getLocation(), radius);
        } catch (NumberFormatException ex) {
            radiusUser = this.module.getCore().getUserManager().findUser(radiusString);
            if (radiusUser == null) {
                user.sendTranslated(NEGATIVE, "Invalid radius/location selection");
                user.sendTranslated(POSITIVE, "The radius parameter can be: <radius> | selection | global | <player>[:<radius>]");
                return false;
            }
            params.setWorld(radiusUser.getWorld());
        }
    }
    return true;
}
Also used : User(org.cubeengine.libcube.service.user.User) LogAttachment(org.cubeengine.module.log.LogAttachment)

Example 3 with User

use of org.cubeengine.libcube.service.user.User in project modules-extra by CubeEngine.

the class LookupCommands method lookup.

@Command(desc = "Queries a lookup in the database\n    Show availiable parameters with /lookup params")
public // TODO param for filter / chat / command / signtexts
void lookup(CommandContext context, @Label("params") @Optional String action, @Named({ "action", "a" }) @Complete(ActionTypeCompleter.class) String actions, @Named({ "radius", "r" }) String radius, @Named({ "player", "p" }) @Complete(PlayerListCompleter.class) String players, @Named({ "block", "b" }) @Complete(MaterialListCompleter.class) String blocks, @Named({ "entity", "e" }) String entities, @Named({ "since", "time", "t" }) String since, @Named({ "before" }) String before, @Named({ "world", "w", "in" }) @Complete(WorldCompleter.class) String world, @Named({ "limit", "pagelimit" }) Integer limit, @Named({ "page" }) Integer page, @Named("params") @Complete(ActionTypeCompleter.class) String params, @Flag(longName = "coordinates", name = "coords") boolean showCoord, @Flag(longName = "detailed", name = "det") boolean detailed, @Flag(longName = "nodate", name = "nd") boolean nodate, @Flag(longName = "descending", name = "desc") boolean descending) {
    if ("params".equalsIgnoreCase(action) || params != null) {
        this.params(context.getSource(), params);
        return;
    }
    if (context.getSource() instanceof User) {
        if (!context.hasNamed()) {
            try {
                context.sendTranslated(NEGATIVE, "You have to provide parameters");
            // ((Dispatcher)context.getCommand()).getCommand("?").execute(context.getInvocation());
            // TODO show all selected params of last lookup
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
            return;
        }
        User user = (User) context.getSource();
        LogAttachment attachment = user.attachOrGet(LogAttachment.class, this.module);
        // gets last OR new Showparameter
        ShowParameter show = attachment.getLastShowParameter();
        Lookup lookup = attachment.getLastLookup();
        if (// /lookup show / page <page>
        !this.fillShowOptions(attachment, lookup, show, context.getSource(), showCoord, nodate, detailed, descending, limit, page, action)) {
            return;
        }
        lookup = attachment.createNewCommandLookup();
        QueryParameter parameters = lookup.getQueryParameter();
        if (!(readActions(parameters, actions, user) && readRadius(parameters, radius, user) && readUser(parameters, players, user) && readBlocks(parameters, blocks, user) && readEntities(parameters, entities, user) && readWorld(parameters, world, radius != null, user) && readTimeSince(parameters, since, user) && readTimeBefore(parameters, before, user))) {
            return;
        }
        attachment.queueShowParameter(show);
        this.module.getLogManager().fillLookupAndShow(lookup, user);
    } else {
        // TODO implement me
        System.out.println("Not implemented yet");
    }
}
Also used : QueryParameter(org.cubeengine.module.log.storage.QueryParameter) User(org.cubeengine.libcube.service.user.User) ShowParameter(org.cubeengine.module.log.storage.ShowParameter) Lookup(org.cubeengine.module.log.storage.Lookup) TimeConversionException(org.cubeengine.libcube.util.TimeConversionException) LogAttachment(org.cubeengine.module.log.LogAttachment) Command(org.cubeengine.butler.parametric.Command)

Example 4 with User

use of org.cubeengine.libcube.service.user.User in project modules-extra by CubeEngine.

the class QueryManager method doQueryLookup.

private void doQueryLookup() {
    if (queuedLookups.isEmpty()) {
        return;
    }
    QueuedSqlParams poll = this.queuedLookups.poll();
    final QueryAction queryAction = poll.action;
    final Lookup lookup = poll.lookup;
    final User user = poll.user;
    // limit 10000
    DBCursor cursor = this.collection.find(poll.query);
    QueryResults results = new QueryResults(lookup, module);
    for (DBObject entry : cursor) {
        try {
            @SuppressWarnings("unchecked") Class<? extends BaseAction> action = (Class<? extends BaseAction>) Class.forName((String) entry.get("action"));
            results.addResult(module.getCore().getConfigFactory().load(action, entry));
        } catch (ClassNotFoundException e) {
            module.getLog().warn(e, "Could not find Action for DBObject! {}", entry.get("action"));
        }
    }
    lookup.setQueryResults(results);
    if (user != null && user.isOnline()) {
        module.getCore().getTaskManager().runTask(module, (Runnable) () -> {
            switch(queryAction) {
                case SHOW:
                    lookup.show(user);
                    return;
                case ROLLBACK:
                    lookup.rollback(user, false);
                    return;
                case ROLLBACK_PREVIEW:
                    lookup.rollback(user, true);
                    return;
                case REDO:
                    lookup.redo(user, false);
                    return;
                case REDO_PREVIEW:
                    lookup.redo(user, true);
            }
        });
    }
    if (!queuedLookups.isEmpty()) {
        this.futureLookup = this.lookupExecutor.submit(this.lookupRunner);
    }
}
Also used : User(org.cubeengine.libcube.service.user.User) BaseAction(org.cubeengine.module.log.action.BaseAction) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor)

Aggregations

User (org.cubeengine.libcube.service.user.User)4 LogAttachment (org.cubeengine.module.log.LogAttachment)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBCursor (com.mongodb.DBCursor)1 DBObject (com.mongodb.DBObject)1 Command (org.cubeengine.butler.parametric.Command)1 TimeConversionException (org.cubeengine.libcube.util.TimeConversionException)1 BaseAction (org.cubeengine.module.log.action.BaseAction)1 Lookup (org.cubeengine.module.log.storage.Lookup)1 QueryParameter (org.cubeengine.module.log.storage.QueryParameter)1 ShowParameter (org.cubeengine.module.log.storage.ShowParameter)1