mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +01:00
Fix parsing contexts from commands with server/world = global (#2093)
This commit is contained in:
parent
3a7fadb843
commit
30d7768299
@ -30,6 +30,7 @@ import me.lucko.luckperms.common.command.abstraction.Command;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.commands.user.UserParentCommand;
|
||||
import me.lucko.luckperms.common.context.contextset.AbstractContextSet;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.context.contextset.MutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
@ -175,26 +176,26 @@ public class ArgumentParser {
|
||||
|
||||
private static MutableContextSet parseContext(int fromIndex, List<String> args) {
|
||||
MutableContextSet contextSet = new MutableContextSetImpl();
|
||||
List<String> pairs = args.subList(fromIndex, args.size());
|
||||
for (int i = 0; i < pairs.size(); i++) {
|
||||
String pair = pairs.get(i);
|
||||
int index = pair.indexOf('=');
|
||||
List<String> entries = args.subList(fromIndex, args.size());
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
String entry = entries.get(i);
|
||||
int sep = entry.indexOf('=');
|
||||
|
||||
String key;
|
||||
String value;
|
||||
|
||||
if (index != -1) {
|
||||
key = pair.substring(0, index);
|
||||
value = pair.substring(index + 1);
|
||||
if (sep != -1) {
|
||||
key = entry.substring(0, sep);
|
||||
value = entry.substring(sep + 1);
|
||||
} else {
|
||||
key = i == 1 ? DefaultContextKeys.WORLD_KEY : DefaultContextKeys.SERVER_KEY;
|
||||
value = pair;
|
||||
value = entry;
|
||||
}
|
||||
|
||||
if (key.equals("") || key.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (value.equals("") || value.trim().isEmpty()) {
|
||||
if (AbstractContextSet.stringIsEmpty(key) ||
|
||||
AbstractContextSet.stringIsEmpty(value) ||
|
||||
// TODO reconsider a better place to insert / avoid this special case
|
||||
AbstractContextSet.shouldIgnoreEntry(key, value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
|
||||
import net.luckperms.api.context.ContextSet;
|
||||
import net.luckperms.api.context.DefaultContextKeys;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@ -36,7 +37,7 @@ import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
abstract class AbstractContextSet implements ContextSet {
|
||||
public abstract class AbstractContextSet implements ContextSet {
|
||||
|
||||
protected abstract SetMultimap<String, String> backing();
|
||||
|
||||
@ -89,7 +90,7 @@ abstract class AbstractContextSet implements ContextSet {
|
||||
return value.toLowerCase();
|
||||
}
|
||||
|
||||
private static boolean stringIsEmpty(String s) {
|
||||
public static boolean stringIsEmpty(String s) {
|
||||
if (s.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
@ -101,4 +102,8 @@ abstract class AbstractContextSet implements ContextSet {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean shouldIgnoreEntry(String key, String value) {
|
||||
return (key.equalsIgnoreCase(DefaultContextKeys.SERVER_KEY) || key.equalsIgnoreCase(DefaultContextKeys.WORLD_KEY)) && value.equalsIgnoreCase("global");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,10 +25,10 @@
|
||||
|
||||
package me.lucko.luckperms.common.node;
|
||||
|
||||
import me.lucko.luckperms.common.context.contextset.AbstractContextSet;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
|
||||
import net.luckperms.api.context.ContextSet;
|
||||
import net.luckperms.api.context.DefaultContextKeys;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.luckperms.api.node.NodeBuilder;
|
||||
import net.luckperms.api.node.ScopedNode;
|
||||
@ -119,7 +119,7 @@ public abstract class AbstractNodeBuilder<N extends ScopedNode<N, B>, B extends
|
||||
@Override
|
||||
public @NonNull B withContext(@NonNull String key, @NonNull String value) {
|
||||
// TODO reconsider a better place to insert / avoid this special case
|
||||
if ((key.equalsIgnoreCase(DefaultContextKeys.SERVER_KEY) || key.equalsIgnoreCase(DefaultContextKeys.WORLD_KEY)) && value.equalsIgnoreCase("global")) {
|
||||
if (AbstractContextSet.shouldIgnoreEntry(key, value)) {
|
||||
return (B) this;
|
||||
}
|
||||
this.context.add(key, value);
|
||||
|
Loading…
Reference in New Issue
Block a user