use of me.lucko.luckperms.sponge.service.LuckPermsService in project LuckPerms by lucko.
the class LPSpongePlugin method setupPlatformHooks.
@Override
protected void setupPlatformHooks() {
getLogger().info("Registering PermissionService...");
this.updateEventHandler = UpdateEventHandler.obtain(this);
this.service = new LuckPermsService(this);
if (this.bootstrap.getGame().getPluginManager().getPlugin("permissionsex").isPresent()) {
getLogger().warn("Detected PermissionsEx - assuming it's loaded for migration.");
getLogger().warn("Delaying LuckPerms PermissionService registration.");
this.lateLoad = true;
} else {
this.bootstrap.getGame().getServiceManager().setProvider(this.bootstrap, LPPermissionService.class, this.service);
this.bootstrap.getGame().getServiceManager().setProvider(this.bootstrap, PermissionService.class, this.service.sponge());
}
}
use of me.lucko.luckperms.sponge.service.LuckPermsService 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;
}
Aggregations