Use Splitter instead of Patterns, don't split arguments in quotes

This commit is contained in:
Luck 2016-09-12 19:00:37 +01:00
parent 22426bab33
commit e7ca79d251
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
18 changed files with 121 additions and 93 deletions

View File

@ -22,8 +22,12 @@
package me.lucko.luckperms; package me.lucko.luckperms;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import me.lucko.luckperms.api.data.Callback; import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.commands.CommandManager; import me.lucko.luckperms.commands.CommandManager;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.constants.Patterns;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -39,7 +43,12 @@ class BukkitCommand extends CommandManager implements CommandExecutor, TabExecut
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
onCommand(BukkitSenderFactory.get().wrap(sender), label, Arrays.asList(args), Callback.empty()); onCommand(
BukkitSenderFactory.get().wrap(sender),
label,
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(Joiner.on(' ').join(args))),
Callback.empty()
);
return true; return true;
} }

View File

@ -23,8 +23,8 @@
package me.lucko.luckperms; package me.lucko.luckperms;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.inject.LPPermissible;
import me.lucko.luckperms.inject.Injector; import me.lucko.luckperms.inject.Injector;
import me.lucko.luckperms.inject.LPPermissible;
import me.lucko.luckperms.users.BukkitUser; import me.lucko.luckperms.users.BukkitUser;
import me.lucko.luckperms.users.User; import me.lucko.luckperms.users.User;
import me.lucko.luckperms.utils.AbstractListener; import me.lucko.luckperms.utils.AbstractListener;

View File

@ -22,11 +22,11 @@
package me.lucko.luckperms.inject; package me.lucko.luckperms.inject;
import com.google.common.base.Splitter;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.constants.Patterns;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.permissions.*; import org.bukkit.permissions.*;
@ -99,7 +99,7 @@ public class LPPermissible extends PermissibleBase {
} }
String node = ""; String node = "";
String[] permParts = Patterns.DOT.split(permission); Iterable<String> permParts = Splitter.on('.').split(permission);
for (String s : permParts) { for (String s : permParts) {
if (node.equals("")) { if (node.equals("")) {
node = s; node = s;

View File

@ -22,8 +22,12 @@
package me.lucko.luckperms; package me.lucko.luckperms;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import me.lucko.luckperms.api.data.Callback; import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.commands.CommandManager; import me.lucko.luckperms.commands.CommandManager;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.constants.Patterns;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor; import net.md_5.bungee.api.plugin.TabExecutor;
@ -40,7 +44,12 @@ class BungeeCommand extends Command implements TabExecutor {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
manager.onCommand(BungeeSenderFactory.get().wrap(sender), "bperms", Arrays.asList(args), Callback.empty()); manager.onCommand(
BungeeSenderFactory.get().wrap(sender),
"bperms",
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(Joiner.on(' ').join(args))),
Callback.empty()
);
} }
@Override @Override

View File

@ -37,6 +37,22 @@ public class Util {
sender.sendMessage(color(Message.PREFIX + message)); sender.sendMessage(color(Message.PREFIX + message));
} }
public static List<String> stripQuotes(List<String> input) {
input = new ArrayList<>(input);
ListIterator<String> iterator = input.listIterator();
while (iterator.hasNext()) {
String value = iterator.next();
if (!(value.length() >= 3)) {
continue;
}
if (value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') {
iterator.set(value.substring(1, value.length() - 1));
}
}
return input;
}
public static String color(String s) { public static String color(String s) {
return translateAlternateColorCodes('&', s); return translateAlternateColorCodes('&', s);
} }

View File

@ -28,7 +28,6 @@ import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Patterns;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.data.LogEntry;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -53,7 +52,7 @@ public class GroupSetPermission extends SubCommand<Group> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (Patterns.GROUP_MATCH.matcher(node).matches()) { if (node.toLowerCase().startsWith("group.")) {
Message.GROUP_USE_INHERIT.send(sender); Message.GROUP_USE_INHERIT.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -28,7 +28,6 @@ import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Patterns;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.data.LogEntry;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -55,7 +54,7 @@ public class GroupSetTempPermission extends SubCommand<Group> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (Patterns.GROUP_MATCH.matcher(node).matches()) { if (node.toLowerCase().startsWith("group.")) {
Message.GROUP_USE_INHERIT.send(sender); Message.GROUP_USE_INHERIT.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -28,7 +28,6 @@ import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Patterns;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.data.LogEntry;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -52,7 +51,7 @@ public class GroupUnSetPermission extends SubCommand<Group> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (Patterns.GROUP_MATCH.matcher(node).matches()) { if (node.toLowerCase().startsWith("group.")) {
Message.GROUP_USE_UNINHERIT.send(sender); Message.GROUP_USE_UNINHERIT.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -28,7 +28,6 @@ import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Patterns;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.data.LogEntry;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -53,7 +52,7 @@ public class GroupUnsetTempPermission extends SubCommand<Group> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (Patterns.GROUP_MATCH.matcher(node).matches()) { if (node.toLowerCase().startsWith("group.")) {
Message.GROUP_USE_UNINHERIT.send(sender); Message.GROUP_USE_UNINHERIT.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -28,7 +28,6 @@ import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Patterns;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.data.LogEntry;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -54,7 +53,7 @@ public class UserSetPermission extends SubCommand<User> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (Patterns.GROUP_MATCH.matcher(node).matches()) { if (node.toLowerCase().startsWith("group.")) {
Message.USER_USE_ADDGROUP.send(sender); Message.USER_USE_ADDGROUP.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -28,7 +28,6 @@ import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Patterns;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.data.LogEntry;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
@ -55,7 +54,7 @@ public class UserSetTempPermission extends SubCommand<User> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (Patterns.GROUP_MATCH.matcher(node).matches()) { if (node.toLowerCase().startsWith("group.")) {
Message.USER_USE_ADDGROUP.send(sender); Message.USER_USE_ADDGROUP.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -28,7 +28,6 @@ import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Patterns;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.data.LogEntry;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -52,7 +51,7 @@ public class UserUnSetPermission extends SubCommand<User> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (Patterns.GROUP_MATCH.matcher(node).matches()) { if (node.toLowerCase().startsWith("group.")) {
Message.USER_USE_REMOVEGROUP.send(sender); Message.USER_USE_REMOVEGROUP.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -28,7 +28,6 @@ import me.lucko.luckperms.commands.Predicate;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Patterns;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.data.LogEntry;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -53,7 +52,7 @@ public class UserUnsetTempPermission extends SubCommand<User> {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
if (Patterns.GROUP_MATCH.matcher(node).matches()) { if (node.toLowerCase().startsWith("group.")) {
Message.USER_USE_REMOVEGROUP.send(sender); Message.USER_USE_REMOVEGROUP.send(sender);
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }

View File

@ -33,15 +33,9 @@ import java.util.regex.PatternSyntaxException;
public class Patterns { public class Patterns {
private static final Map<String, Pattern> CACHE = new ConcurrentHashMap<>(); private static final Map<String, Pattern> CACHE = new ConcurrentHashMap<>();
public static final Pattern SPACE = Pattern.compile(" "); public static final Pattern COMMAND_SEPARATOR = Pattern.compile(" (?=([^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)");
public static final Pattern SERVER_DELIMITER = Pattern.compile("\\/"); public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[\\/\\$\\.\\- ]");
public static final Pattern WORLD_DELIMITER = Pattern.compile("\\-"); public static final Pattern NON_USERNAME = Pattern.compile("[^A-Za-z0-9_ ]");
public static final Pattern TEMP_DELIMITER = Pattern.compile("\\$");
public static final Pattern DOT = Pattern.compile("\\.");
public static final Pattern VERTICAL_BAR = Pattern.compile("\\|");
public static final Pattern GROUP_MATCH = Pattern.compile("group\\..*");
public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[\\/\\$\\.\\-]");
public static final Pattern NON_USERNAME = Pattern.compile("[^A-Za-z0-9_]");
public static final Pattern SHORTHAND_NODE = Pattern.compile("\\.\\([^.]+\\)"); public static final Pattern SHORTHAND_NODE = Pattern.compile("\\.\\([^.]+\\)");
public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]"); public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]");
public static final Pattern NODE_CONTEXTS = Pattern.compile("\\(.+\\).*"); public static final Pattern NODE_CONTEXTS = Pattern.compile("\\(.+\\).*");

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.data; package me.lucko.luckperms.data;
import com.google.common.base.Splitter;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.Setter; import lombok.Setter;
@ -31,7 +32,6 @@ import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.constants.Constants; import me.lucko.luckperms.constants.Constants;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Patterns;
import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.constants.Permission;
import java.util.*; import java.util.*;
@ -98,7 +98,7 @@ public class Importer {
executing = index; executing = index;
try { try {
CommandResult result = commandManager.onCommand(fake, "perms", Arrays.asList(Patterns.SPACE.split(command))); CommandResult result = commandManager.onCommand(fake, "perms", Splitter.on(' ').splitToList(command));
getResult(index, command).setResult(result); getResult(index, command).setResult(result);
} catch (Exception e) { } catch (Exception e) {

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.utils; package me.lucko.luckperms.utils;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import lombok.*; import lombok.*;
import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.Tristate;
@ -41,6 +42,7 @@ import java.util.stream.IntStream;
public class Node implements me.lucko.luckperms.api.Node { public class Node implements me.lucko.luckperms.api.Node {
private static final Pattern PREFIX_PATTERN = Pattern.compile("(?i)prefix\\.-?\\d+\\..*"); 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 SUFFIX_PATTERN = Pattern.compile("(?i)suffix\\.-?\\d+\\..*");
private static final Pattern META_PATTERN = Pattern.compile("meta\\..*\\..*");
public static me.lucko.luckperms.api.Node fromSerialisedNode(String s, Boolean b) { public static me.lucko.luckperms.api.Node fromSerialisedNode(String s, Boolean b) {
return builderFromSerialisedNode(s, b).build(); return builderFromSerialisedNode(s, b).build();
@ -48,36 +50,36 @@ public class Node implements me.lucko.luckperms.api.Node {
public static me.lucko.luckperms.api.Node.Builder builderFromSerialisedNode(String s, Boolean b) { public static me.lucko.luckperms.api.Node.Builder builderFromSerialisedNode(String s, Boolean b) {
if (s.contains("/")) { if (s.contains("/")) {
String[] parts = Patterns.SERVER_DELIMITER.split(s, 2); List<String> parts = Splitter.on('/').limit(2).splitToList(s);
// 0=server(+world) 1=node // 0=server(+world) 1=node
// WORLD SPECIFIC // WORLD SPECIFIC
if (parts[0].contains("-")) { if (parts.get(0).contains("-")) {
String[] serverParts = Patterns.WORLD_DELIMITER.split(parts[0], 2); List<String> serverParts = Splitter.on('-').limit(2).splitToList(parts.get(0));
// 0=server 1=world // 0=server 1=world
if (parts[1].contains("$")) { if (parts.get(1).contains("$")) {
String[] tempParts = Patterns.TEMP_DELIMITER.split(parts[1], 2); List<String> tempParts = Splitter.on('$').limit(2).splitToList(parts.get(1));
return new Node.Builder(tempParts[0], true).setServerRaw(serverParts[0]).setWorld(serverParts[1]) return new Node.Builder(tempParts.get(0), true).setServerRaw(serverParts.get(0)).setWorld(serverParts.get(1))
.setExpiry(Long.parseLong(tempParts[1])).setValue(b); .setExpiry(Long.parseLong(tempParts.get(1))).setValue(b);
} else { } else {
return new Node.Builder(parts[1], true).setServerRaw(serverParts[0]).setWorld(serverParts[1]).setValue(b); return new Node.Builder(parts.get(1), true).setServerRaw(serverParts.get(0)).setWorld(serverParts.get(1)).setValue(b);
} }
} else { } else {
// SERVER BUT NOT WORLD SPECIFIC // SERVER BUT NOT WORLD SPECIFIC
if (parts[1].contains("$")) { if (parts.get(1).contains("$")) {
String[] tempParts = Patterns.TEMP_DELIMITER.split(parts[1], 2); List<String> tempParts = Splitter.on('$').limit(2).splitToList(parts.get(1));
return new Node.Builder(tempParts[0], true).setServerRaw(parts[0]).setExpiry(Long.parseLong(tempParts[1])).setValue(b); return new Node.Builder(tempParts.get(0), true).setServerRaw(parts.get(0)).setExpiry(Long.parseLong(tempParts.get(1))).setValue(b);
} else { } else {
return new Node.Builder(parts[1], true).setServerRaw(parts[0]).setValue(b); return new Node.Builder(parts.get(1), true).setServerRaw(parts.get(0)).setValue(b);
} }
} }
} else { } else {
// NOT SERVER SPECIFIC // NOT SERVER SPECIFIC
if (s.contains("$")) { if (s.contains("$")) {
String[] tempParts = Patterns.TEMP_DELIMITER.split(s, 2); List<String> tempParts = Splitter.on('$').limit(2).splitToList(s);
return new Node.Builder(tempParts[0], true).setExpiry(Long.parseLong(tempParts[1])).setValue(b); return new Node.Builder(tempParts.get(0), true).setExpiry(Long.parseLong(tempParts.get(1))).setValue(b);
} else { } else {
return new Node.Builder(s, true).setValue(b); return new Node.Builder(s, true).setValue(b);
} }
@ -100,6 +102,11 @@ public class Node implements me.lucko.luckperms.api.Node {
private final Map<String, String> extraContexts = new HashMap<>(); private final Map<String, String> extraContexts = new HashMap<>();
// Cache the state
private Tristate isPrefix = Tristate.UNDEFINED;
private Tristate isSuffix = Tristate.UNDEFINED;
private Tristate isMeta = Tristate.UNDEFINED;
/** /**
* Make an immutable node instance * Make an immutable node instance
* @param permission the actual permission node * @param permission the actual permission node
@ -203,7 +210,7 @@ public class Node implements me.lucko.luckperms.api.Node {
if (world.startsWith("(") && world.endsWith(")") && world.contains("|")) { if (world.startsWith("(") && world.endsWith(")") && world.contains("|")) {
final String bits = world.substring(1, world.length() - 1); final String bits = world.substring(1, world.length() - 1);
String[] parts = Patterns.VERTICAL_BAR.split(bits); Iterable<String> parts = Splitter.on('|').split(bits);
for (String s : parts) { for (String s : parts) {
if (s.equalsIgnoreCase(thisWorld)) { if (s.equalsIgnoreCase(thisWorld)) {
@ -313,7 +320,7 @@ public class Node implements me.lucko.luckperms.api.Node {
return Collections.emptyList(); return Collections.emptyList();
} }
String[] parts = Patterns.DOT.split(getPermission()); Iterable<String> parts = Splitter.on('.').split(getPermission());
List<Set<String>> nodeParts = new ArrayList<>(); List<Set<String>> nodeParts = new ArrayList<>();
for (String s : parts) { for (String s : parts) {
@ -324,13 +331,13 @@ public class Node implements me.lucko.luckperms.api.Node {
final String bits = s.substring(1, s.length() - 1); final String bits = s.substring(1, s.length() - 1);
if (s.contains("|")) { if (s.contains("|")) {
nodeParts.add(new HashSet<>(Arrays.asList(Patterns.VERTICAL_BAR.split(bits)))); nodeParts.add(new HashSet<>(Splitter.on('|').splitToList(bits)));
} else { } else {
String[] range = Patterns.WORLD_DELIMITER.split(bits, 2); List<String> range = Splitter.on('-').limit(2).splitToList(bits);
if (isChar(range[0], range[1])) { if (isChar(range.get(0), range.get(1))) {
nodeParts.add(getCharRange(range[0].charAt(0), range[1].charAt(0))); nodeParts.add(getCharRange(range.get(0).charAt(0), range.get(1).charAt(0)));
} else if (isInt(range[0], range[1])) { } else if (isInt(range.get(0), range.get(1))) {
nodeParts.add(IntStream.rangeClosed(Integer.parseInt(range[0]), Integer.parseInt(range[1])).boxed() nodeParts.add(IntStream.rangeClosed(Integer.parseInt(range.get(0)), Integer.parseInt(range.get(1))).boxed()
.map(i -> "" + i) .map(i -> "" + i)
.collect(Collectors.toSet()) .collect(Collectors.toSet())
); );
@ -423,7 +430,7 @@ public class Node implements me.lucko.luckperms.api.Node {
@Override @Override
public boolean isGroupNode() { public boolean isGroupNode() {
return Patterns.GROUP_MATCH.matcher(getPermission()).matches(); return getPermission().toLowerCase().startsWith("group.");
} }
@Override @Override
@ -447,7 +454,11 @@ public class Node implements me.lucko.luckperms.api.Node {
@Override @Override
public boolean isMeta() { public boolean isMeta() {
return getPermission().matches("meta\\..*\\..*"); if (isMeta == Tristate.UNDEFINED) {
isMeta = Tristate.fromBoolean(META_PATTERN.matcher(getPermission()).matches());
}
return isMeta.asBoolean();
} }
@Override @Override
@ -462,7 +473,11 @@ public class Node implements me.lucko.luckperms.api.Node {
@Override @Override
public boolean isPrefix() { public boolean isPrefix() {
return PREFIX_PATTERN.matcher(getPermission()).matches(); if (isPrefix == Tristate.UNDEFINED) {
isPrefix = Tristate.fromBoolean(PREFIX_PATTERN.matcher(getPermission()).matches());
}
return isPrefix.asBoolean();
} }
@Override @Override
@ -471,15 +486,18 @@ public class Node implements me.lucko.luckperms.api.Node {
throw new IllegalStateException(); throw new IllegalStateException();
} }
String[] prefixPart = Patterns.DOT.split(getPermission().substring("prefix.".length()), 2); List<String> prefixPart = Splitter.on('.').limit(2).splitToList(getPermission().substring("prefix.".length()));
Integer i = Integer.parseInt(prefixPart[0]); Integer i = Integer.parseInt(prefixPart.get(0));
return new AbstractMap.SimpleEntry<>(i, prefixPart.get(1));
return new AbstractMap.SimpleEntry<>(i, prefixPart[1]);
} }
@Override @Override
public boolean isSuffix() { public boolean isSuffix() {
return SUFFIX_PATTERN.matcher(getPermission()).matches(); if (isSuffix == Tristate.UNDEFINED) {
isSuffix = Tristate.fromBoolean(SUFFIX_PATTERN.matcher(getPermission()).matches());
}
return isSuffix.asBoolean();
} }
@Override @Override
@ -488,10 +506,9 @@ public class Node implements me.lucko.luckperms.api.Node {
throw new IllegalStateException(); throw new IllegalStateException();
} }
String[] suffixPart = Patterns.DOT.split(getPermission().substring("suffix.".length()), 2); List<String> suffixPart = Splitter.on('.').limit(2).splitToList(getPermission().substring("suffix.".length()));
Integer i = Integer.parseInt(suffixPart[0]); Integer i = Integer.parseInt(suffixPart.get(0));
return new AbstractMap.SimpleEntry<>(i, suffixPart.get(1));
return new AbstractMap.SimpleEntry<>(i, suffixPart[1]);
} }
@Override @Override
@ -635,18 +652,14 @@ public class Node implements me.lucko.luckperms.api.Node {
if (!Patterns.NODE_CONTEXTS.matcher(permission).matches()) { if (!Patterns.NODE_CONTEXTS.matcher(permission).matches()) {
this.permission = permission; this.permission = permission;
} else { } else {
String[] contextParts = permission.substring(1).split("\\)", 2); List<String> contextParts = Splitter.on(')').limit(2).splitToList(permission.substring(1));
// 0 = context, 1 = node // 0 = context, 1 = node
this.permission = contextParts[1];
for (String s : contextParts[0].split("\\,")) { this.permission = contextParts.get(1);
if (!s.contains("=")) { try {
// Not valid extraContexts.putAll(Splitter.on(',').withKeyValueSeparator('=').split(contextParts.get(0)));
continue; } catch (IllegalArgumentException e) {
} e.printStackTrace();
String[] context = s.split("\\=", 2);
extraContexts.put(context[0], context[1]);
} }
} }
} }

View File

@ -22,8 +22,10 @@
package me.lucko.luckperms; package me.lucko.luckperms;
import com.google.common.base.Splitter;
import me.lucko.luckperms.api.data.Callback; import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.commands.CommandManager; import me.lucko.luckperms.commands.CommandManager;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.constants.Patterns; import me.lucko.luckperms.constants.Patterns;
import org.spongepowered.api.command.CommandCallable; import org.spongepowered.api.command.CommandCallable;
import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandException;
@ -34,8 +36,6 @@ import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -47,27 +47,22 @@ class SpongeCommand extends CommandManager implements CommandCallable {
@Override @Override
public CommandResult process(CommandSource source, String s) throws CommandException { public CommandResult process(CommandSource source, String s) throws CommandException {
onCommand(SpongeSenderFactory.get().wrap(source), "perms", Arrays.asList(Patterns.SPACE.split(s)), Callback.empty()); onCommand(
SpongeSenderFactory.get().wrap(source),
"perms",
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(s)),
Callback.empty()
);
return CommandResult.success(); return CommandResult.success();
} }
@Override @Override
public List<String> getSuggestions(CommandSource source, String s, @Nullable Location<World> location) throws CommandException { public List<String> getSuggestions(CommandSource source, String s, @Nullable Location<World> location) throws CommandException {
List<String> args = new ArrayList<>(Arrays.asList(Patterns.SPACE.split(s))); return onTabComplete(SpongeSenderFactory.get().wrap(source), Splitter.on(' ').splitToList(s));
if (s.endsWith(" ")) {
args.add("");
}
return onTabComplete(SpongeSenderFactory.get().wrap(source), args);
} }
public List<String> getSuggestions(CommandSource source, String s) throws CommandException { public List<String> getSuggestions(CommandSource source, String s) throws CommandException {
List<String> args = new ArrayList<>(Arrays.asList(Patterns.SPACE.split(s))); return onTabComplete(SpongeSenderFactory.get().wrap(source), Splitter.on(' ').splitToList(s));
if (s.endsWith(" ")) {
args.add("");
}
return onTabComplete(SpongeSenderFactory.get().wrap(source), args);
} }
@Override @Override

View File

@ -22,7 +22,7 @@
package me.lucko.luckperms; package me.lucko.luckperms;
import me.lucko.luckperms.constants.Patterns; import com.google.common.base.Splitter;
import me.lucko.luckperms.core.LPConfiguration; import me.lucko.luckperms.core.LPConfiguration;
import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.commented.CommentedConfigurationNode; import ninja.leaping.configurate.commented.CommentedConfigurationNode;
@ -70,7 +70,7 @@ class SpongeConfig extends LPConfiguration<LPSpongePlugin> {
} }
private ConfigurationNode getNode(String path) { private ConfigurationNode getNode(String path) {
String[] paths = Patterns.DOT.split(path); Iterable<String> paths = Splitter.on('.').split(path);
ConfigurationNode node = root; ConfigurationNode node = root;
for (String s : paths) { for (String s : paths) {