mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Modify node escaping to use "\" characters, and remove all limits on node/server/world strings - closes #166
This commit is contained in:
parent
6540c695de
commit
9b8d6e1dc7
@ -37,6 +37,20 @@ import java.util.Set;
|
||||
*/
|
||||
public class MetaUtils {
|
||||
|
||||
private static String escapeDelimiters(String s, String... delims) {
|
||||
for (String delim : delims) {
|
||||
s = s.replace(delim, "\\" + delim);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static String unescapeDelimiters(String s, String... delims) {
|
||||
for (String delim : delims) {
|
||||
s = s.replace("\\" + delim, delim);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes special characters used within LuckPerms, so the string can be saved without issues
|
||||
*
|
||||
@ -49,11 +63,7 @@ public class MetaUtils {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
s = s.replace(".", "{SEP}");
|
||||
s = s.replace("/", "{FSEP}");
|
||||
s = s.replace("$", "{DSEP}");
|
||||
|
||||
return s;
|
||||
return escapeDelimiters(s, ".", "/", "-", "$");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,6 +81,7 @@ public class MetaUtils {
|
||||
s = s.replace("{SEP}", ".");
|
||||
s = s.replace("{FSEP}", "/");
|
||||
s = s.replace("{DSEP}", "$");
|
||||
s = unescapeDelimiters(s, ".", "/", "-", "$");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -63,8 +63,6 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkNode;
|
||||
|
||||
/**
|
||||
* Implements the LuckPerms API using the plugin instance
|
||||
*/
|
||||
@ -235,7 +233,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
|
||||
@Override
|
||||
public Node.Builder buildNode(@NonNull String permission) throws IllegalArgumentException {
|
||||
return new NodeBuilder(checkNode(permission));
|
||||
return new NodeBuilder(permission);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -65,22 +65,6 @@ public class ApiUtils {
|
||||
return s.toLowerCase();
|
||||
}
|
||||
|
||||
public static String checkServer(String s) {
|
||||
Preconditions.checkArgument(
|
||||
!ArgumentChecker.checkServer(s),
|
||||
"Invalid server entry '" + s + "'. Server names can only contain alphanumeric characters."
|
||||
);
|
||||
return s;
|
||||
}
|
||||
|
||||
public static String checkNode(String s) {
|
||||
Preconditions.checkArgument(
|
||||
!ArgumentChecker.checkNode(s),
|
||||
"Invalid node entry '" + s + "'. Nodes cannot contain '/' or '$' characters."
|
||||
);
|
||||
return s;
|
||||
}
|
||||
|
||||
public static long checkTime(long l) {
|
||||
Preconditions.checkArgument(!ArgumentChecker.checkTime(l), "Unix time '" + l + "' is invalid, as it has already passed.");
|
||||
return l;
|
||||
|
@ -35,7 +35,6 @@ import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkGroup;
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkServer;
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkTime;
|
||||
|
||||
/**
|
||||
@ -83,13 +82,13 @@ public class GroupDelegate extends PermissionHolderDelegate implements Group {
|
||||
@Override
|
||||
public void setInheritGroup(@NonNull Group group, @NonNull String server) throws ObjectAlreadyHasException {
|
||||
checkGroup(group);
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server));
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectAlreadyHasException {
|
||||
checkGroup(group);
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world);
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -101,13 +100,13 @@ public class GroupDelegate extends PermissionHolderDelegate implements Group {
|
||||
@Override
|
||||
public void setInheritGroup(@NonNull Group group, @NonNull String server, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
checkGroup(group);
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), checkTime(expireAt));
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), server, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
checkGroup(group);
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world, checkTime(expireAt));
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), server, world, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -125,25 +124,25 @@ public class GroupDelegate extends PermissionHolderDelegate implements Group {
|
||||
@Override
|
||||
public void unsetInheritGroup(@NonNull Group group, @NonNull String server) throws ObjectLacksException {
|
||||
checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server));
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectLacksException {
|
||||
checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetInheritGroup(@NonNull Group group, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), temporary);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), server, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world, temporary);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), server, world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,7 +157,7 @@ public class GroupDelegate extends PermissionHolderDelegate implements Group {
|
||||
|
||||
@Override
|
||||
public List<String> getLocalGroups(@NonNull String server, @NonNull String world) {
|
||||
return master.getLocalGroups(checkServer(server), world);
|
||||
return master.getLocalGroups(server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -168,6 +167,6 @@ public class GroupDelegate extends PermissionHolderDelegate implements Group {
|
||||
|
||||
@Override
|
||||
public List<String> getLocalGroups(@NonNull String server) {
|
||||
return master.getLocalGroups(checkServer(server));
|
||||
return master.getLocalGroups(server);
|
||||
}
|
||||
}
|
||||
|
@ -48,8 +48,6 @@ import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkNode;
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkServer;
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkTime;
|
||||
import static me.lucko.luckperms.common.core.model.PermissionHolder.exportToLegacy;
|
||||
|
||||
@ -123,12 +121,12 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull String server) {
|
||||
return master.hasPermission(node, b, checkServer(server));
|
||||
return master.hasPermission(node, b, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world) {
|
||||
return master.hasPermission(node, b, checkServer(server), world);
|
||||
return master.hasPermission(node, b, server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -138,12 +136,12 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull boolean temporary) {
|
||||
return master.hasPermission(node, b, checkServer(server), temporary);
|
||||
return master.hasPermission(node, b, server, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world, @NonNull boolean temporary) {
|
||||
return master.hasPermission(node, b, checkServer(server), world, temporary);
|
||||
return master.hasPermission(node, b, server, world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,12 +156,12 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
|
||||
@Override
|
||||
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull String server) {
|
||||
return master.inheritsPermission(node, b, checkServer(server));
|
||||
return master.inheritsPermission(node, b, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world) {
|
||||
return master.inheritsPermission(node, b, checkServer(server), world);
|
||||
return master.inheritsPermission(node, b, server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -173,12 +171,12 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
|
||||
@Override
|
||||
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull boolean temporary) {
|
||||
return master.inheritsPermission(node, b, checkServer(server), temporary);
|
||||
return master.inheritsPermission(node, b, server, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world, @NonNull boolean temporary) {
|
||||
return master.inheritsPermission(node, b, checkServer(server), world, temporary);
|
||||
return master.inheritsPermission(node, b, server, world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -193,32 +191,32 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value);
|
||||
master.setPermission(node, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull String server) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value, checkServer(server));
|
||||
master.setPermission(node, value, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull String server, @NonNull String world) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value, checkServer(server), world);
|
||||
master.setPermission(node, value, server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value, checkTime(expireAt));
|
||||
master.setPermission(node, value, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull String server, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value, checkServer(server), checkTime(expireAt));
|
||||
master.setPermission(node, value, server, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull String server, @NonNull String world, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value, checkServer(server), world, checkTime(expireAt));
|
||||
master.setPermission(node, value, server, world, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -233,32 +231,32 @@ public class PermissionHolderDelegate implements PermissionHolder {
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node), temporary);
|
||||
master.unsetPermission(node, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node));
|
||||
master.unsetPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull String server) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node), checkServer(server));
|
||||
master.unsetPermission(node, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull String server, @NonNull String world) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node), checkServer(server), world);
|
||||
master.unsetPermission(node, server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node), checkServer(server), temporary);
|
||||
master.unsetPermission(node, server, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull String server, @NonNull String world, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node), checkServer(server), world, temporary);
|
||||
master.unsetPermission(node, server, world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,7 +37,6 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkGroup;
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkServer;
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkTime;
|
||||
|
||||
/**
|
||||
@ -124,13 +123,13 @@ public class UserDelegate extends PermissionHolderDelegate implements User {
|
||||
@Override
|
||||
public void addGroup(@NonNull Group group, @NonNull String server) throws ObjectAlreadyHasException {
|
||||
checkGroup(group);
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server));
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectAlreadyHasException {
|
||||
checkGroup(group);
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world);
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -142,13 +141,13 @@ public class UserDelegate extends PermissionHolderDelegate implements User {
|
||||
@Override
|
||||
public void addGroup(@NonNull Group group, @NonNull String server, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
checkGroup(group);
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), checkTime(expireAt));
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), server, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
checkGroup(group);
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world, checkTime(expireAt));
|
||||
master.setInheritGroup(((GroupDelegate) group).getMaster(), server, world, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -166,25 +165,25 @@ public class UserDelegate extends PermissionHolderDelegate implements User {
|
||||
@Override
|
||||
public void removeGroup(@NonNull Group group, @NonNull String server) throws ObjectLacksException {
|
||||
checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server));
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectLacksException {
|
||||
checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), temporary);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), server, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world, temporary);
|
||||
master.unsetInheritGroup(((GroupDelegate) group).getMaster(), server, world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -199,12 +198,12 @@ public class UserDelegate extends PermissionHolderDelegate implements User {
|
||||
|
||||
@Override
|
||||
public List<String> getLocalGroups(@NonNull String server, @NonNull String world) {
|
||||
return master.getLocalGroups(checkServer(server), world);
|
||||
return master.getLocalGroups(server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLocalGroups(@NonNull String server) {
|
||||
return master.getLocalGroups(checkServer(server));
|
||||
return master.getLocalGroups(server);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class TrackAppend extends SubCommand<Track> {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
if (ArgumentChecker.checkName(groupName)) {
|
||||
sendDetailedUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class TrackInsert extends SubCommand<Track> {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
if (ArgumentChecker.checkName(groupName)) {
|
||||
sendDetailedUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class TrackRemove extends SubCommand<Track> {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (ArgumentChecker.checkNode(groupName)) {
|
||||
if (ArgumentChecker.checkName(groupName)) {
|
||||
sendDetailedUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
@ -66,14 +66,11 @@ public class ArgumentUtils {
|
||||
|
||||
public static String handleNode(int index, List<String> args) throws ArgumentException {
|
||||
String node = args.get(index).replace("{SPACE}", " ");
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
throw new DetailedUsageException();
|
||||
}
|
||||
|
||||
if (node.toLowerCase().startsWith("group.")) {
|
||||
throw new UseInheritException();
|
||||
}
|
||||
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -107,11 +104,7 @@ public class ArgumentUtils {
|
||||
|
||||
public static String handleServer(int index, List<String> args) throws ArgumentException {
|
||||
if (args.size() > index) {
|
||||
final String server = args.get(index).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
throw new InvalidServerException();
|
||||
}
|
||||
return server;
|
||||
return args.get(index).toLowerCase();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -66,4 +66,12 @@ public class Patterns {
|
||||
}
|
||||
}
|
||||
|
||||
public static String buildDelimitedMatcher(String delim, String esc) {
|
||||
return "(?<!" + Pattern.quote(esc) + ")" + Pattern.quote(delim);
|
||||
}
|
||||
|
||||
public static Pattern compileDelimitedMatcher(String delim, String esc) {
|
||||
return compile(buildDelimitedMatcher(delim, esc));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.common.constants.Patterns;
|
||||
import me.lucko.luckperms.common.core.model.ImmutableNode;
|
||||
import me.lucko.luckperms.common.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -58,12 +57,16 @@ public class NodeBuilder implements Node.Builder {
|
||||
if (!Patterns.NODE_CONTEXTS.matcher(permission).matches()) {
|
||||
this.permission = permission;
|
||||
} else {
|
||||
List<String> contextParts = Splitter.on(')').limit(2).splitToList(permission.substring(1));
|
||||
List<String> contextParts = Splitter.on(Patterns.compileDelimitedMatcher(")", "\\")).limit(2).splitToList(permission.substring(1));
|
||||
// 0 = context, 1 = node
|
||||
|
||||
this.permission = contextParts.get(1);
|
||||
try {
|
||||
extraContexts.addAll(Splitter.on(',').withKeyValueSeparator('=').split(contextParts.get(0)));
|
||||
Map<String, String> map = Splitter.on(Patterns.compileDelimitedMatcher(",", "\\")).withKeyValueSeparator(Splitter.on(Patterns.compileDelimitedMatcher("=", "\\"))).split(contextParts.get(0));
|
||||
for (Map.Entry<String, String> e : map.entrySet()) {
|
||||
this.withExtraContext(NodeFactory.unescapeDelimiters(e.getKey(), "=", "(", ")", ","), NodeFactory.unescapeDelimiters(e.getValue(), "=", "(", ")", ","));
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -113,15 +116,6 @@ public class NodeBuilder implements Node.Builder {
|
||||
|
||||
@Override
|
||||
public Node.Builder setServer(String server) {
|
||||
if (server != null && ArgumentChecker.checkServer(server)) {
|
||||
throw new IllegalArgumentException("Server name invalid.");
|
||||
}
|
||||
|
||||
this.server = server;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Node.Builder setServerRaw(String server) {
|
||||
this.server = server;
|
||||
return this;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
|
||||
import me.lucko.luckperms.api.MetaUtils;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.constants.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@ -70,36 +71,42 @@ public class NodeFactory {
|
||||
}
|
||||
|
||||
public static Node.Builder builderFromSerialisedNode(String s, Boolean b) {
|
||||
if (s.contains("/")) {
|
||||
List<String> parts = Splitter.on('/').limit(2).splitToList(s);
|
||||
// if contains /
|
||||
if (Patterns.compileDelimitedMatcher("/", "\\").matcher(s).find()) {
|
||||
List<String> parts = Splitter.on(Patterns.compileDelimitedMatcher("/", "\\")).limit(2).splitToList(s);
|
||||
// 0=server(+world) 1=node
|
||||
|
||||
// WORLD SPECIFIC
|
||||
if (parts.get(0).contains("-")) {
|
||||
List<String> serverParts = Splitter.on('-').limit(2).splitToList(parts.get(0));
|
||||
// if parts[0] contains -
|
||||
if (Patterns.compileDelimitedMatcher("-", "\\").matcher(parts.get(0)).find()) {
|
||||
List<String> serverParts = Splitter.on(Patterns.compileDelimitedMatcher("-", "\\")).limit(2).splitToList(parts.get(0));
|
||||
// 0=server 1=world
|
||||
|
||||
if (parts.get(1).contains("$")) {
|
||||
// if parts[1] contains $
|
||||
if (Patterns.compileDelimitedMatcher("$", "\\").matcher(parts.get(1)).find()) {
|
||||
List<String> tempParts = Splitter.on('$').limit(2).splitToList(parts.get(1));
|
||||
return new NodeBuilder(tempParts.get(0), true).setServerRaw(serverParts.get(0)).setWorld(serverParts.get(1))
|
||||
return new NodeBuilder(tempParts.get(0), true).setServer(serverParts.get(0)).setWorld(serverParts.get(1))
|
||||
.setExpiry(Long.parseLong(tempParts.get(1))).setValue(b);
|
||||
} else {
|
||||
return new NodeBuilder(parts.get(1), true).setServerRaw(serverParts.get(0)).setWorld(serverParts.get(1)).setValue(b);
|
||||
return new NodeBuilder(parts.get(1), true).setServer(serverParts.get(0)).setWorld(serverParts.get(1)).setValue(b);
|
||||
}
|
||||
|
||||
} else {
|
||||
// SERVER BUT NOT WORLD SPECIFIC
|
||||
if (parts.get(1).contains("$")) {
|
||||
List<String> tempParts = Splitter.on('$').limit(2).splitToList(parts.get(1));
|
||||
return new NodeBuilder(tempParts.get(0), true).setServerRaw(parts.get(0)).setExpiry(Long.parseLong(tempParts.get(1))).setValue(b);
|
||||
|
||||
// if parts[1] contains $
|
||||
if (Patterns.compileDelimitedMatcher("$", "\\").matcher(parts.get(1)).find()) {
|
||||
List<String> tempParts = Splitter.on(Patterns.compileDelimitedMatcher("$", "\\")).limit(2).splitToList(parts.get(1));
|
||||
return new NodeBuilder(tempParts.get(0), true).setServer(parts.get(0)).setExpiry(Long.parseLong(tempParts.get(1))).setValue(b);
|
||||
} else {
|
||||
return new NodeBuilder(parts.get(1), true).setServerRaw(parts.get(0)).setValue(b);
|
||||
return new NodeBuilder(parts.get(1), true).setServer(parts.get(0)).setValue(b);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// NOT SERVER SPECIFIC
|
||||
if (s.contains("$")) {
|
||||
List<String> tempParts = Splitter.on('$').limit(2).splitToList(s);
|
||||
|
||||
// if s contains $
|
||||
if (Patterns.compileDelimitedMatcher("$", "\\").matcher(s).find()) {
|
||||
List<String> tempParts = Splitter.on(Patterns.compileDelimitedMatcher("$", "\\")).limit(2).splitToList(s);
|
||||
return new NodeBuilder(tempParts.get(0), true).setExpiry(Long.parseLong(tempParts.get(1))).setValue(b);
|
||||
} else {
|
||||
return new NodeBuilder(s, true).setValue(b);
|
||||
@ -173,4 +180,62 @@ public class NodeFactory {
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String escapeDelimiters(String s, String... delims) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (String delim : delims) {
|
||||
s = s.replace(delim, "\\" + delim);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static String unescapeDelimiters(String s, String... delims) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (String delim : delims) {
|
||||
s = s.replace("\\" + delim, delim);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static boolean isMetaNode(String s) {
|
||||
if (!s.startsWith("meta.")) {
|
||||
return false;
|
||||
}
|
||||
String parts = s.substring("meta.".length());
|
||||
return Patterns.compileDelimitedMatcher(".", "\\").matcher(parts).find();
|
||||
}
|
||||
|
||||
private static boolean isChatMetaNode(String type, String s) {
|
||||
if (!s.startsWith(type + ".")) {
|
||||
return false;
|
||||
}
|
||||
String parts = s.substring((type + ".").length());
|
||||
|
||||
if (!Patterns.compileDelimitedMatcher(".", "\\").matcher(parts).find()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> metaParts = Splitter.on(Patterns.compileDelimitedMatcher(".", "\\")).limit(2).splitToList(parts);
|
||||
String priority = metaParts.get(0);
|
||||
try {
|
||||
Integer.parseInt(priority);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPrefixNode(String s) {
|
||||
return isChatMetaNode("prefix", s);
|
||||
}
|
||||
|
||||
public static boolean isSuffixNode(String s) {
|
||||
return isChatMetaNode("suffix", s);
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.constants.Patterns;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.utils.ShorthandParser;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -56,9 +57,6 @@ import java.util.stream.Collectors;
|
||||
@ToString(of = {"permission", "value", "override", "server", "world", "expireAt", "contexts"})
|
||||
@EqualsAndHashCode(of = {"permission", "value", "override", "server", "world", "expireAt", "contexts"})
|
||||
public class ImmutableNode implements Node {
|
||||
private static final Pattern PREFIX_PATTERN = Pattern.compile("(?i)prefix\\.-?\\d+\\..*");
|
||||
private static final Pattern SUFFIX_PATTERN = Pattern.compile("(?i)suffix\\.-?\\d+\\..*");
|
||||
private static final Pattern META_PATTERN = Pattern.compile("meta\\..*\\..*");
|
||||
|
||||
private static boolean shouldApply(String str, boolean applyRegex, String thisStr) {
|
||||
if (str.equalsIgnoreCase(thisStr)) {
|
||||
@ -197,39 +195,39 @@ public class ImmutableNode implements Node {
|
||||
server = "global";
|
||||
}
|
||||
|
||||
this.permission = permission;
|
||||
this.permission = NodeFactory.unescapeDelimiters(permission, "/", "-", "$", "(", ")", "=", ",");
|
||||
this.value = value;
|
||||
this.override = override;
|
||||
this.expireAt = expireAt;
|
||||
this.server = server;
|
||||
this.world = world;
|
||||
this.server = NodeFactory.unescapeDelimiters(server, "/", "-");
|
||||
this.world = NodeFactory.unescapeDelimiters(world, "/", "-");
|
||||
this.contexts = contexts == null ? ContextSet.empty() : contexts.makeImmutable();
|
||||
|
||||
// Setup state
|
||||
isGroup = permission.toLowerCase().startsWith("group.");
|
||||
isGroup = this.permission.toLowerCase().startsWith("group.");
|
||||
if (isGroup) {
|
||||
groupName = permission.substring("group.".length());
|
||||
groupName = this.permission.substring("group.".length());
|
||||
}
|
||||
|
||||
isWildcard = permission.endsWith(".*");
|
||||
wildcardLevel = (int) permission.chars().filter(num -> num == Character.getNumericValue('.')).count();
|
||||
isWildcard = this.permission.endsWith(".*");
|
||||
wildcardLevel = (int) this.permission.chars().filter(num -> num == Character.getNumericValue('.')).count();
|
||||
|
||||
isMeta = META_PATTERN.matcher(permission).matches();
|
||||
isMeta = NodeFactory.isMetaNode(this.permission);
|
||||
if (isMeta) {
|
||||
List<String> metaPart = Splitter.on('.').limit(2).splitToList(getPermission().substring("meta.".length()));
|
||||
List<String> metaPart = Splitter.on(Patterns.compileDelimitedMatcher(".", "\\")).limit(2).splitToList(getPermission().substring("meta.".length()));
|
||||
meta = Maps.immutableEntry(MetaUtils.unescapeCharacters(metaPart.get(0)), MetaUtils.unescapeCharacters(metaPart.get(1)));
|
||||
}
|
||||
|
||||
isPrefix = PREFIX_PATTERN.matcher(permission).matches();
|
||||
isPrefix = NodeFactory.isPrefixNode(this.permission);
|
||||
if (isPrefix) {
|
||||
List<String> prefixPart = Splitter.on('.').limit(2).splitToList(getPermission().substring("prefix.".length()));
|
||||
List<String> prefixPart = Splitter.on(Patterns.compileDelimitedMatcher(".", "\\")).limit(2).splitToList(getPermission().substring("prefix.".length()));
|
||||
Integer i = Integer.parseInt(prefixPart.get(0));
|
||||
prefix = Maps.immutableEntry(i, MetaUtils.unescapeCharacters(prefixPart.get(1)));
|
||||
}
|
||||
|
||||
isSuffix = SUFFIX_PATTERN.matcher(permission).matches();
|
||||
isSuffix = NodeFactory.isSuffixNode(this.permission);
|
||||
if (isSuffix) {
|
||||
List<String> suffixPart = Splitter.on('.').limit(2).splitToList(getPermission().substring("suffix.".length()));
|
||||
List<String> suffixPart = Splitter.on(Patterns.compileDelimitedMatcher(".", "\\")).limit(2).splitToList(getPermission().substring("suffix.".length()));
|
||||
Integer i = Integer.parseInt(suffixPart.get(0));
|
||||
suffix = Maps.immutableEntry(i, MetaUtils.unescapeCharacters(suffixPart.get(1)));
|
||||
}
|
||||
@ -453,29 +451,29 @@ public class ImmutableNode implements Node {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (server != null) {
|
||||
builder.append(server);
|
||||
builder.append(NodeFactory.escapeDelimiters(server, "/", "-"));
|
||||
|
||||
if (world != null) {
|
||||
builder.append("-").append(world);
|
||||
builder.append("-").append(NodeFactory.escapeDelimiters(world, "/", "-"));
|
||||
}
|
||||
builder.append("/");
|
||||
} else {
|
||||
if (world != null) {
|
||||
builder.append("global-").append(world).append("/");
|
||||
builder.append("global-").append(NodeFactory.escapeDelimiters(world, "/", "-")).append("/");
|
||||
}
|
||||
}
|
||||
|
||||
if (!contexts.isEmpty()) {
|
||||
builder.append("(");
|
||||
for (Map.Entry<String, String> entry : contexts.toSet()) {
|
||||
builder.append(entry.getKey()).append("=").append(entry.getValue()).append(",");
|
||||
builder.append(NodeFactory.escapeDelimiters(entry.getKey(), "=", "(", ")", ",")).append("=").append(NodeFactory.escapeDelimiters(entry.getValue(), "=", "(", ")", ",")).append(",");
|
||||
}
|
||||
|
||||
builder.deleteCharAt(builder.length() - 1);
|
||||
builder.append(")");
|
||||
}
|
||||
|
||||
builder.append(permission);
|
||||
builder.append(NodeFactory.escapeDelimiters(permission, "/", "-", "$", "(", ")", "=", ","));
|
||||
|
||||
if (expireAt != 0L) {
|
||||
builder.append("$").append(expireAt);
|
||||
|
@ -44,14 +44,6 @@ public class ArgumentChecker {
|
||||
return (s.length() > 36 || Patterns.NON_ALPHA_NUMERIC_SPACE.matcher(s).find());
|
||||
}
|
||||
|
||||
public static boolean checkServer(String s) {
|
||||
return !s.toLowerCase().startsWith("r=") && Patterns.NON_ALPHA_NUMERIC_SPACE.matcher(s).find();
|
||||
}
|
||||
|
||||
public static boolean checkNode(String s) {
|
||||
return (s.contains("/") || s.contains("$"));
|
||||
}
|
||||
|
||||
public static boolean checkTime(long l) {
|
||||
return DateUtil.shouldExpire(l);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class MigrationUtils {
|
||||
|
||||
for (Map.Entry<String, Boolean> perm : e.getValue().entrySet()) {
|
||||
try {
|
||||
holder.setPermission(new NodeBuilder(perm.getKey()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(perm.getValue()).build());
|
||||
holder.setPermission(new NodeBuilder(perm.getKey()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(perm.getValue()).build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
}
|
||||
@ -77,15 +77,15 @@ public class MigrationUtils {
|
||||
for (Map.Entry<String, String> opt : e.getValue().entrySet()) {
|
||||
if (opt.getKey().equalsIgnoreCase("prefix")) {
|
||||
try {
|
||||
holder.setPermission(NodeFactory.makePrefixNode(priority, opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
holder.setPermission(NodeFactory.makePrefixNode(priority, opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
} else if (opt.getKey().equalsIgnoreCase("suffix")) {
|
||||
try {
|
||||
holder.setPermission(NodeFactory.makeSuffixNode(priority, opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
holder.setPermission(NodeFactory.makeSuffixNode(priority, opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
} else {
|
||||
try {
|
||||
holder.setPermission(NodeFactory.makeMetaNode(opt.getKey(), opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
holder.setPermission(NodeFactory.makeMetaNode(opt.getKey(), opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
}
|
||||
@ -111,7 +111,7 @@ public class MigrationUtils {
|
||||
}
|
||||
|
||||
try {
|
||||
holder.setPermission(new NodeBuilder("group." + convertName(s.getIdentifier())).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
holder.setPermission(new NodeBuilder("group." + convertName(s.getIdentifier())).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user