use of me.lucko.luckperms.sponge.service.model.LPSubject in project LuckPerms by lucko.
the class SpongeMainCommand method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List<String> args, String label) {
LuckPermsService service = this.plugin.getService();
if (args.size() < 1) {
MessageUtils.sendPluginMessage(sender, "&aCurrent Subject Collections:\n" + MessageUtils.toCommaSep(service.getLoadedCollections().keySet().stream().filter(s -> !s.equalsIgnoreCase("user") && !s.equalsIgnoreCase("group")).sorted().collect(Collectors.toList())));
return CommandResult.SUCCESS;
}
String subjectCollection = args.get(0);
if (subjectCollection.equalsIgnoreCase("user") || subjectCollection.equalsIgnoreCase("group")) {
MessageUtils.sendPluginMessage(sender, "Please use the main LuckPerms commands to edit users and groups.");
return CommandResult.STATE_ERROR;
}
if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(subjectCollection))) {
MessageUtils.sendPluginMessage(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::getIdentifier).collect(Collectors.toList());
if (subjects.size() > 50) {
List<String> extra = subjects.subList(50, subjects.size());
int overflow = extra.size();
extra.clear();
MessageUtils.sendPluginMessage(sender, "&aCurrent Subjects:\n" + MessageUtils.toCommaSep(subjects) + "&b ... and &a" + overflow + " &bmore.");
} else {
MessageUtils.sendPluginMessage(sender, "&aCurrent Subjects:\n" + MessageUtils.toCommaSep(subjects));
}
return CommandResult.SUCCESS;
}
if (args.size() < 4) {
sendDetailedUsage(sender, label);
return CommandResult.SUCCESS;
}
boolean persistent = true;
if (args.get(2).toLowerCase().startsWith("-t")) {
persistent = false;
args.remove(2);
}
String type = args.get(2).toLowerCase();
if (!type.equals("permission") && !type.equals("parent") && !type.equals("option")) {
sendDetailedUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
String cmd = args.get(3);
Optional<Command<LPSubjectData, ?>> o = this.subCommands.get(type).stream().filter(s -> s.getName().equalsIgnoreCase(cmd)).findAny();
if (!o.isPresent()) {
sendDetailedUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
final Command<LPSubjectData, ?> sub = o.get();
if (!sub.isAuthorized(sender)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
List<String> strippedArgs = new ArrayList<>();
if (args.size() > 4) {
strippedArgs.addAll(args.subList(4, args.size()));
}
if (sub.getArgumentCheck().test(strippedArgs.size())) {
sub.sendDetailedUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
String subjectId = args.get(1);
if (!collection.hasRegistered(subjectId).join()) {
MessageUtils.sendPluginMessage(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();
CommandResult result;
try {
result = sub.execute(plugin, sender, subjectData, strippedArgs, label);
} catch (CommandException e) {
result = CommandManager.handleException(e, sender, label, sub);
}
return result;
}
use of me.lucko.luckperms.sponge.service.model.LPSubject in project LuckPerms by lucko.
the class SpongeUserManager method loadSubject.
@Override
public CompletableFuture<LPSubject> loadSubject(String identifier) {
UUID uuid = Uuids.parseNullable(identifier);
if (uuid == null) {
throw new IllegalArgumentException("Identifier is not a UUID: " + identifier);
}
LPSubject present = this.subjectLoadingCache.getIfPresent(uuid);
if (present != null) {
return CompletableFuture.completedFuture(present);
}
return CompletableFuture.supplyAsync(() -> this.subjectLoadingCache.get(uuid), this.plugin.getBootstrap().getScheduler().async());
}
use of me.lucko.luckperms.sponge.service.model.LPSubject in project LuckPerms by lucko.
the class ParentAdd method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
String collection = args.get(0);
String name = args.get(1);
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
LPPermissionService service = Sponge.getServiceManager().provideUnchecked(LPPermissionService.class);
if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
MessageUtils.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't already exist.");
}
LPSubjectCollection c = service.getCollection(collection);
if (!c.hasRegistered(name).join()) {
MessageUtils.sendPluginMessage(sender, "Warning: Subject '&4" + name + "&c' doesn't already exist.");
}
LPSubject subject = c.loadSubject(name).join();
if (subjectData.addParent(contextSet, subject.toReference()).join()) {
MessageUtils.sendPluginMessage(sender, "&aAdded parent &b" + subject.getParentCollection().getIdentifier() + "&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
MessageUtils.sendPluginMessage(sender, "Unable to add parent. Does the Subject already have it added?");
}
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.sponge.service.model.LPSubject in project LuckPerms by lucko.
the class DescriptionBuilder method register.
@Nonnull
@Override
public PermissionDescription register() throws IllegalStateException {
if (this.id == null) {
throw new IllegalStateException("id cannot be null");
}
LPPermissionDescription description = this.service.registerPermissionDescription(this.id, this.description, this.container);
// Set role-templates
LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
for (Map.Entry<String, Tristate> assignment : this.roles.entrySet()) {
LPSubject roleSubject = subjects.loadSubject(assignment.getKey()).join();
roleSubject.getTransientSubjectData().setPermission(ContextSet.empty(), this.id, assignment.getValue());
}
this.service.getPlugin().getPermissionVault().offer(this.id);
// null stuff so this instance can be reused
this.roles.clear();
this.id = null;
this.description = null;
return description.sponge();
}
use of me.lucko.luckperms.sponge.service.model.LPSubject in project LuckPerms by lucko.
the class DescriptionBuilder method register.
@Nonnull
@Override
public PermissionDescription register() throws IllegalStateException {
if (this.id == null) {
throw new IllegalStateException("id cannot be null");
}
LPPermissionDescription description = this.service.registerPermissionDescription(this.id, this.description, this.container);
// Set role-templates
LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
for (Map.Entry<String, Tristate> assignment : this.roles.entrySet()) {
LPSubject roleSubject = subjects.loadSubject(assignment.getKey()).join();
roleSubject.getTransientSubjectData().setPermission(ContextSet.empty(), this.id, assignment.getValue());
}
this.service.getPlugin().getPermissionVault().offer(this.id);
// null stuff so this instance can be reused
this.roles.clear();
this.id = null;
this.description = null;
return description.sponge();
}
Aggregations