3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 14:30:17 +01:00

Better config JSON encoding (something is broken with Cloudflare; we'll figure it out

Dieser Commit ist enthalten in:
Camotoy 2024-09-26 16:39:09 -04:00
Ursprung c4bed6509c
Commit b2ea5792be
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
4 geänderte Dateien mit 43 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -32,7 +32,9 @@ dependencies {
api(libs.bundles.protocol)
api(libs.minecraftauth)
api(libs.minecraftauth) {
exclude("com.google.code.gson", "gson")
}
api(libs.mcprotocollib) {
exclude("io.netty", "netty-all")
exclude("net.raphimc", "MinecraftAuth")

Datei anzeigen

@ -28,7 +28,6 @@ package org.geysermc.geyser.command.defaults;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.util.TriState;
import org.geysermc.geyser.command.GeyserCommand;
@ -37,6 +36,7 @@ import org.geysermc.geyser.dump.DumpInfo;
import org.geysermc.geyser.text.AsteriskSerializer;
import org.geysermc.geyser.text.ChatColor;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.util.JsonUtils;
import org.geysermc.geyser.util.WebUtils;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.context.CommandContext;
@ -145,7 +145,7 @@ public class DumpCommand extends GeyserCommand {
JsonObject responseNode;
try {
response = WebUtils.post(DUMP_URL + "documents", dumpData);
responseNode = (JsonObject) new JsonParser().parse(response);
responseNode = JsonUtils.parseJson(response);
} catch (IOException e) {
source.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.upload_error", source.locale()));
geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.dump.upload_error_short"), e);

Datei anzeigen

@ -28,18 +28,22 @@ package org.geysermc.geyser.dump;
import com.google.common.hash.Hashing;
import com.google.common.io.ByteSource;
import com.google.common.io.Files;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.annotations.SerializedName;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import lombok.Getter;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
import org.geysermc.floodgate.util.DeviceOs;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.extension.Extension;
import org.geysermc.geyser.configuration.AdvancedConfig;
import org.geysermc.geyser.network.GameProtocol;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.AsteriskSerializer;
@ -106,12 +110,13 @@ public class DumpInfo {
ConfigurationNode configNode = CommentedConfigurationNode.root(options);
configNode.set(geyser.config());
this.config = configNode.get(geyser.config().getClass());
this.config = toGson(configNode);
ConfigurationNode advancedConfigNode = CommentedConfigurationNode.root(options);
advancedConfigNode.set(geyser.config().advanced());
this.advancedConfig = advancedConfigNode.get(AdvancedConfig.class);
this.advancedConfig = toGson(advancedConfigNode);
} catch (SerializationException e) {
e.printStackTrace();
if (geyser.config().debugMode()) {
e.printStackTrace();
}
@ -164,6 +169,36 @@ public class DumpInfo {
}
}
private JsonElement toGson(ConfigurationNode node) {
if (node.isMap()) {
JsonObject object = new JsonObject();
node.childrenMap().forEach((key, value) -> {
JsonElement json = toGson(value);
object.add(key.toString(), json);
});
return object;
} else if (node.isList()) {
JsonArray array = new JsonArray();
node.childrenList().forEach(childNode -> array.add(toGson(childNode)));
return array;
} else {
return convertRawScalar(node);
}
}
private JsonElement convertRawScalar(ConfigurationNode node) {
final @Nullable Object value = node.rawScalar();
if (value == null) {
return JsonNull.INSTANCE;
} else if (value instanceof Number n) {
return new JsonPrimitive(n);
} else if (value instanceof Boolean b) {
return new JsonPrimitive(b);
} else {
return new JsonPrimitive(value.toString());
}
}
@Getter
public static class VersionInfo {
private final String name;

Datei anzeigen

@ -53,7 +53,6 @@ public class ConfigLoaderTest {
File file = tempDirectory.resolve("config.yml").toFile();
// Sorry Konicai...
forAllConfigs(type -> {
new ConfigLoader(file).transformer(n -> this.config1 = n.copy()).load(type);
long initialModification = file.lastModified();