Enforce removal of server=global and world=global contexts at a higher level

This commit is contained in:
Luck 2020-05-21 17:30:13 +01:00
parent 13ebc87b29
commit 5a6176def5
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 24 additions and 11 deletions

View File

@ -30,7 +30,6 @@ 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;
@ -193,8 +192,7 @@ public class ArgumentParser {
value = entry;
}
// TODO reconsider a better place to insert / avoid this special case
if (!Context.isValidKey(key) || !Context.isValidValue(value) || AbstractContextSet.isGlobalServerWorldEntry(key, value)) {
if (!Context.isValidKey(key) || !Context.isValidValue(value)) {
continue;
}

View File

@ -123,7 +123,7 @@ public abstract class AbstractContextSet implements ContextSet {
}
public static boolean isGlobalServerWorldEntry(String key, String value) {
return (key.equalsIgnoreCase(DefaultContextKeys.SERVER_KEY) || key.equalsIgnoreCase(DefaultContextKeys.WORLD_KEY)) && value.equalsIgnoreCase("global");
return (key.equals(DefaultContextKeys.SERVER_KEY) || key.equals(DefaultContextKeys.WORLD_KEY)) && value.equals("global");
}
}

View File

@ -52,7 +52,15 @@ public final class ImmutableContextSetImpl extends AbstractContextSet implements
public static final ImmutableContextSetImpl EMPTY = new ImmutableContextSetImpl(ImmutableSetMultimap.of());
public static ImmutableContextSet of(String key, String value) {
return new ImmutableContextSetImpl(ImmutableSetMultimap.of(sanitizeKey(key), sanitizeValue(value)));
key = sanitizeKey(key);
value = sanitizeValue(value);
// special case for 'server=global' and 'world=global'
if (isGlobalServerWorldEntry(key, value)) {
return EMPTY;
}
return new ImmutableContextSetImpl(ImmutableSetMultimap.of(key, sanitizeValue(value)));
}
private final ImmutableSetMultimap<String, String> map;
@ -215,6 +223,10 @@ public final class ImmutableContextSetImpl extends AbstractContextSet implements
}
private void put(String key, String value) {
// special case for server=global and world=global
if (isGlobalServerWorldEntry(key, value)) {
return;
}
builder().put(key, value);
}

View File

@ -157,7 +157,15 @@ public final class MutableContextSetImpl extends AbstractContextSet implements M
@Override
public void add(@NonNull String key, @NonNull String value) {
this.map.put(sanitizeKey(key), sanitizeValue(value));
key = sanitizeKey(key);
value = sanitizeValue(value);
// special case for server=global and world=global
if (isGlobalServerWorldEntry(key, value)) {
return;
}
this.map.put(key, value);
}
@Override

View File

@ -25,7 +25,6 @@
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;
@ -118,10 +117,6 @@ 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 (AbstractContextSet.isGlobalServerWorldEntry(key, value)) {
return (B) this;
}
this.context.add(key, value);
return (B) this;
}