diff --git a/src/main/java/com/provismet/vmcmc/ClientVMC.java b/src/main/java/com/provismet/vmcmc/ClientVMC.java index 224f4d7..9a398f4 100644 --- a/src/main/java/com/provismet/vmcmc/ClientVMC.java +++ b/src/main/java/com/provismet/vmcmc/ClientVMC.java @@ -24,8 +24,8 @@ public static Identifier identifier (String path) { @Override public void onInitializeClient () { - Pair portInfo = Config.readJSON(); - PacketSender.initPort(portInfo.getLeft(), portInfo.getRight()); + Config.ConnectionInfo portInfo = Config.readJSON(); + PacketSender.initPort(portInfo.host(), portInfo.port()); CaptureRegistry.registerStandardEvents(); FabricLoader.getInstance().getEntrypointContainers(MODID, VmcApi.class).forEach(entrypoint -> { diff --git a/src/main/java/com/provismet/vmcmc/config/Config.java b/src/main/java/com/provismet/vmcmc/config/Config.java index 9602b94..6d154ac 100644 --- a/src/main/java/com/provismet/vmcmc/config/Config.java +++ b/src/main/java/com/provismet/vmcmc/config/Config.java @@ -9,7 +9,6 @@ import com.provismet.vmcmc.vmc.PacketSender; import net.minecraft.util.Identifier; -import net.minecraft.util.Pair; public class Config { private static final String HOST = "host"; @@ -21,7 +20,7 @@ public class Config { private static String host = PacketSender.LOCALHOST; private static int port = PacketSender.DEFAULT_PORT; - public static Pair readJSON () { + public static ConnectionInfo readJSON () { try { FileReader reader = new FileReader(FILEPATH); JsonReader parser = new JsonReader(reader); @@ -47,16 +46,16 @@ public static Pair readJSON () { } } parser.close(); - return new Pair<>(host, port); + return new ConnectionInfo(host, port); } catch (FileNotFoundException e) { ClientVMC.LOGGER.warn("Config not found, creating default config."); saveJSON(); - return new Pair<>(PacketSender.LOCALHOST, PacketSender.DEFAULT_PORT); + return ConnectionInfo.getDefault(); } catch (Exception e) { ClientVMC.LOGGER.warn("Config could not be read, using default parameters.", e); - return new Pair<>(PacketSender.LOCALHOST, PacketSender.DEFAULT_PORT); + return ConnectionInfo.getDefault(); } } @@ -71,7 +70,7 @@ public static void saveJSON () { writer.write(simpleJSON); writer.close(); } - catch (Exception e) { + catch (Exception ignored) { } } @@ -106,7 +105,13 @@ public static void setPort (int newPort) { port = newPort; } else { - ClientVMC.LOGGER.error("Attempted to set illegal port: " + newPort); + ClientVMC.LOGGER.error("Attempted to set illegal port: {}", newPort); + } + } + + public record ConnectionInfo (String host, int port) { + public static ConnectionInfo getDefault () { + return new ConnectionInfo(PacketSender.LOCALHOST, PacketSender.DEFAULT_PORT); } } }