From 73640975ce6e6f4abd67c7a5eca9919832d20aa7 Mon Sep 17 00:00:00 2001 From: Tobias Rath Date: Mon, 12 Dec 2022 14:54:12 +0100 Subject: Fix ServerAddressAdapter for IPv6 (#329) --- .../nochatreports/config/ServerAddressAdapter.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/main/java/com/aizistral/nochatreports') diff --git a/src/main/java/com/aizistral/nochatreports/config/ServerAddressAdapter.java b/src/main/java/com/aizistral/nochatreports/config/ServerAddressAdapter.java index 9a90b6e..c68aed9 100644 --- a/src/main/java/com/aizistral/nochatreports/config/ServerAddressAdapter.java +++ b/src/main/java/com/aizistral/nochatreports/config/ServerAddressAdapter.java @@ -1,19 +1,14 @@ package com.aizistral.nochatreports.config; -import java.io.IOException; -import java.lang.reflect.Type; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.InstanceCreator; import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.multiplayer.resolver.ServerAddress; +import java.io.IOException; + @Environment(EnvType.CLIENT) public class ServerAddressAdapter extends TypeAdapter { public static final ServerAddressAdapter INSTANCE = new ServerAddressAdapter(); @@ -25,17 +20,16 @@ public class ServerAddressAdapter extends TypeAdapter { @Override public ServerAddress read(JsonReader reader) throws IOException { String string = reader.nextString(); - String address[] = string.split(":"); - if (address.length != 2) + if (!ServerAddress.isValidAddress(string)) throw new IOException("Incorrect server address format: " + string); - return new ServerAddress(address[0], Integer.valueOf(address[1])); + return ServerAddress.parseString(string); } @Override public void write(JsonWriter writer, ServerAddress address) throws IOException { - writer.value(address.getHost() + ":" + address.getPort()); + writer.value(address.toString()); } } -- cgit v1.2.3