mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Refactor sponge commands to use the proxied interfaces (closes #197)
This commit is contained in:
parent
e6a90a18c4
commit
35d1057673
@ -266,6 +266,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
lateLoad = true;
|
lateLoad = true;
|
||||||
} else {
|
} else {
|
||||||
game.getServiceManager().setProvider(this, PermissionService.class, service);
|
game.getServiceManager().setProvider(this, PermissionService.class, service);
|
||||||
|
game.getServiceManager().setProvider(this, LuckPermsService.class, service);
|
||||||
}
|
}
|
||||||
|
|
||||||
// register with the LP API
|
// register with the LP API
|
||||||
@ -299,6 +300,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
if (lateLoad) {
|
if (lateLoad) {
|
||||||
getLog().info("Providing late registration of PermissionService...");
|
getLog().info("Providing late registration of PermissionService...");
|
||||||
game.getServiceManager().setProvider(this, PermissionService.class, service);
|
game.getServiceManager().setProvider(this, PermissionService.class, service);
|
||||||
|
game.getServiceManager().setProvider(this, LuckPermsService.class, service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,23 +323,14 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
@Listener
|
@Listener
|
||||||
public void onPostInit(GamePostInitializationEvent event) {
|
public void onPostInit(GamePostInitializationEvent event) {
|
||||||
// register permissions
|
// register permissions
|
||||||
Optional<PermissionService> ps = game.getServiceManager().provide(PermissionService.class);
|
LuckPermsService service = this.service;
|
||||||
if (!ps.isPresent()) {
|
if (service == null) {
|
||||||
getLog().warn("Unable to register all LuckPerms permissions. PermissionService not available.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final PermissionService p = ps.get();
|
|
||||||
|
|
||||||
Optional<PermissionDescription.Builder> builder = p.newDescriptionBuilder(this);
|
|
||||||
if (!builder.isPresent()) {
|
|
||||||
getLog().warn("Unable to register all LuckPerms permissions. Description Builder not available.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Permission perm : Permission.values()) {
|
for (Permission perm : Permission.values()) {
|
||||||
for (String node : perm.getNodes()) {
|
for (String node : perm.getNodes()) {
|
||||||
registerPermission(p, node);
|
registerPermission(service, node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -473,7 +466,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerPermission(PermissionService p, String node) {
|
private void registerPermission(LuckPermsService p, String node) {
|
||||||
Optional<PermissionDescription.Builder> builder = p.newDescriptionBuilder(this);
|
Optional<PermissionDescription.Builder> builder = p.newDescriptionBuilder(this);
|
||||||
if (!builder.isPresent()) return;
|
if (!builder.isPresent()) return;
|
||||||
|
|
||||||
|
@ -33,12 +33,11 @@ import me.lucko.luckperms.common.commands.utils.Util;
|
|||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class OptionClear extends SubCommand<SubjectData> {
|
public class OptionClear extends SubCommand<LPSubjectData> {
|
||||||
public OptionClear() {
|
public OptionClear() {
|
||||||
super("clear", "Clears the Subjects options", Permission.SPONGE_OPTION_CLEAR, Predicates.alwaysFalse(),
|
super("clear", "Clears the Subjects options", Permission.SPONGE_OPTION_CLEAR, Predicates.alwaysFalse(),
|
||||||
Arg.list(
|
Arg.list(
|
||||||
@ -48,13 +47,13 @@ public class OptionClear extends SubCommand<SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, SubjectData subjectData, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||||
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
||||||
if (contextSet.isEmpty()) {
|
if (contextSet.isEmpty()) {
|
||||||
subjectData.clearOptions();
|
subjectData.clearOptions();
|
||||||
Util.sendPluginMessage(sender, "&aCleared options matching contexts &bANY&a.");
|
Util.sendPluginMessage(sender, "&aCleared options matching contexts &bANY&a.");
|
||||||
} else {
|
} else {
|
||||||
subjectData.clearOptions(SpongeUtils.convertContexts(contextSet));
|
subjectData.clearOptions(contextSet);
|
||||||
Util.sendPluginMessage(sender, "&aCleared options matching contexts &b" + SpongeUtils.contextToString(contextSet));
|
Util.sendPluginMessage(sender, "&aCleared options matching contexts &b" + SpongeUtils.contextToString(contextSet));
|
||||||
}
|
}
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
package me.lucko.luckperms.sponge.commands;
|
package me.lucko.luckperms.sponge.commands;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.commands.Arg;
|
import me.lucko.luckperms.common.commands.Arg;
|
||||||
import me.lucko.luckperms.common.commands.CommandException;
|
import me.lucko.luckperms.common.commands.CommandException;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
@ -33,15 +34,12 @@ import me.lucko.luckperms.common.commands.utils.Util;
|
|||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import org.spongepowered.api.service.context.Context;
|
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class OptionInfo extends SubCommand<SubjectData> {
|
public class OptionInfo extends SubCommand<LPSubjectData> {
|
||||||
public OptionInfo() {
|
public OptionInfo() {
|
||||||
super("info", "Shows info about the subject's options", Permission.SPONGE_OPTION_INFO, Predicates.alwaysFalse(),
|
super("info", "Shows info about the subject's options", Permission.SPONGE_OPTION_INFO, Predicates.alwaysFalse(),
|
||||||
Arg.list(Arg.create("contexts...", false, "the contexts to filter by"))
|
Arg.list(Arg.create("contexts...", false, "the contexts to filter by"))
|
||||||
@ -49,23 +47,22 @@ public class OptionInfo extends SubCommand<SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, SubjectData subjectData, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||||
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
||||||
if (contextSet.isEmpty()) {
|
if (contextSet.isEmpty()) {
|
||||||
Util.sendPluginMessage(sender, "&aShowing options matching contexts &bANY&a.");
|
Util.sendPluginMessage(sender, "&aShowing options matching contexts &bANY&a.");
|
||||||
Map<Set<Context>, Map<String, String>> options = subjectData.getAllOptions();
|
Map<ImmutableContextSet, Map<String, String>> options = subjectData.getOptions();
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
Util.sendPluginMessage(sender, "That subject does not have any options defined.");
|
Util.sendPluginMessage(sender, "That subject does not have any options defined.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<Set<Context>, Map<String, String>> e : options.entrySet()) {
|
for (Map.Entry<ImmutableContextSet, Map<String, String>> e : options.entrySet()) {
|
||||||
ContextSet set = SpongeUtils.convertContexts(e.getKey());
|
Util.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(e.getKey()) + "\n" + SpongeUtils.optionsToString(e.getValue()));
|
||||||
Util.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(set) + "\n" + SpongeUtils.optionsToString(e.getValue()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Map<String, String> options = subjectData.getOptions(SpongeUtils.convertContexts(contextSet));
|
Map<String, String> options = subjectData.getOptions(contextSet);
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
Util.sendPluginMessage(sender, "That subject does not have any options defined in those contexts.");
|
Util.sendPluginMessage(sender, "That subject does not have any options defined in those contexts.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
|
@ -33,12 +33,11 @@ import me.lucko.luckperms.common.commands.utils.Util;
|
|||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class OptionSet extends SubCommand<SubjectData> {
|
public class OptionSet extends SubCommand<LPSubjectData> {
|
||||||
public OptionSet() {
|
public OptionSet() {
|
||||||
super("set", "Sets an option for the Subject", Permission.SPONGE_OPTION_SET, Predicates.inRange(0, 1),
|
super("set", "Sets an option for the Subject", Permission.SPONGE_OPTION_SET, Predicates.inRange(0, 1),
|
||||||
Arg.list(
|
Arg.list(
|
||||||
@ -50,12 +49,12 @@ public class OptionSet extends SubCommand<SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, SubjectData subjectData, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||||
String key = args.get(0);
|
String key = args.get(0);
|
||||||
String value = args.get(1);
|
String value = args.get(1);
|
||||||
ContextSet contextSet = ArgumentUtils.handleContexts(2, args);
|
ContextSet contextSet = ArgumentUtils.handleContexts(2, args);
|
||||||
|
|
||||||
if (subjectData.setOption(SpongeUtils.convertContexts(contextSet), key, value)) {
|
if (subjectData.setOption(contextSet, key, value)) {
|
||||||
Util.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeUtils.contextToString(contextSet));
|
Util.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeUtils.contextToString(contextSet));
|
||||||
} else {
|
} else {
|
||||||
Util.sendPluginMessage(sender, "Unable to set option. Does the Subject already have it set?");
|
Util.sendPluginMessage(sender, "Unable to set option. Does the Subject already have it set?");
|
||||||
|
@ -33,12 +33,11 @@ import me.lucko.luckperms.common.commands.utils.Util;
|
|||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class OptionUnset extends SubCommand<SubjectData> {
|
public class OptionUnset extends SubCommand<LPSubjectData> {
|
||||||
public OptionUnset() {
|
public OptionUnset() {
|
||||||
super("unset", "Unsets an option for the Subject", Permission.SPONGE_OPTION_UNSET, Predicates.is(0),
|
super("unset", "Unsets an option for the Subject", Permission.SPONGE_OPTION_UNSET, Predicates.is(0),
|
||||||
Arg.list(
|
Arg.list(
|
||||||
@ -49,11 +48,11 @@ public class OptionUnset extends SubCommand<SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, SubjectData subjectData, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||||
String key = args.get(0);
|
String key = args.get(0);
|
||||||
ContextSet contextSet = ArgumentUtils.handleContexts(1, args);
|
ContextSet contextSet = ArgumentUtils.handleContexts(1, args);
|
||||||
|
|
||||||
if (subjectData.setOption(SpongeUtils.convertContexts(contextSet), key, null)) {
|
if (subjectData.setOption(contextSet, key, null)) {
|
||||||
Util.sendPluginMessage(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeUtils.contextToString(contextSet));
|
Util.sendPluginMessage(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeUtils.contextToString(contextSet));
|
||||||
} else {
|
} else {
|
||||||
Util.sendPluginMessage(sender, "Unable to unset option. Are you sure the Subject has it set?");
|
Util.sendPluginMessage(sender, "Unable to unset option. Are you sure the Subject has it set?");
|
||||||
|
@ -33,16 +33,16 @@ import me.lucko.luckperms.common.commands.utils.Util;
|
|||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectCollection;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
|
|
||||||
import org.spongepowered.api.Sponge;
|
import org.spongepowered.api.Sponge;
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ParentAdd extends SubCommand<SubjectData> {
|
public class ParentAdd extends SubCommand<LPSubjectData> {
|
||||||
public ParentAdd() {
|
public ParentAdd() {
|
||||||
super("add", "Adds a parent to the Subject", Permission.SPONGE_PARENT_ADD, Predicates.inRange(0, 1),
|
super("add", "Adds a parent to the Subject", Permission.SPONGE_PARENT_ADD, Predicates.inRange(0, 1),
|
||||||
Arg.list(
|
Arg.list(
|
||||||
@ -54,24 +54,24 @@ public class ParentAdd extends SubCommand<SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, SubjectData subjectData, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||||
String collection = args.get(0);
|
String collection = args.get(0);
|
||||||
String name = args.get(1);
|
String name = args.get(1);
|
||||||
ContextSet contextSet = ArgumentUtils.handleContexts(2, args);
|
ContextSet contextSet = ArgumentUtils.handleContexts(2, args);
|
||||||
|
|
||||||
PermissionService service = Sponge.getServiceManager().provideUnchecked(PermissionService.class);
|
LuckPermsService service = Sponge.getServiceManager().provideUnchecked(LuckPermsService.class);
|
||||||
if (service.getKnownSubjects().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
|
if (service.getCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
|
||||||
Util.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't already exist.");
|
Util.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't already exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
SubjectCollection c = service.getSubjects(collection);
|
LPSubjectCollection c = service.getSubjects(collection);
|
||||||
if (!c.hasRegistered(name)) {
|
if (!c.hasRegistered(name)) {
|
||||||
Util.sendPluginMessage(sender, "Warning: Subject '&4" + name + "&c' doesn't already exist.");
|
Util.sendPluginMessage(sender, "Warning: Subject '&4" + name + "&c' doesn't already exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Subject subject = c.get(name);
|
LPSubject subject = c.get(name);
|
||||||
|
|
||||||
if (subjectData.addParent(SpongeUtils.convertContexts(contextSet), subject)) {
|
if (subjectData.addParent(contextSet, subject.toReference())) {
|
||||||
Util.sendPluginMessage(sender, "&aAdded parent &b" + subject.getContainingCollection().getIdentifier() +
|
Util.sendPluginMessage(sender, "&aAdded parent &b" + subject.getContainingCollection().getIdentifier() +
|
||||||
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeUtils.contextToString(contextSet));
|
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeUtils.contextToString(contextSet));
|
||||||
} else {
|
} else {
|
||||||
|
@ -33,12 +33,11 @@ import me.lucko.luckperms.common.commands.utils.Util;
|
|||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ParentClear extends SubCommand<SubjectData> {
|
public class ParentClear extends SubCommand<LPSubjectData> {
|
||||||
public ParentClear() {
|
public ParentClear() {
|
||||||
super("clear", "Clears the Subjects parents", Permission.SPONGE_PARENT_CLEAR, Predicates.alwaysFalse(),
|
super("clear", "Clears the Subjects parents", Permission.SPONGE_PARENT_CLEAR, Predicates.alwaysFalse(),
|
||||||
Arg.list(
|
Arg.list(
|
||||||
@ -48,13 +47,13 @@ public class ParentClear extends SubCommand<SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, SubjectData subjectData, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||||
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
||||||
if (contextSet.isEmpty()) {
|
if (contextSet.isEmpty()) {
|
||||||
subjectData.clearParents();
|
subjectData.clearParents();
|
||||||
Util.sendPluginMessage(sender, "&aCleared parents matching contexts &bANY&a.");
|
Util.sendPluginMessage(sender, "&aCleared parents matching contexts &bANY&a.");
|
||||||
} else {
|
} else {
|
||||||
subjectData.clearParents(SpongeUtils.convertContexts(contextSet));
|
subjectData.clearParents(contextSet);
|
||||||
Util.sendPluginMessage(sender, "&aCleared parents matching contexts &b" + SpongeUtils.contextToString(contextSet));
|
Util.sendPluginMessage(sender, "&aCleared parents matching contexts &b" + SpongeUtils.contextToString(contextSet));
|
||||||
}
|
}
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
package me.lucko.luckperms.sponge.commands;
|
package me.lucko.luckperms.sponge.commands;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.commands.Arg;
|
import me.lucko.luckperms.common.commands.Arg;
|
||||||
import me.lucko.luckperms.common.commands.CommandException;
|
import me.lucko.luckperms.common.commands.CommandException;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
@ -33,16 +34,14 @@ import me.lucko.luckperms.common.commands.utils.Util;
|
|||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import org.spongepowered.api.service.context.Context;
|
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ParentInfo extends SubCommand<SubjectData> {
|
public class ParentInfo extends SubCommand<LPSubjectData> {
|
||||||
public ParentInfo() {
|
public ParentInfo() {
|
||||||
super("info", "Shows info about the subject's parents", Permission.SPONGE_PARENT_INFO, Predicates.alwaysFalse(),
|
super("info", "Shows info about the subject's parents", Permission.SPONGE_PARENT_INFO, Predicates.alwaysFalse(),
|
||||||
Arg.list(Arg.create("contexts...", false, "the contexts to filter by"))
|
Arg.list(Arg.create("contexts...", false, "the contexts to filter by"))
|
||||||
@ -50,23 +49,22 @@ public class ParentInfo extends SubCommand<SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, SubjectData subjectData, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||||
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
||||||
if (contextSet.isEmpty()) {
|
if (contextSet.isEmpty()) {
|
||||||
Util.sendPluginMessage(sender, "&aShowing parents matching contexts &bANY&a.");
|
Util.sendPluginMessage(sender, "&aShowing parents matching contexts &bANY&a.");
|
||||||
Map<Set<Context>, List<Subject>> parents = subjectData.getAllParents();
|
Map<ImmutableContextSet, Set<SubjectReference>> parents = subjectData.getParents();
|
||||||
if (parents.isEmpty()) {
|
if (parents.isEmpty()) {
|
||||||
Util.sendPluginMessage(sender, "That subject does not have any parents defined.");
|
Util.sendPluginMessage(sender, "That subject does not have any parents defined.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<Set<Context>, List<Subject>> e : parents.entrySet()) {
|
for (Map.Entry<ImmutableContextSet, Set<SubjectReference>> e : parents.entrySet()) {
|
||||||
ContextSet set = SpongeUtils.convertContexts(e.getKey());
|
Util.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(e.getKey()) + "\n" + SpongeUtils.parentsToString(e.getValue()));
|
||||||
Util.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(set) + "\n" + SpongeUtils.parentsToString(e.getValue()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
List<Subject> parents = subjectData.getParents(SpongeUtils.convertContexts(contextSet));
|
Set<SubjectReference> parents = subjectData.getParents(contextSet);
|
||||||
if (parents.isEmpty()) {
|
if (parents.isEmpty()) {
|
||||||
Util.sendPluginMessage(sender, "That subject does not have any parents defined in those contexts.");
|
Util.sendPluginMessage(sender, "That subject does not have any parents defined in those contexts.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
|
@ -33,16 +33,16 @@ import me.lucko.luckperms.common.commands.utils.Util;
|
|||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectCollection;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
|
|
||||||
import org.spongepowered.api.Sponge;
|
import org.spongepowered.api.Sponge;
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ParentRemove extends SubCommand<SubjectData> {
|
public class ParentRemove extends SubCommand<LPSubjectData> {
|
||||||
public ParentRemove() {
|
public ParentRemove() {
|
||||||
super("remove", "Removes a parent from the Subject", Permission.SPONGE_PARENT_REMOVE, Predicates.inRange(0, 1),
|
super("remove", "Removes a parent from the Subject", Permission.SPONGE_PARENT_REMOVE, Predicates.inRange(0, 1),
|
||||||
Arg.list(
|
Arg.list(
|
||||||
@ -54,24 +54,24 @@ public class ParentRemove extends SubCommand<SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, SubjectData subjectData, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||||
String collection = args.get(0);
|
String collection = args.get(0);
|
||||||
String name = args.get(1);
|
String name = args.get(1);
|
||||||
ContextSet contextSet = ArgumentUtils.handleContexts(2, args);
|
ContextSet contextSet = ArgumentUtils.handleContexts(2, args);
|
||||||
|
|
||||||
PermissionService service = Sponge.getServiceManager().provideUnchecked(PermissionService.class);
|
LuckPermsService service = Sponge.getServiceManager().provideUnchecked(LuckPermsService.class);
|
||||||
if (service.getKnownSubjects().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
|
if (service.getCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
|
||||||
Util.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't exist.");
|
Util.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
SubjectCollection c = service.getSubjects(collection);
|
LPSubjectCollection c = service.getSubjects(collection);
|
||||||
if (!c.hasRegistered(name)) {
|
if (!c.hasRegistered(name)) {
|
||||||
Util.sendPluginMessage(sender, "Warning: Subject '&4" + name + "&c' doesn't exist.");
|
Util.sendPluginMessage(sender, "Warning: Subject '&4" + name + "&c' doesn't exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Subject subject = c.get(name);
|
LPSubject subject = c.get(name);
|
||||||
|
|
||||||
if (subjectData.removeParent(SpongeUtils.convertContexts(contextSet), subject)) {
|
if (subjectData.removeParent(contextSet, subject.toReference())) {
|
||||||
Util.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getContainingCollection().getIdentifier() +
|
Util.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getContainingCollection().getIdentifier() +
|
||||||
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeUtils.contextToString(contextSet));
|
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeUtils.contextToString(contextSet));
|
||||||
} else {
|
} else {
|
||||||
|
@ -33,12 +33,11 @@ import me.lucko.luckperms.common.commands.utils.Util;
|
|||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PermissionClear extends SubCommand<SubjectData> {
|
public class PermissionClear extends SubCommand<LPSubjectData> {
|
||||||
public PermissionClear() {
|
public PermissionClear() {
|
||||||
super("clear", "Clears the Subjects permissions", Permission.SPONGE_PERMISSION_CLEAR, Predicates.alwaysFalse(),
|
super("clear", "Clears the Subjects permissions", Permission.SPONGE_PERMISSION_CLEAR, Predicates.alwaysFalse(),
|
||||||
Arg.list(
|
Arg.list(
|
||||||
@ -48,13 +47,13 @@ public class PermissionClear extends SubCommand<SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, SubjectData subjectData, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||||
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
||||||
if (contextSet.isEmpty()) {
|
if (contextSet.isEmpty()) {
|
||||||
subjectData.clearPermissions();
|
subjectData.clearPermissions();
|
||||||
Util.sendPluginMessage(sender, "&aCleared permissions matching contexts &bANY&a.");
|
Util.sendPluginMessage(sender, "&aCleared permissions matching contexts &bANY&a.");
|
||||||
} else {
|
} else {
|
||||||
subjectData.clearPermissions(SpongeUtils.convertContexts(contextSet));
|
subjectData.clearPermissions(contextSet);
|
||||||
Util.sendPluginMessage(sender, "&aCleared permissions matching contexts &b" + SpongeUtils.contextToString(contextSet));
|
Util.sendPluginMessage(sender, "&aCleared permissions matching contexts &b" + SpongeUtils.contextToString(contextSet));
|
||||||
}
|
}
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
package me.lucko.luckperms.sponge.commands;
|
package me.lucko.luckperms.sponge.commands;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.commands.Arg;
|
import me.lucko.luckperms.common.commands.Arg;
|
||||||
import me.lucko.luckperms.common.commands.CommandException;
|
import me.lucko.luckperms.common.commands.CommandException;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
@ -33,15 +34,12 @@ import me.lucko.luckperms.common.commands.utils.Util;
|
|||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import org.spongepowered.api.service.context.Context;
|
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class PermissionInfo extends SubCommand<SubjectData> {
|
public class PermissionInfo extends SubCommand<LPSubjectData> {
|
||||||
public PermissionInfo() {
|
public PermissionInfo() {
|
||||||
super("info", "Shows info about the subject's permissions", Permission.SPONGE_PERMISSION_INFO, Predicates.alwaysFalse(),
|
super("info", "Shows info about the subject's permissions", Permission.SPONGE_PERMISSION_INFO, Predicates.alwaysFalse(),
|
||||||
Arg.list(Arg.create("contexts...", false, "the contexts to filter by"))
|
Arg.list(Arg.create("contexts...", false, "the contexts to filter by"))
|
||||||
@ -49,23 +47,22 @@ public class PermissionInfo extends SubCommand<SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, SubjectData subjectData, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||||
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
ContextSet contextSet = ArgumentUtils.handleContexts(0, args);
|
||||||
if (contextSet.isEmpty()) {
|
if (contextSet.isEmpty()) {
|
||||||
Util.sendPluginMessage(sender, "&aShowing permissions matching contexts &bANY&a.");
|
Util.sendPluginMessage(sender, "&aShowing permissions matching contexts &bANY&a.");
|
||||||
Map<Set<Context>, Map<String, Boolean>> permissions = subjectData.getAllPermissions();
|
Map<ImmutableContextSet, Map<String, Boolean>> permissions = subjectData.getPermissions();
|
||||||
if (permissions.isEmpty()) {
|
if (permissions.isEmpty()) {
|
||||||
Util.sendPluginMessage(sender, "That subject does not have any permissions defined.");
|
Util.sendPluginMessage(sender, "That subject does not have any permissions defined.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<Set<Context>, Map<String, Boolean>> e : permissions.entrySet()) {
|
for (Map.Entry<ImmutableContextSet, Map<String, Boolean>> e : permissions.entrySet()) {
|
||||||
ContextSet set = SpongeUtils.convertContexts(e.getKey());
|
Util.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(e.getKey()) + "\n" + SpongeUtils.nodesToString(e.getValue()));
|
||||||
Util.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(set) + "\n" + SpongeUtils.nodesToString(e.getValue()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Map<String, Boolean> permissions = subjectData.getPermissions(SpongeUtils.convertContexts(contextSet));
|
Map<String, Boolean> permissions = subjectData.getPermissions(contextSet);
|
||||||
if (permissions.isEmpty()) {
|
if (permissions.isEmpty()) {
|
||||||
Util.sendPluginMessage(sender, "That subject does not have any permissions defined in those contexts.");
|
Util.sendPluginMessage(sender, "That subject does not have any permissions defined in those contexts.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.sponge.commands;
|
package me.lucko.luckperms.sponge.commands;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.common.commands.Arg;
|
import me.lucko.luckperms.common.commands.Arg;
|
||||||
import me.lucko.luckperms.common.commands.CommandException;
|
import me.lucko.luckperms.common.commands.CommandException;
|
||||||
@ -33,13 +34,11 @@ import me.lucko.luckperms.common.commands.utils.Util;
|
|||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
import org.spongepowered.api.util.Tristate;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PermissionSet extends SubCommand<SubjectData> {
|
public class PermissionSet extends SubCommand<LPSubjectData> {
|
||||||
public PermissionSet() {
|
public PermissionSet() {
|
||||||
super("set", "Sets a permission for the Subject", Permission.SPONGE_PERMISSION_SET, Predicates.inRange(0, 1),
|
super("set", "Sets a permission for the Subject", Permission.SPONGE_PERMISSION_SET, Predicates.inRange(0, 1),
|
||||||
Arg.list(
|
Arg.list(
|
||||||
@ -51,12 +50,12 @@ public class PermissionSet extends SubCommand<SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, SubjectData subjectData, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||||
String node = args.get(0);
|
String node = args.get(0);
|
||||||
Tristate tristate = SpongeUtils.parseTristate(1, args);
|
Tristate tristate = SpongeUtils.parseTristate(1, args);
|
||||||
ContextSet contextSet = ArgumentUtils.handleContexts(2, args);
|
ContextSet contextSet = ArgumentUtils.handleContexts(2, args);
|
||||||
|
|
||||||
if (subjectData.setPermission(SpongeUtils.convertContexts(contextSet), node, tristate)) {
|
if (subjectData.setPermission(contextSet, node, tristate)) {
|
||||||
Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeUtils.contextToString(contextSet));
|
Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeUtils.contextToString(contextSet));
|
||||||
} else {
|
} else {
|
||||||
Util.sendPluginMessage(sender, "Unable to set permission. Does the Subject already have it set?");
|
Util.sendPluginMessage(sender, "Unable to set permission. Does the Subject already have it set?");
|
||||||
|
@ -39,10 +39,9 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
|||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectCollection;
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -50,26 +49,25 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.StreamSupport;
|
|
||||||
|
|
||||||
public class SpongeMainCommand extends BaseCommand<Void, SubjectData> {
|
public class SpongeMainCommand extends BaseCommand<Void, LPSubjectData> {
|
||||||
private final LPSpongePlugin plugin;
|
private final LPSpongePlugin plugin;
|
||||||
|
|
||||||
private final Map<String, List<Command<SubjectData, ?>>> subCommands = ImmutableMap.<String, List<Command<SubjectData, ?>>>builder()
|
private final Map<String, List<Command<LPSubjectData, ?>>> subCommands = ImmutableMap.<String, List<Command<LPSubjectData, ?>>>builder()
|
||||||
.put("permission", ImmutableList.<Command<SubjectData, ?>>builder()
|
.put("permission", ImmutableList.<Command<LPSubjectData, ?>>builder()
|
||||||
.add(new PermissionInfo())
|
.add(new PermissionInfo())
|
||||||
.add(new PermissionSet())
|
.add(new PermissionSet())
|
||||||
.add(new PermissionClear())
|
.add(new PermissionClear())
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
.put("parent", ImmutableList.<Command<SubjectData, ?>>builder()
|
.put("parent", ImmutableList.<Command<LPSubjectData, ?>>builder()
|
||||||
.add(new ParentInfo())
|
.add(new ParentInfo())
|
||||||
.add(new ParentAdd())
|
.add(new ParentAdd())
|
||||||
.add(new ParentRemove())
|
.add(new ParentRemove())
|
||||||
.add(new ParentClear())
|
.add(new ParentClear())
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
.put("option", ImmutableList.<Command<SubjectData, ?>>builder()
|
.put("option", ImmutableList.<Command<LPSubjectData, ?>>builder()
|
||||||
.add(new OptionInfo())
|
.add(new OptionInfo())
|
||||||
.add(new OptionSet())
|
.add(new OptionSet())
|
||||||
.add(new OptionUnset())
|
.add(new OptionUnset())
|
||||||
@ -119,11 +117,11 @@ public class SpongeMainCommand extends BaseCommand<Void, SubjectData> {
|
|||||||
Util.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + subjectCollection + "&c' doesn't already exist. Creating it now.");
|
Util.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + subjectCollection + "&c' doesn't already exist. Creating it now.");
|
||||||
}
|
}
|
||||||
|
|
||||||
SubjectCollection collection = service.getSubjects(subjectCollection);
|
LPSubjectCollection collection = service.getSubjects(subjectCollection);
|
||||||
|
|
||||||
if (args.size() < 2) {
|
if (args.size() < 2) {
|
||||||
List<String> subjects = StreamSupport.stream(collection.getAllSubjects().spliterator(), false)
|
List<String> subjects = collection.getSubjects().stream()
|
||||||
.map(Subject::getIdentifier)
|
.map(LPSubject::getIdentifier)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
if (subjects.size() > 50) {
|
if (subjects.size() > 50) {
|
||||||
@ -156,7 +154,7 @@ public class SpongeMainCommand extends BaseCommand<Void, SubjectData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String cmd = args.get(3);
|
String cmd = args.get(3);
|
||||||
Optional<Command<SubjectData, ?>> o = subCommands.get(type).stream()
|
Optional<Command<LPSubjectData, ?>> o = subCommands.get(type).stream()
|
||||||
.filter(s -> s.getName().equalsIgnoreCase(cmd))
|
.filter(s -> s.getName().equalsIgnoreCase(cmd))
|
||||||
.findAny();
|
.findAny();
|
||||||
|
|
||||||
@ -165,7 +163,7 @@ public class SpongeMainCommand extends BaseCommand<Void, SubjectData> {
|
|||||||
return CommandResult.INVALID_ARGS;
|
return CommandResult.INVALID_ARGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Command<SubjectData, ?> sub = o.get();
|
final Command<LPSubjectData, ?> sub = o.get();
|
||||||
if (!sub.isAuthorized(sender)) {
|
if (!sub.isAuthorized(sender)) {
|
||||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||||
return CommandResult.NO_PERMISSION;
|
return CommandResult.NO_PERMISSION;
|
||||||
@ -186,8 +184,8 @@ public class SpongeMainCommand extends BaseCommand<Void, SubjectData> {
|
|||||||
Util.sendPluginMessage(sender, "Warning: Subject '&4" + subjectId + "&c' doesn't already exist. Creating it now.");
|
Util.sendPluginMessage(sender, "Warning: Subject '&4" + subjectId + "&c' doesn't already exist. Creating it now.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Subject subject = collection.get(subjectId);
|
LPSubject subject = collection.get(subjectId);
|
||||||
SubjectData subjectData = persistent ? subject.getSubjectData() : subject.getTransientSubjectData();
|
LPSubjectData subjectData = persistent ? subject.getSubjectData() : subject.getTransientSubjectData();
|
||||||
|
|
||||||
CommandResult result;
|
CommandResult result;
|
||||||
try {
|
try {
|
||||||
@ -232,12 +230,12 @@ public class SpongeMainCommand extends BaseCommand<Void, SubjectData> {
|
|||||||
return "/%s sponge <collection> <subject>";
|
return "/%s sponge <collection> <subject>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Command<SubjectData, ?>> getSubCommands() {
|
public List<Command<LPSubjectData, ?>> getSubCommands() {
|
||||||
return subCommands.values().stream().flatMap(List::stream).collect(ImmutableCollectors.toImmutableList());
|
return subCommands.values().stream().flatMap(List::stream).collect(ImmutableCollectors.toImmutableList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<List<Command<SubjectData, ?>>> getChildren() {
|
public Optional<List<Command<LPSubjectData, ?>>> getChildren() {
|
||||||
return Optional.of(getSubCommands());
|
return Optional.of(getSubCommands());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,19 +24,14 @@ package me.lucko.luckperms.sponge.commands;
|
|||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
|
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||||
import org.spongepowered.api.service.context.Context;
|
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
|
||||||
import org.spongepowered.api.util.Tristate;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class SpongeUtils {
|
public class SpongeUtils {
|
||||||
@ -78,13 +73,13 @@ public class SpongeUtils {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parentsToString(List<Subject> parents) {
|
public static String parentsToString(Set<SubjectReference> parents) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Subject s : parents) {
|
for (SubjectReference s : parents) {
|
||||||
sb.append("&3> &a")
|
sb.append("&3> &a")
|
||||||
.append(s.getIdentifier())
|
.append(s.getIdentifier())
|
||||||
.append(" &bfrom collection &a")
|
.append(" &bfrom collection &a")
|
||||||
.append(s.getContainingCollection().getIdentifier())
|
.append(s.getCollection())
|
||||||
.append("&b.\n");
|
.append("&b.\n");
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
@ -102,12 +97,4 @@ public class SpongeUtils {
|
|||||||
return sb.delete(sb.length() - 2, sb.length()).toString();
|
return sb.delete(sb.length() - 2, sb.length()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContextSet convertContexts(Set<Context> contexts) {
|
|
||||||
return ContextSet.fromEntries(contexts.stream().map(c -> Maps.immutableEntry(c.getKey(), c.getValue())).collect(Collectors.toSet()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<Context> convertContexts(ContextSet contexts) {
|
|
||||||
return contexts.toSet().stream().map(e -> new Context(e.getKey(), e.getValue())).collect(Collectors.toSet());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user