Update internal permissions to match the new command layouts

This commit is contained in:
Luck 2016-10-19 20:14:16 +01:00
parent c66a01c1a6
commit ce3d7829d7
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
29 changed files with 228 additions and 157 deletions

View File

@ -37,6 +37,7 @@ import me.lucko.luckperms.common.calculators.CalculatorFactory;
import me.lucko.luckperms.common.commands.ConsecutiveExecutor;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.config.LPConfiguration;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.contexts.ContextManager;
import me.lucko.luckperms.common.contexts.ServerCalculator;
import me.lucko.luckperms.common.core.UuidCache;
@ -53,7 +54,6 @@ import me.lucko.luckperms.common.utils.LogFactory;
import org.bukkit.World;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.ServicePriority;
@ -355,30 +355,10 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
private void registerPermissions(PermissionDefault def) {
PluginManager pm = getServer().getPluginManager();
Map<String, List<String>> wildcards = new HashMap<>();
List<String> all = new ArrayList<>();
for (me.lucko.luckperms.common.constants.Permission p : me.lucko.luckperms.common.constants.Permission.values()) {
pm.addPermission(new Permission(p.getNode(), def));
if (p.getGroup() != null) {
if (!wildcards.containsKey(p.getGroup())) {
wildcards.put(p.getGroup(), new ArrayList<>());
}
wildcards.get(p.getGroup()).add(p.getTag());
for (Permission p : Permission.values()) {
for (String node : p.getNodes()) {
pm.addPermission(new org.bukkit.permissions.Permission(node, def));
}
all.add(p.getNode());
}
for (Map.Entry<String, List<String>> e : wildcards.entrySet()) {
pm.addPermission(new Permission(
"luckperms." + e.getKey() + ".*", def,
e.getValue().stream()
.map(tag -> "luckperms." + e.getKey() + "." + tag)
.collect(Collectors.toMap(s -> s, s -> true))
)
);
}
pm.addPermission(new Permission("luckperms.*", def, all.stream().collect(Collectors.toMap(s -> s, s -> true))));
}
}

View File

@ -22,17 +22,16 @@
package me.lucko.luckperms.common.commands;
import com.google.common.collect.ImmutableMap;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import java.lang.ref.WeakReference;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
/**
* Factory class to make a thread-safe sender instance
@ -100,12 +99,15 @@ public abstract class SenderFactory<T> implements Runnable {
this.console = this.uuid.equals(Constants.getConsoleUUID()) || this.uuid.equals(Constants.getImporterUUID());
if (!this.console) {
if (toCheck == null || toCheck.isEmpty()) {
this.perms = ImmutableMap.copyOf(Arrays.stream(Permission.values())
.collect(Collectors.toMap(p -> p, p -> factory.hasPermission(t, p.getNode()))));
} else {
this.perms = ImmutableMap.copyOf(toCheck.stream().collect(Collectors.toMap(p -> p, p -> factory.hasPermission(t, p.getNode()))));
}
this.perms = ((toCheck == null || toCheck.isEmpty()) ? Arrays.stream(Permission.values()) : toCheck.stream())
.collect(ImmutableCollectors.toImmutableMap(p -> p, p -> {
for (String s : p.getNodes()) {
if (factory.hasPermission(t, s)) {
return true;
}
}
return false;
}));
}
}

View File

@ -40,7 +40,7 @@ import java.util.List;
public class MetaAddPrefix extends SecondarySubCommand {
public MetaAddPrefix() {
super("addprefix", "Adds a prefix", Permission.USER_ADDPREFIX, Permission.GROUP_ADDPREFIX, Predicate.notInRange(2, 4),
super("addprefix", "Adds a prefix", Permission.USER_META_ADDPREFIX, Permission.GROUP_META_ADDPREFIX, Predicate.notInRange(2, 4),
Arg.list(
Arg.create("priority", true, "the priority to add the prefix at"),
Arg.create("prefix", true, "the prefix string"),

View File

@ -40,7 +40,7 @@ import java.util.List;
public class MetaAddSuffix extends SecondarySubCommand {
public MetaAddSuffix() {
super("addsuffix", "Adds a suffix", Permission.USER_ADDSUFFIX, Permission.GROUP_ADDSUFFIX, Predicate.notInRange(2, 4),
super("addsuffix", "Adds a suffix", Permission.USER_META_ADDSUFFIX, Permission.GROUP_META_ADDSUFFIX, Predicate.notInRange(2, 4),
Arg.list(
Arg.create("priority", true, "the priority to add the suffix at"),
Arg.create("suffix", true, "the suffix string"),

View File

@ -41,7 +41,7 @@ import java.util.List;
public class MetaAddTempPrefix extends SecondarySubCommand {
public MetaAddTempPrefix() {
super("addtempprefix", "Adds a prefix temporarily", Permission.USER_ADD_TEMP_PREFIX, Permission.GROUP_ADD_TEMP_PREFIX, Predicate.notInRange(3, 5),
super("addtempprefix", "Adds a prefix temporarily", Permission.USER_META_ADDTEMP_PREFIX, Permission.GROUP_META_ADDTEMP_PREFIX, Predicate.notInRange(3, 5),
Arg.list(
Arg.create("priority", true, "the priority to add the prefix at"),
Arg.create("prefix", true, "the prefix string"),

View File

@ -41,7 +41,7 @@ import java.util.List;
public class MetaAddTempSuffix extends SecondarySubCommand {
public MetaAddTempSuffix() {
super("addtempsuffix", "Adds a suffix temporarily", Permission.USER_ADD_TEMP_SUFFIX, Permission.GROUP_ADD_TEMP_SUFFIX, Predicate.notInRange(3, 5),
super("addtempsuffix", "Adds a suffix temporarily", Permission.USER_META_ADDTEMP_SUFFIX, Permission.GROUP_META_ADDTEMP_SUFFIX, Predicate.notInRange(3, 5),
Arg.list(
Arg.create("priority", true, "the priority to add the suffix at"),
Arg.create("suffix", true, "the suffix string"),

View File

@ -39,7 +39,7 @@ import java.util.stream.Collectors;
public class MetaClear extends SecondarySubCommand {
public MetaClear() {
super("clear", "Clears all chat meta", Permission.USER_CLEARMETA, Permission.GROUP_CLEARMETA, Predicate.notInRange(0, 2),
super("clear", "Clears all chat meta", Permission.USER_META_CLEAR, Permission.GROUP_META_CLEAR, Predicate.notInRange(0, 2),
Arg.list(
Arg.create("server", false, "the server name to filter by"),
Arg.create("world", false, "the world name to filter by")

View File

@ -38,7 +38,7 @@ import java.util.*;
public class MetaInfo extends SecondarySubCommand {
public MetaInfo() {
super("info", "Shows all chat meta", Permission.USER_CHATMETA, Permission.GROUP_CHATMETA, Predicate.alwaysFalse(), null);
super("info", "Shows all chat meta", Permission.USER_META_INFO, Permission.GROUP_META_INFO, Predicate.alwaysFalse(), null);
}
@Override

View File

@ -42,7 +42,7 @@ import java.util.List;
public class MetaRemovePrefix extends SecondarySubCommand {
public MetaRemovePrefix() {
super("removeprefix", "Removes a prefix", Permission.USER_REMOVEPREFIX, Permission.GROUP_REMOVEPREFIX, Predicate.notInRange(2, 4),
super("removeprefix", "Removes a prefix", Permission.USER_META_REMOVEPREFIX, Permission.GROUP_META_REMOVEPREFIX, Predicate.notInRange(2, 4),
Arg.list(
Arg.create("priority", true, "the priority to add the prefix at"),
Arg.create("prefix", true, "the prefix string"),

View File

@ -42,7 +42,7 @@ import java.util.List;
public class MetaRemoveSuffix extends SecondarySubCommand {
public MetaRemoveSuffix() {
super("removesuffix", "Removes a suffix", Permission.USER_REMOVESUFFIX, Permission.GROUP_REMOVESUFFIX, Predicate.notInRange(2, 4),
super("removesuffix", "Removes a suffix", Permission.USER_META_REMOVESUFFIX, Permission.GROUP_META_REMOVESUFFIX, Predicate.notInRange(2, 4),
Arg.list(
Arg.create("priority", true, "the priority to add the suffix at"),
Arg.create("suffix", true, "the suffix string"),

View File

@ -42,7 +42,7 @@ import java.util.List;
public class MetaRemoveTempPrefix extends SecondarySubCommand {
public MetaRemoveTempPrefix() {
super("removetempprefix", "Removes a temporary prefix", Permission.USER_REMOVE_TEMP_PREFIX, Permission.GROUP_REMOVE_TEMP_PREFIX, Predicate.notInRange(2, 4),
super("removetempprefix", "Removes a temporary prefix", Permission.USER_META_REMOVETEMP_PREFIX, Permission.GROUP_META_REMOVETEMP_PREFIX, Predicate.notInRange(2, 4),
Arg.list(
Arg.create("priority", true, "the priority to add the prefix at"),
Arg.create("prefix", true, "the prefix string"),

View File

@ -42,7 +42,7 @@ import java.util.List;
public class MetaRemoveTempSuffix extends SecondarySubCommand {
public MetaRemoveTempSuffix() {
super("removetempsuffix", "Removes a temporary suffix", Permission.USER_REMOVE_TEMP_SUFFIX, Permission.GROUP_REMOVE_TEMP_SUFFIX, Predicate.notInRange(2, 4),
super("removetempsuffix", "Removes a temporary suffix", Permission.USER_META_REMOVETEMP_SUFFIX, Permission.GROUP_META_REMOVETEMP_SUFFIX, Predicate.notInRange(2, 4),
Arg.list(
Arg.create("priority", true, "the priority to add the suffix at"),
Arg.create("suffix", true, "the suffix string"),

View File

@ -41,7 +41,7 @@ import java.util.List;
public class MetaSet extends SecondarySubCommand {
public MetaSet() {
super("set", "Sets a meta value", Permission.USER_SET_META, Permission.GROUP_SET_META, Predicate.notInRange(2, 4),
super("set", "Sets a meta value", Permission.USER_META_SET, Permission.GROUP_META_SET, Predicate.notInRange(2, 4),
Arg.list(
Arg.create("key", true, "the key to set"),
Arg.create("value", true, "the value to set"),

View File

@ -42,7 +42,7 @@ import java.util.List;
public class MetaSetTemp extends SecondarySubCommand {
public MetaSetTemp() {
super("settemp", "Sets a meta value temporarily", Permission.USER_SET_TEMP_META, Permission.GROUP_SET_TEMP_META, Predicate.notInRange(3, 5),
super("settemp", "Sets a meta value temporarily", Permission.USER_META_SETTEMP, Permission.GROUP_META_SETTEMP, Predicate.notInRange(3, 5),
Arg.list(
Arg.create("key", true, "the key to set"),
Arg.create("value", true, "the value to set"),

View File

@ -40,7 +40,7 @@ import java.util.stream.Collectors;
public class MetaUnset extends SecondarySubCommand {
public MetaUnset() {
super("unset", "Unsets a meta value", Permission.USER_UNSET_META, Permission.GROUP_UNSET_META, Predicate.notInRange(1, 3),
super("unset", "Unsets a meta value", Permission.USER_META_UNSET, Permission.GROUP_META_UNSET, Predicate.notInRange(1, 3),
Arg.list(
Arg.create("key", true, "the key to unset"),
Arg.create("server", false, "the server to remove the meta pair on"),

View File

@ -40,7 +40,7 @@ import java.util.stream.Collectors;
public class MetaUnsetTemp extends SecondarySubCommand {
public MetaUnsetTemp() {
super("unset", "Unsets a temporary meta value", Permission.USER_UNSET_TEMP_META, Permission.GROUP_UNSET_TEMP_META, Predicate.notInRange(1, 3),
super("unsettemp", "Unsets a temporary meta value", Permission.USER_META_UNSETTEMP, Permission.GROUP_META_UNSETTEMP, Predicate.notInRange(1, 3),
Arg.list(
Arg.create("key", true, "the key to unset"),
Arg.create("server", false, "the server to remove the meta pair on"),

View File

@ -43,7 +43,7 @@ import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete;
public class ParentAdd extends SecondarySubCommand {
public ParentAdd() {
super("add", "Sets another group for the object to inherit permissions from",
Permission.USER_ADDGROUP, Permission.GROUP_SETINHERIT, Predicate.notInRange(1, 3),
Permission.USER_PARENT_ADD, Permission.GROUP_PARENT_ADD, Predicate.notInRange(1, 3),
Arg.list(
Arg.create("group", true, "the group to inherit from"),
Arg.create("server", false, "the server to inherit the group on"),

View File

@ -44,7 +44,7 @@ import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete;
public class ParentAddTemp extends SecondarySubCommand {
public ParentAddTemp() {
super("addtemp", "Sets another group for the object to inherit permissions from temporarily",
Permission.USER_ADDTEMPGROUP, Permission.GROUP_SET_TEMP_INHERIT, Predicate.notInRange(2, 4),
Permission.USER_PARENT_ADDTEMP, Permission.GROUP_PARENT_ADDTEMP, Predicate.notInRange(2, 4),
Arg.list(
Arg.create("group", true, "the group to inherit from"),
Arg.create("duration", true, "the duration of the group membership"),

View File

@ -37,7 +37,7 @@ import java.util.List;
public class ParentInfo extends SecondarySubCommand {
public ParentInfo() {
super("info", "Lists the groups that this object inherits from",
Permission.USER_LISTGROUPS, Permission.GROUP_LISTPARENTS, Predicate.alwaysFalse(), null);
Permission.USER_PARENT_INFO, Permission.GROUP_PARENT_INFO, Predicate.alwaysFalse(), null);
}
@Override

View File

@ -42,7 +42,7 @@ import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete;
public class ParentRemove extends SecondarySubCommand {
public ParentRemove() {
super("remove", "Removes a previously set inheritance rule", Permission.USER_REMOVEGROUP, Permission.GROUP_UNSETINHERIT,
super("remove", "Removes a previously set inheritance rule", Permission.USER_PARENT_REMOVE, Permission.GROUP_PARENT_REMOVE,
Predicate.notInRange(1, 3),
Arg.list(
Arg.create("group", true, "the group to remove"),

View File

@ -42,7 +42,7 @@ import static me.lucko.luckperms.common.commands.SubCommand.getGroupTabComplete;
public class ParentRemoveTemp extends SecondarySubCommand {
public ParentRemoveTemp() {
super("removetemp", "Removes a previously set temporary inheritance rule",
Permission.USER_REMOVETEMPGROUP, Permission.GROUP_UNSET_TEMP_INHERIT, Predicate.notInRange(1, 3),
Permission.USER_PARENT_REMOVETEMP, Permission.GROUP_PARENT_REMOVETEMP, Predicate.notInRange(1, 3),
Arg.list(
Arg.create("group", true, "the group to remove"),
Arg.create("server", false, "the server to remove the group on"),

View File

@ -36,7 +36,7 @@ import java.util.List;
public class PermissionInfo extends SecondarySubCommand {
public PermissionInfo() {
super("info", "Lists the permission nodes the object has", Permission.USER_LISTNODES, Permission.GROUP_LISTNODES, Predicate.alwaysFalse(), null);
super("info", "Lists the permission nodes the object has", Permission.USER_PERM_INFO, Permission.GROUP_PERM_INFO, Predicate.alwaysFalse(), null);
}
@Override

View File

@ -41,7 +41,7 @@ import static me.lucko.luckperms.common.commands.SubCommand.getBoolTabComplete;
public class PermissionSet extends SecondarySubCommand {
public PermissionSet() {
super("set", "Sets a permission for the object", Permission.USER_SETPERMISSION, Permission.GROUP_SETPERMISSION, Predicate.notInRange(2, 4),
super("set", "Sets a permission for the object", Permission.USER_PERM_SET, Permission.GROUP_PERM_SET, Predicate.notInRange(2, 4),
Arg.list(
Arg.create("node", true, "the permission node to set"),
Arg.create("true|false", true, "the value of the node"),

View File

@ -42,7 +42,7 @@ import static me.lucko.luckperms.common.commands.SubCommand.getBoolTabComplete;
public class PermissionSetTemp extends SecondarySubCommand {
public PermissionSetTemp() {
super("settemp", "Sets a permission for the object temporarily", Permission.USER_SET_TEMP_PERMISSION, Permission.GROUP_SET_TEMP_PERMISSION,
super("settemp", "Sets a permission for the object temporarily", Permission.USER_PERM_SETTEMP, Permission.GROUP_PERM_SETTEMP,
Predicate.notInRange(3, 5),
Arg.list(
Arg.create("node", true, "the permission node to set"),

View File

@ -39,7 +39,7 @@ import java.util.List;
public class PermissionUnset extends SecondarySubCommand {
public PermissionUnset() {
super("unset", "Unsets a permission for the object", Permission.USER_UNSETPERMISSION, Permission.GROUP_UNSETPERMISSION, Predicate.notInRange(1, 3),
super("unset", "Unsets a permission for the object", Permission.USER_PERM_UNSET, Permission.GROUP_PERM_UNSET, Predicate.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to unset"),
Arg.create("server", false, "the server to remove the permission node on"),

View File

@ -39,7 +39,7 @@ import java.util.List;
public class PermissionUnsetTemp extends SecondarySubCommand {
public PermissionUnsetTemp() {
super("unsettemp", "Unsets a temporary permission for the object", Permission.USER_UNSET_TEMP_PERMISSION, Permission.GROUP_UNSET_TEMP_PERMISSION,
super("unsettemp", "Unsets a temporary permission for the object", Permission.USER_PERM_UNSETTEMP, Permission.GROUP_PERM_UNSETTEMP,
Predicate.notInRange(1, 3),
Arg.list(
Arg.create("node", true, "the permission node to unset"),

View File

@ -22,128 +22,153 @@
package me.lucko.luckperms.common.constants;
import com.google.common.collect.Sets;
import lombok.AllArgsConstructor;
import lombok.Getter;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import java.util.Set;
@SuppressWarnings("SpellCheckingInspection")
@Getter
@AllArgsConstructor
public enum Permission {
SYNC("sync", null),
INFO("info", null),
DEBUG("debug", null),
IMPORT("import", null),
SYNC(set("sync"), Type.NONE),
INFO(set("info"), Type.NONE),
DEBUG(set("debug"), Type.NONE),
IMPORT(set("import"), Type.NONE),
CREATE_GROUP("creategroup", null),
DELETE_GROUP("deletegroup", null),
LIST_GROUPS("listgroups", null),
CREATE_GROUP(set("creategroup"), Type.NONE),
DELETE_GROUP(set("deletegroup"), Type.NONE),
LIST_GROUPS(set("listgroups"), Type.NONE),
CREATE_TRACK("createtrack", null),
DELETE_TRACK("deletetrack", null),
LIST_TRACKS("listtracks", null),
CREATE_TRACK(set("createtrack"), Type.NONE),
DELETE_TRACK(set("deletetrack"), Type.NONE),
LIST_TRACKS(set("listtracks"), Type.NONE),
USER_INFO("info", "user"),
USER_GETUUID("getuuid", "user"),
USER_LISTNODES("listnodes", "user"),
USER_LISTGROUPS("listgroups", "user"),
USER_HASPERMISSION("haspermission", "user"),
USER_INHERITSPERMISSION("inheritspermission", "user"),
USER_SETPERMISSION("setpermission", "user"),
USER_UNSETPERMISSION("unsetpermission", "user"),
USER_ADDGROUP("addgroup", "user"),
USER_REMOVEGROUP("removegroup", "user"),
USER_SET_TEMP_PERMISSION("settemppermission", "user"),
USER_UNSET_TEMP_PERMISSION("unsettemppermission", "user"),
USER_ADDTEMPGROUP("addtempgroup", "user"),
USER_REMOVETEMPGROUP("removetempgroup", "user"),
USER_SETPRIMARYGROUP("setprimarygroup", "user"),
USER_SHOWTRACKS("showtracks", "user"),
USER_PROMOTE("promote", "user"),
USER_DEMOTE("demote", "user"),
USER_SHOWPOS("showpos", "user"),
USER_CHATMETA("chatmeta", "user"),
USER_ADDPREFIX("addprefix", "user"),
USER_REMOVEPREFIX("removeprefix", "user"),
USER_ADDSUFFIX("addsuffix", "user"),
USER_REMOVESUFFIX("removesuffix", "user"),
USER_ADD_TEMP_PREFIX("addtempprefix", "user"),
USER_REMOVE_TEMP_PREFIX("removetempprefix", "user"),
USER_ADD_TEMP_SUFFIX("addtempsuffix", "user"),
USER_REMOVE_TEMP_SUFFIX("removetempsuffix", "user"),
USER_SET_META("setmeta", "user"),
USER_UNSET_META("unsetmeta", "user"),
USER_SET_TEMP_META("settempmeta", "user"),
USER_UNSET_TEMP_META("unsettempmeta", "user"),
USER_CLEARMETA("clearmeta", "user"),
USER_BULKCHANGE("bulkchange", "user"),
USER_CLEAR("clear", "user"),
USER_INFO(set("info"), Type.USER),
USER_PERM_INFO(set("permission.info", "listnodes"), Type.USER),
USER_PERM_SET(set("permission.set", "setpermission"), Type.USER),
USER_PERM_UNSET(set("permission.unset", "unsetpermission"), Type.USER),
USER_PERM_SETTEMP(set("permission.settemp", "settemppermission"), Type.USER),
USER_PERM_UNSETTEMP(set("permission.unsettemp", "unsettemppermission"), Type.USER),
USER_PARENT_INFO(set("parent.info", "listgroups"), Type.USER),
USER_PARENT_ADD(set("parent.add", "addgroup"), Type.USER),
USER_PARENT_REMOVE(set("parent.remove", "removegroup"), Type.USER),
USER_PARENT_ADDTEMP(set("parent.addtemp", "addtempgroup"), Type.USER),
USER_PARENT_REMOVETEMP(set("parent.removetemp", "removetempgroup"), Type.USER),
USER_META_INFO(set("meta.info", "chatmeta"), Type.USER),
USER_META_SET(set("meta.set", "setmeta"), Type.USER),
USER_META_UNSET(set("meta.unset", "unsetmeta"), Type.USER),
USER_META_SETTEMP(set("meta.settemp", "settempmeta"), Type.USER),
USER_META_UNSETTEMP(set("meta.unsettemp", "unsettempmeta"), Type.USER),
USER_META_ADDPREFIX(set("meta.addprefix", "addprefix"), Type.USER),
USER_META_ADDSUFFIX(set("meta.addsuffix", "addsuffix"), Type.USER),
USER_META_REMOVEPREFIX(set("meta.removeprefix", "removeprefix"), Type.USER),
USER_META_REMOVESUFFIX(set("meta.removesuffix", "removesuffix"), Type.USER),
USER_META_ADDTEMP_PREFIX(set("meta.addtempprefix", "addtempprefix"), Type.USER),
USER_META_ADDTEMP_SUFFIX(set("meta.addtempsuffix", "addtempsuffix"), Type.USER),
USER_META_REMOVETEMP_PREFIX(set("meta.removetempprefix", "removetempprefix"), Type.USER),
USER_META_REMOVETEMP_SUFFIX(set("meta.removetempsuffix", "removetempsuffix"), Type.USER),
USER_META_CLEAR(set("meta.clear", "clearmeta"), Type.USER),
USER_GETUUID(set("getuuid"), Type.USER),
USER_HASPERMISSION(set("haspermission"), Type.USER),
USER_INHERITSPERMISSION(set("inheritspermission"), Type.USER),
USER_SETPRIMARYGROUP(set("setprimarygroup"), Type.USER),
USER_SHOWTRACKS(set("showtracks"), Type.USER),
USER_PROMOTE(set("promote"), Type.USER),
USER_DEMOTE(set("demote"), Type.USER),
USER_SHOWPOS(set("showpos"), Type.USER),
USER_BULKCHANGE(set("bulkchange"), Type.USER),
USER_CLEAR(set("clear"), Type.USER),
GROUP_INFO("info", "group"),
GROUP_LISTNODES("listnodes", "group"),
GROUP_LISTPARENTS("listparents", "group"),
GROUP_HASPERMISSION("haspermission", "group"),
GROUP_INHERITSPERMISSION("inheritspermission", "group"),
GROUP_SETPERMISSION("setpermission", "group"),
GROUP_UNSETPERMISSION("unsetpermission", "group"),
GROUP_SETINHERIT("setinherit", "group"),
GROUP_UNSETINHERIT("unsetinherit", "group"),
GROUP_SET_TEMP_PERMISSION("settemppermission", "group"),
GROUP_UNSET_TEMP_PERMISSION("unsettemppermission", "group"),
GROUP_SET_TEMP_INHERIT("settempinherit", "group"),
GROUP_UNSET_TEMP_INHERIT("unsettempinherit", "group"),
GROUP_SHOWTRACKS("showtracks", "group"),
GROUP_CHATMETA("chatmeta", "group"),
GROUP_ADDPREFIX("addprefix", "group"),
GROUP_REMOVEPREFIX("removeprefix", "group"),
GROUP_ADDSUFFIX("addsuffix", "group"),
GROUP_REMOVESUFFIX("removesuffix", "group"),
GROUP_ADD_TEMP_PREFIX("addtempprefix", "group"),
GROUP_REMOVE_TEMP_PREFIX("removetempprefix", "group"),
GROUP_ADD_TEMP_SUFFIX("addtempsuffix", "group"),
GROUP_REMOVE_TEMP_SUFFIX("removetempsuffix", "group"),
GROUP_SET_META("setmeta", "group"),
GROUP_UNSET_META("unsetmeta", "group"),
GROUP_SET_TEMP_META("settempmeta", "group"),
GROUP_UNSET_TEMP_META("unsettempmeta", "group"),
GROUP_CLEARMETA("clearmeta", "group"),
GROUP_BULKCHANGE("bulkchange", "group"),
GROUP_CLEAR("clear", "group"),
GROUP_RENAME("rename", "group"),
GROUP_CLONE("clone", "group"),
GROUP_INFO(set("info"), Type.GROUP),
GROUP_PERM_INFO(set("permission.info", "listnodes"), Type.GROUP),
GROUP_PERM_SET(set("permission.set", "setpermission"), Type.GROUP),
GROUP_PERM_UNSET(set("permission.unset", "unsetpermission"), Type.GROUP),
GROUP_PERM_SETTEMP(set("permission.settemp", "settemppermission"), Type.GROUP),
GROUP_PERM_UNSETTEMP(set("permission.unsettemp", "unsettemppermission"), Type.GROUP),
GROUP_PARENT_INFO(set("parent.info", "listparents"), Type.GROUP),
GROUP_PARENT_ADD(set("parent.add", "setinherit"), Type.GROUP),
GROUP_PARENT_REMOVE(set("parent.remove", "unsetinherit"), Type.GROUP),
GROUP_PARENT_ADDTEMP(set("parent.addtemp", "settempinherit"), Type.GROUP),
GROUP_PARENT_REMOVETEMP(set("parent.removetemp", "unsettempinherit"), Type.GROUP),
GROUP_META_INFO(set("meta.info", "chatmeta"), Type.GROUP),
GROUP_META_SET(set("meta.set", "setmeta"), Type.GROUP),
GROUP_META_UNSET(set("meta.unset", "unsetmeta"), Type.GROUP),
GROUP_META_SETTEMP(set("meta.settemp", "settempmeta"), Type.GROUP),
GROUP_META_UNSETTEMP(set("meta.unsettemp", "unsettempmeta"), Type.GROUP),
GROUP_META_ADDPREFIX(set("meta.addprefix", "addprefix"), Type.GROUP),
GROUP_META_ADDSUFFIX(set("meta.addsuffix", "addsuffix"), Type.GROUP),
GROUP_META_REMOVEPREFIX(set("meta.removeprefix", "removeprefix"), Type.GROUP),
GROUP_META_REMOVESUFFIX(set("meta.removesuffix", "removesuffix"), Type.GROUP),
GROUP_META_ADDTEMP_PREFIX(set("meta.addtempprefix", "addtempprefix"), Type.GROUP),
GROUP_META_ADDTEMP_SUFFIX(set("meta.addtempsuffix", "addtempsuffix"), Type.GROUP),
GROUP_META_REMOVETEMP_PREFIX(set("meta.removetempprefix", "removetempprefix"), Type.GROUP),
GROUP_META_REMOVETEMP_SUFFIX(set("meta.removetempsuffix", "removetempsuffix"), Type.GROUP),
GROUP_META_CLEAR(set("meta.clear", "clearmeta"), Type.GROUP),
GROUP_HASPERMISSION(set("haspermission"), Type.GROUP),
GROUP_INHERITSPERMISSION(set("inheritspermission"), Type.GROUP),
GROUP_SHOWTRACKS(set("showtracks"), Type.GROUP),
GROUP_BULKCHANGE(set("bulkchange"), Type.GROUP),
GROUP_CLEAR(set("clear"), Type.GROUP),
GROUP_RENAME(set("rename"), Type.GROUP),
GROUP_CLONE(set("clone"), Type.GROUP),
TRACK_INFO("info", "track"),
TRACK_APPEND("append", "track"),
TRACK_INSERT("insert", "track"),
TRACK_REMOVE("remove", "track"),
TRACK_CLEAR("clear", "track"),
TRACK_RENAME("rename", "track"),
TRACK_CLONE("clone", "track"),
TRACK_INFO(set("info"), Type.TRACK),
TRACK_APPEND(set("append"), Type.TRACK),
TRACK_INSERT(set("insert"), Type.TRACK),
TRACK_REMOVE(set("remove"), Type.TRACK),
TRACK_CLEAR(set("clear"), Type.TRACK),
TRACK_RENAME(set("rename"), Type.TRACK),
TRACK_CLONE(set("clone"), Type.TRACK),
LOG_RECENT("recent", "log"),
LOG_USER_HISTORY("userhistory", "log"),
LOG_GROUP_HISTORY("grouphistory", "log"),
LOG_TRACK_HISTORY("trackhistory", "log"),
LOG_SEARCH("search", "log"),
LOG_NOTIFY("notify", "log"),
LOG_EXPORT("export", "log"),
LOG_RECENT(set("recent"), Type.LOG),
LOG_USER_HISTORY(set("userhistory"), Type.LOG),
LOG_GROUP_HISTORY(set("grouphistory"), Type.LOG),
LOG_TRACK_HISTORY(set("trackhistory"), Type.LOG),
LOG_SEARCH(set("search"), Type.LOG),
LOG_NOTIFY(set("notify"), Type.LOG),
LOG_EXPORT(set("export"), Type.LOG),
MIGRATION("migration", null);
MIGRATION(set("migration"), Type.NONE);
private String tag;
private String group;
private static final String IDENTIFIER = "luckperms.";
public String getNode() {
if (group != null) {
return "luckperms." + group + "." + tag;
private Set<String> nodes;
private Type type;
Permission(Set<String> tags, Type type) {
this.type = type;
if (type == Type.NONE) {
this.nodes = tags.stream().map(t -> IDENTIFIER + t).collect(ImmutableCollectors.toImmutableSet());
} else {
this.nodes = tags.stream().map(t -> IDENTIFIER + type.getTag() + "." + t).collect(ImmutableCollectors.toImmutableSet());
}
return "luckperms." + tag;
}
public boolean isAuthorized(Sender sender) {
return sender.hasPermission(this);
}
private static Set<String> set(String... args) {
return Sets.newHashSet(args);
}
@Getter
@AllArgsConstructor
public enum Type {
NONE(null),
USER("user"),
GROUP("group"),
TRACK("track"),
LOG("log");
private final String tag;
}
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.utils;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import lombok.experimental.UtilityClass;
import java.util.function.Function;
import java.util.stream.Collector;
@UtilityClass
public class ImmutableCollectors {
public static <T, K, V> Collector<T, ImmutableMap.Builder<K, V>, ImmutableMap<K, V>> toImmutableMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) {
return Collector.of(
ImmutableMap.Builder<K, V>::new,
(r, t) -> r.put(keyMapper.apply(t), valueMapper.apply(t)),
(l, r) -> l.putAll(r.build()),
ImmutableMap.Builder::build,
Collector.Characteristics.UNORDERED);
}
public static <T> Collector<T, ImmutableSet.Builder<T>, ImmutableSet<T>> toImmutableSet() {
return Collector.of(
ImmutableSet.Builder<T>::new,
ImmutableSet.Builder<T>::add,
(l, r) -> l.addAll(r.build()),
ImmutableSet.Builder<T>::build,
Collector.Characteristics.UNORDERED);
}
public static <T> Collector<T, ImmutableList.Builder<T>, ImmutableList<T>> toImmutableList() {
return Collector.of(
ImmutableList.Builder<T>::new,
ImmutableList.Builder<T>::add,
(l, r) -> l.addAll(r.build()),
ImmutableList.Builder<T>::build);
}
}

View File

@ -200,7 +200,9 @@ public class LPSpongePlugin implements LuckPermsPlugin {
}
for (Permission perm : Permission.values()) {
registerPermission(p, perm.getNode());
for (String node : perm.getNodes()) {
registerPermission(p, node);
}
}
}