mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-10-06 09:17:28 +02:00
Context parsing changes
This commit is contained in:
parent
40218563e1
commit
72dec16f54
@ -34,12 +34,10 @@ import me.lucko.luckperms.common.sender.Sender;
|
|||||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||||
import me.lucko.luckperms.common.util.DateParser;
|
import me.lucko.luckperms.common.util.DateParser;
|
||||||
|
|
||||||
import net.luckperms.api.context.DefaultContextKeys;
|
|
||||||
import net.luckperms.api.context.ImmutableContextSet;
|
import net.luckperms.api.context.ImmutableContextSet;
|
||||||
import net.luckperms.api.context.MutableContextSet;
|
import net.luckperms.api.context.MutableContextSet;
|
||||||
import net.luckperms.api.model.TemporaryMergeBehaviour;
|
import net.luckperms.api.model.TemporaryMergeBehaviour;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -153,87 +151,30 @@ public class ArgumentParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static MutableContextSet parseContext(int fromIndex, List<String> args, LuckPermsPlugin plugin) throws CommandException {
|
public static MutableContextSet parseContext(int fromIndex, List<String> args, LuckPermsPlugin plugin) throws CommandException {
|
||||||
if (args.size() > fromIndex) {
|
if (args.size() <= fromIndex) {
|
||||||
MutableContextSet set = new MutableContextSetImpl();
|
return plugin.getConfiguration().getContextsFile().getDefaultContexts().mutableCopy();
|
||||||
|
}
|
||||||
|
|
||||||
List<String> contexts = args.subList(fromIndex, args.size());
|
MutableContextSet contextSet = new MutableContextSetImpl();
|
||||||
|
List<String> toQuery = args.subList(fromIndex, args.size());
|
||||||
for (int i = 0; i < contexts.size(); i++) {
|
for (String s : toQuery) {
|
||||||
String pair = contexts.get(i);
|
int index = s.indexOf('=');
|
||||||
|
if (index != -1) {
|
||||||
// one of the first two values, and doesn't have a key
|
String key = s.substring(0, index);
|
||||||
if (i <= 1 && !pair.contains("=")) {
|
|
||||||
String key = i == 0 ? DefaultContextKeys.SERVER_KEY : DefaultContextKeys.WORLD_KEY;
|
|
||||||
set.add(key, pair);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = pair.indexOf('=');
|
|
||||||
if (index == -1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String key = pair.substring(0, index);
|
|
||||||
if (key.equals("") || key.trim().isEmpty()) {
|
if (key.equals("") || key.trim().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = pair.substring(index + 1);
|
String value = s.substring(index + 1);
|
||||||
if (value.equals("") || value.trim().isEmpty()) {
|
if (value.equals("") || value.trim().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
set.add(key, value);
|
contextSet.add(key, value);
|
||||||
}
|
|
||||||
|
|
||||||
return sanitizeContexts(set);
|
|
||||||
} else {
|
|
||||||
return sanitizeContexts(plugin.getConfiguration().getContextsFile().getDefaultContexts().mutableCopy());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MutableContextSet sanitizeContexts(MutableContextSet set) throws ArgumentException {
|
|
||||||
// remove any potential "global" context mappings
|
|
||||||
set.remove(DefaultContextKeys.SERVER_KEY, "global");
|
|
||||||
set.remove(DefaultContextKeys.WORLD_KEY, "global");
|
|
||||||
set.remove(DefaultContextKeys.SERVER_KEY, "null");
|
|
||||||
set.remove(DefaultContextKeys.WORLD_KEY, "null");
|
|
||||||
set.remove(DefaultContextKeys.SERVER_KEY, "*");
|
|
||||||
set.remove(DefaultContextKeys.WORLD_KEY, "*");
|
|
||||||
|
|
||||||
// remove excess entries from the set.
|
|
||||||
// (it can only have one server and one world.)
|
|
||||||
List<String> servers = new ArrayList<>(set.getValues(DefaultContextKeys.SERVER_KEY));
|
|
||||||
if (servers.size() > 1) {
|
|
||||||
// start iterating at index 1
|
|
||||||
for (int i = 1; i < servers.size(); i++) {
|
|
||||||
set.remove(DefaultContextKeys.SERVER_KEY, servers.get(i));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> worlds = new ArrayList<>(set.getValues(DefaultContextKeys.WORLD_KEY));
|
return contextSet;
|
||||||
if (worlds.size() > 1) {
|
|
||||||
// start iterating at index 1
|
|
||||||
for (int i = 1; i < worlds.size(); i++) {
|
|
||||||
set.remove(DefaultContextKeys.WORLD_KEY, worlds.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// there's either none or 1
|
|
||||||
for (String server : servers) {
|
|
||||||
if (!DataConstraints.SERVER_NAME_TEST.test(server)) {
|
|
||||||
throw new InvalidServerWorldException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// there's either none or 1
|
|
||||||
for (String world : worlds) {
|
|
||||||
if (!DataConstraints.WORLD_NAME_TEST.test(world)) {
|
|
||||||
throw new InvalidServerWorldException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parsePriority(int index, List<String> args) throws ArgumentException {
|
public static int parsePriority(int index, List<String> args) throws ArgumentException {
|
||||||
@ -255,12 +196,12 @@ public class ArgumentParser {
|
|||||||
int index = s.indexOf('=');
|
int index = s.indexOf('=');
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
String key = s.substring(0, index);
|
String key = s.substring(0, index);
|
||||||
if (key.equals("")) {
|
if (key.equals("") || key.trim().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = s.substring(index + 1);
|
String value = s.substring(index + 1);
|
||||||
if (value.equals("")) {
|
if (value.equals("") || value.trim().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user