mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-18 07:07:37 +01:00
Enforce removal of server=global and world=global contexts at a higher level
This commit is contained in:
parent
13ebc87b29
commit
5a6176def5
@ -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.CommandException;
|
||||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||||
import me.lucko.luckperms.common.commands.user.UserParentCommand;
|
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.ImmutableContextSetImpl;
|
||||||
import me.lucko.luckperms.common.context.contextset.MutableContextSetImpl;
|
import me.lucko.luckperms.common.context.contextset.MutableContextSetImpl;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
@ -193,8 +192,7 @@ public class ArgumentParser {
|
|||||||
value = entry;
|
value = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO reconsider a better place to insert / avoid this special case
|
if (!Context.isValidKey(key) || !Context.isValidValue(value)) {
|
||||||
if (!Context.isValidKey(key) || !Context.isValidValue(value) || AbstractContextSet.isGlobalServerWorldEntry(key, value)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ public abstract class AbstractContextSet implements ContextSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isGlobalServerWorldEntry(String key, String value) {
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,15 @@ public final class ImmutableContextSetImpl extends AbstractContextSet implements
|
|||||||
public static final ImmutableContextSetImpl EMPTY = new ImmutableContextSetImpl(ImmutableSetMultimap.of());
|
public static final ImmutableContextSetImpl EMPTY = new ImmutableContextSetImpl(ImmutableSetMultimap.of());
|
||||||
|
|
||||||
public static ImmutableContextSet of(String key, String value) {
|
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;
|
private final ImmutableSetMultimap<String, String> map;
|
||||||
@ -215,6 +223,10 @@ public final class ImmutableContextSetImpl extends AbstractContextSet implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void put(String key, String value) {
|
private void put(String key, String value) {
|
||||||
|
// special case for server=global and world=global
|
||||||
|
if (isGlobalServerWorldEntry(key, value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
builder().put(key, value);
|
builder().put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,15 @@ public final class MutableContextSetImpl extends AbstractContextSet implements M
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(@NonNull String key, @NonNull String value) {
|
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
|
@Override
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.node;
|
package me.lucko.luckperms.common.node;
|
||||||
|
|
||||||
import me.lucko.luckperms.common.context.contextset.AbstractContextSet;
|
|
||||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||||
|
|
||||||
import net.luckperms.api.context.ContextSet;
|
import net.luckperms.api.context.ContextSet;
|
||||||
@ -118,10 +117,6 @@ public abstract class AbstractNodeBuilder<N extends ScopedNode<N, B>, B extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull B withContext(@NonNull String key, @NonNull String value) {
|
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);
|
this.context.add(key, value);
|
||||||
return (B) this;
|
return (B) this;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user