diff --git a/common/src/main/java/me/lucko/luckperms/common/command/utils/ArgumentParser.java b/common/src/main/java/me/lucko/luckperms/common/command/utils/ArgumentParser.java index 334e188b8..e44b5c11b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/utils/ArgumentParser.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/utils/ArgumentParser.java @@ -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; } diff --git a/common/src/main/java/me/lucko/luckperms/common/context/contextset/AbstractContextSet.java b/common/src/main/java/me/lucko/luckperms/common/context/contextset/AbstractContextSet.java index 5d5de1bef..f2dc00125 100644 --- a/common/src/main/java/me/lucko/luckperms/common/context/contextset/AbstractContextSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/context/contextset/AbstractContextSet.java @@ -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"); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/context/contextset/ImmutableContextSetImpl.java b/common/src/main/java/me/lucko/luckperms/common/context/contextset/ImmutableContextSetImpl.java index ad3f7e37d..2765a76b3 100644 --- a/common/src/main/java/me/lucko/luckperms/common/context/contextset/ImmutableContextSetImpl.java +++ b/common/src/main/java/me/lucko/luckperms/common/context/contextset/ImmutableContextSetImpl.java @@ -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 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); } diff --git a/common/src/main/java/me/lucko/luckperms/common/context/contextset/MutableContextSetImpl.java b/common/src/main/java/me/lucko/luckperms/common/context/contextset/MutableContextSetImpl.java index 1c307b59f..d7699131d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/context/contextset/MutableContextSetImpl.java +++ b/common/src/main/java/me/lucko/luckperms/common/context/contextset/MutableContextSetImpl.java @@ -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 diff --git a/common/src/main/java/me/lucko/luckperms/common/node/AbstractNodeBuilder.java b/common/src/main/java/me/lucko/luckperms/common/node/AbstractNodeBuilder.java index f8df7866e..35e927706 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/AbstractNodeBuilder.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/AbstractNodeBuilder.java @@ -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, 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; }