Search in sources :

Example 1 with LogAttachment

use of org.cubeengine.module.log.LogAttachment 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 2 with LogAttachment

use of org.cubeengine.module.log.LogAttachment 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 3 with LogAttachment

use of org.cubeengine.module.log.LogAttachment in project modules-extra by CubeEngine.

the class Lookup method redo.

public void redo(User user, boolean preview) {
    LogAttachment attachment = user.attachOrGet(LogAttachment.class, this.module);
    attachment.setLastLookup(this);
    this.queryResults.redo(attachment, preview);
    if (preview) {
        attachment.sendPreview();
    }
}
Also used : LogAttachment(org.cubeengine.module.log.LogAttachment)

Example 4 with LogAttachment

use of org.cubeengine.module.log.LogAttachment in project modules-extra by CubeEngine.

the class Lookup method show.

public void show(User user) {
    LogAttachment attachment = user.attachOrGet(LogAttachment.class, this.module);
    attachment.setLastLookup(this);
    this.queryResults.show(user, queryParameter, attachment.getShowParameter());
}
Also used : LogAttachment(org.cubeengine.module.log.LogAttachment)

Example 5 with LogAttachment

use of org.cubeengine.module.log.LogAttachment in project modules-extra by CubeEngine.

the class Lookup method rollback.

public void rollback(User user, boolean preview) {
    LogAttachment attachment = user.attachOrGet(LogAttachment.class, this.module);
    attachment.setLastLookup(this);
    this.queryResults.rollback(attachment, preview);
    if (preview) {
        attachment.sendPreview();
    }
}
Also used : LogAttachment(org.cubeengine.module.log.LogAttachment)

Aggregations

LogAttachment (org.cubeengine.module.log.LogAttachment)6 User (org.cubeengine.libcube.service.user.User)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1 Command (org.cubeengine.butler.parametric.Command)1 TimeConversionException (org.cubeengine.libcube.util.TimeConversionException)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 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1