use of me.lucko.luckperms.common.locale.Message in project LuckPerms by lucko.
the class VerboseCommand method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
if (args.isEmpty()) {
sendUsage(sender, label);
return;
}
VerboseHandler verboseHandler = plugin.getVerboseHandler();
String mode = args.get(0).toLowerCase(Locale.ROOT);
if (mode.equals("command") || mode.equals("cmd")) {
if (args.size() < 3) {
sendDetailedUsage(sender, label);
return;
}
String name = args.get(1);
Sender executor;
if (name.equals("me") || name.equals("self") || name.equalsIgnoreCase(sender.getName())) {
executor = sender;
} else {
if (!CommandPermission.VERBOSE_COMMAND_OTHERS.isAuthorized(sender)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
executor = plugin.getOnlineSenders().filter(s -> !s.isConsole()).filter(s -> s.getName().equalsIgnoreCase(name)).findAny().orElse(null);
if (executor == null) {
Message.USER_NOT_ONLINE.send(sender, name);
return;
}
}
String commandWithSlash = String.join(" ", args.subList(2, args.size()));
String command = commandWithSlash.charAt(0) == '/' ? commandWithSlash.substring(1) : commandWithSlash;
plugin.getBootstrap().getScheduler().sync().execute(() -> {
Message.VERBOSE_ON_COMMAND.send(sender, executor.getName(), command);
verboseHandler.registerListener(sender, VerboseFilter.acceptAll(), true);
executor.performCommand(command);
VerboseListener listener = verboseHandler.unregisterListener(sender);
if (listener.getMatchedCount() == 0) {
Message.VERBOSE_OFF_COMMAND_NO_CHECKS.send(sender);
} else {
Message.VERBOSE_OFF_COMMAND.send(sender);
}
});
return;
}
if (mode.equals("on") || mode.equals("true") || mode.equals("record")) {
List<String> filters = new ArrayList<>();
if (args.size() != 1) {
filters.addAll(args.subList(1, args.size()));
}
String filter = filters.isEmpty() ? "" : String.join(" ", filters);
VerboseFilter compiledFilter;
try {
compiledFilter = VerboseFilter.compile(filter);
} catch (InvalidFilterException e) {
Message.VERBOSE_INVALID_FILTER.send(sender, filter, e.getCause().getMessage());
return;
}
boolean notify = !mode.equals("record");
verboseHandler.registerListener(sender, compiledFilter, notify);
if (notify) {
if (!filter.isEmpty()) {
Message.VERBOSE_ON_QUERY.send(sender, filter);
} else {
Message.VERBOSE_ON.send(sender);
}
} else {
if (!filter.isEmpty()) {
Message.VERBOSE_RECORDING_ON_QUERY.send(sender, filter);
} else {
Message.VERBOSE_RECORDING_ON.send(sender);
}
}
return;
}
if (mode.equals("off") || mode.equals("false") || mode.equals("paste") || mode.equals("upload")) {
VerboseListener listener = verboseHandler.unregisterListener(sender);
if (mode.equals("paste") || mode.equals("upload")) {
if (listener == null) {
Message.VERBOSE_OFF.send(sender);
} else {
Message.VERBOSE_UPLOAD_START.send(sender);
String id;
try {
id = listener.uploadPasteData(plugin.getBytebin());
} catch (UnsuccessfulRequestException e) {
Message.GENERIC_HTTP_REQUEST_FAILURE.send(sender, e.getResponse().code(), e.getResponse().message());
return;
} catch (IOException e) {
plugin.getLogger().warn("Error uploading data to bytebin", e);
Message.GENERIC_HTTP_UNKNOWN_FAILURE.send(sender);
return;
}
String url = plugin.getConfiguration().get(ConfigKeys.VERBOSE_VIEWER_URL_PATTERN) + id;
Message.VERBOSE_RESULTS_URL.send(sender, url);
return;
}
} else {
Message.VERBOSE_OFF.send(sender);
}
return;
}
sendUsage(sender, label);
}
use of me.lucko.luckperms.common.locale.Message in project LuckPerms by lucko.
the class GroupListMembers method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, Group target, ArgumentList args, String label) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
InheritanceNode node = Inheritance.builder(target.getName()).build();
ConstraintNodeMatcher<InheritanceNode> matcher = StandardNodeMatchers.key(node);
int page = args.getIntOrDefault(0, 1);
Message.SEARCH_SEARCHING_MEMBERS.send(sender, target.getName());
List<NodeEntry<UUID, InheritanceNode>> matchedUsers = plugin.getStorage().searchUserNodes(matcher).join().stream().filter(n -> n.getNode().getValue()).collect(Collectors.toList());
// special handling for default group
if (target.getName().equals(GroupManager.DEFAULT_GROUP_NAME)) {
// include all non-saved online players in the results
for (User user : plugin.getUserManager().getAll().values()) {
if (!plugin.getUserManager().isNonDefaultUser(user)) {
matchedUsers.add(NodeEntry.of(user.getUniqueId(), node));
}
}
// send a warning message about this behaviour
Message.SEARCH_RESULT_GROUP_DEFAULT.send(sender);
}
List<NodeEntry<String, InheritanceNode>> matchedGroups = plugin.getStorage().searchGroupNodes(matcher).join().stream().filter(n -> n.getNode().getValue()).collect(Collectors.toList());
int users = matchedUsers.size();
int groups = matchedGroups.size();
Message.SEARCH_RESULT.send(sender, users + groups, users, groups);
if (!matchedUsers.isEmpty()) {
Map<UUID, String> uuidLookups = LoadingMap.of(u -> plugin.lookupUsername(u).orElseGet(u::toString));
sendResult(sender, matchedUsers, uuidLookups::get, Message.SEARCH_SHOWING_USERS, HolderType.USER, label, page);
}
if (!matchedGroups.isEmpty()) {
sendResult(sender, matchedGroups, Function.identity(), Message.SEARCH_SHOWING_GROUPS, HolderType.GROUP, label, page);
}
}
Aggregations