use of me.lucko.luckperms.common.command.abstraction.ChildCommand in project LuckPerms by lucko.
the class SpongeParentCommand method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, Void v, ArgumentList args, String label) {
LuckPermsService service = this.plugin.getService();
if (args.size() < 1) {
SpongeCommandUtils.sendPrefixed(sender, "&aCurrent Subject Collections:\n" + SpongeCommandUtils.toCommaSep(service.getLoadedCollections().keySet().stream().filter(s -> !s.equalsIgnoreCase("user") && !s.equalsIgnoreCase("group")).sorted().collect(Collectors.toList())));
return;
}
String subjectCollection = args.get(0);
if (subjectCollection.equalsIgnoreCase("user") || subjectCollection.equalsIgnoreCase("group")) {
SpongeCommandUtils.sendPrefixed(sender, "Please use the main LuckPerms commands to edit users and groups.");
return;
}
if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(subjectCollection))) {
SpongeCommandUtils.sendPrefixed(sender, "Warning: SubjectCollection '&4" + subjectCollection + "&c' doesn't already exist. Creating it now.");
}
LPSubjectCollection collection = service.getCollection(subjectCollection);
if (args.size() < 2) {
List<String> subjects = collection.getLoadedSubjects().stream().map(lpSubject -> lpSubject.getIdentifier().getName()).collect(Collectors.toList());
if (subjects.size() > 50) {
List<String> extra = subjects.subList(50, subjects.size());
int overflow = extra.size();
extra.clear();
SpongeCommandUtils.sendPrefixed(sender, "&aCurrent Subjects:\n" + SpongeCommandUtils.toCommaSep(subjects) + "&b ... and &a" + overflow + " &bmore.");
} else {
SpongeCommandUtils.sendPrefixed(sender, "&aCurrent Subjects:\n" + SpongeCommandUtils.toCommaSep(subjects));
}
return;
}
if (args.size() < 4) {
sendDetailedUsage(sender, label);
return;
}
boolean persistent = true;
if (args.get(2).toLowerCase(Locale.ROOT).startsWith("-t")) {
persistent = false;
args.remove(2);
}
String type = args.get(2).toLowerCase(Locale.ROOT);
if (!type.equals("permission") && !type.equals("parent") && !type.equals("option")) {
sendDetailedUsage(sender, label);
return;
}
String cmd = args.get(3);
ChildCommand<LPSubjectData> sub = this.children.get(type).stream().filter(s -> s.getName().equalsIgnoreCase(cmd)).findAny().orElse(null);
if (sub == null) {
sendDetailedUsage(sender, label);
return;
}
if (!sub.isAuthorized(sender)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
if (sub.getArgumentCheck().test(args.size() - 4)) {
sub.sendDetailedUsage(sender, label);
return;
}
String subjectId = args.get(1);
if (!collection.hasRegistered(subjectId).join()) {
SpongeCommandUtils.sendPrefixed(sender, "Warning: Subject '&4" + subjectId + "&c' doesn't already exist. Creating it now.");
}
LPSubject subject = collection.loadSubject(subjectId).join();
LPSubjectData subjectData = persistent ? subject.getSubjectData() : subject.getTransientSubjectData();
try {
sub.execute(plugin, sender, subjectData, args.subList(4, args.size()), label);
} catch (CommandException e) {
e.handle(sender, label, sub);
}
}
Aggregations