Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-17 01:23:43 +02:00
Safely handle bad configuration of 'block-protocols' and 'block-versions' (#2983)
Dieser Commit ist enthalten in:
Ursprung
548f80bb7c
Commit
34f0dbf642
@ -31,6 +31,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.IntPredicate;
|
import java.util.function.IntPredicate;
|
||||||
|
|
||||||
@ -160,10 +161,12 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
private BlockedProtocolVersions loadBlockedProtocolVersions() {
|
private BlockedProtocolVersions loadBlockedProtocolVersions() {
|
||||||
IntSet blockedProtocols = new IntOpenHashSet(getIntegerList("block-protocols"));
|
List<Integer> blockProtocols = getListSafe("block-protocols", Integer.class, "Invalid blocked version protocol found in config: '%s'");
|
||||||
|
List<String> blockVersions = getListSafe("block-versions", String.class, "Invalid blocked version found in config: '%s'");
|
||||||
|
IntSet blockedProtocols = new IntOpenHashSet(blockProtocols);
|
||||||
int lowerBound = -1;
|
int lowerBound = -1;
|
||||||
int upperBound = -1;
|
int upperBound = -1;
|
||||||
for (String s : getStringList("block-versions")) {
|
for (String s : blockVersions) {
|
||||||
if (s.isEmpty()) {
|
if (s.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package com.viaversion.viaversion.util;
|
package com.viaversion.viaversion.util;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
|
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
|
||||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
@ -26,11 +27,7 @@ import org.yaml.snakeyaml.DumperOptions;
|
|||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import org.yaml.snakeyaml.representer.Representer;
|
import org.yaml.snakeyaml.representer.Representer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -214,6 +211,23 @@ public abstract class Config implements ConfigurationProvider {
|
|||||||
return o != null ? (List<String>) o : new ArrayList<>();
|
return o != null ? (List<String>) o : new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> List<T> getListSafe(String key, Class<T> type, String invalidValueMessage) {
|
||||||
|
Object o = this.config.get(key);
|
||||||
|
if (o instanceof List) {
|
||||||
|
List<?> list = (List<?>) o;
|
||||||
|
List<T> filteredValues = new ArrayList<>();
|
||||||
|
for (Object o1 : list) {
|
||||||
|
if (type.isInstance(o1)) {
|
||||||
|
filteredValues.add(type.cast(o1));
|
||||||
|
} else if (invalidValueMessage != null) {
|
||||||
|
Via.getPlatform().getLogger().warning(String.format(invalidValueMessage, o1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredValues;
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable JsonElement getSerializedComponent(String key) {
|
public @Nullable JsonElement getSerializedComponent(String key) {
|
||||||
final Object o = this.config.get(key);
|
final Object o = this.config.get(key);
|
||||||
if (o != null && !((String) o).isEmpty()) {
|
if (o != null && !((String) o).isEmpty()) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren