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;
}
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;
}
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");
}
}
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);
}
}
Aggregations