Ignore empty string world names in Bukkit WorldCalculator (#2119)

This commit is contained in:
Luck committed 2020-03-30 14:32:27 +01:00
1 parent 42e9f43443
commit b65639cd76
5 files changed
+63 -22

No files matched your search

@@ -39,6 +39,7 @@ import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.storage.misc.DataConstraints;
import me.lucko.luckperms.common.util.DurationParser;
import net.luckperms.api.context.Context;
import net.luckperms.api.context.DefaultContextKeys;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.context.MutableContextSet;
@@ -192,10 +193,8 @@ public class ArgumentParser {
value = entry;
}
if (AbstractContextSet.stringIsEmpty(key) ||
AbstractContextSet.stringIsEmpty(value) ||
// TODO reconsider a better place to insert / avoid this special case
AbstractContextSet.shouldIgnoreEntry(key, value)) {
// TODO reconsider a better place to insert / avoid this special case
if (!Context.isValidKey(key) || !Context.isValidValue(value) || AbstractContextSet.isGlobalServerWorldEntry(key, value)) {
continue;
}
@@ -28,6 +28,7 @@ package me.lucko.luckperms.common.context.contextset;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.SetMultimap;
import net.luckperms.api.context.Context;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.context.DefaultContextKeys;
@@ -76,7 +77,7 @@ public abstract class AbstractContextSet implements ContextSet {
static String sanitizeKey(String key) {
Objects.requireNonNull(key, "key is null");
if (stringIsEmpty(key)) {
if (!Context.isValidKey(key)) {
throw new IllegalArgumentException("key is (effectively) empty");
}
return key.toLowerCase();
@@ -84,25 +85,13 @@ public abstract class AbstractContextSet implements ContextSet {
static String sanitizeValue(String value) {
Objects.requireNonNull(value, "value is null");
if (stringIsEmpty(value)) {
if (!Context.isValidValue(value)) {
throw new IllegalArgumentException("value is (effectively) empty");
}
return value.toLowerCase();
}
public static boolean stringIsEmpty(String s) {
if (s.isEmpty()) {
return true;
}
for (char c : s.toCharArray()) {
if (c != ' ') {
return false;
}
}
return true;
}
public static boolean shouldIgnoreEntry(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");
}
@@ -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 (AbstractContextSet.shouldIgnoreEntry(key, value)) {
if (AbstractContextSet.isGlobalServerWorldEntry(key, value)) {
return (B) this;
}
this.context.add(key, value);