use of net.minecraft.client.option.ServerList in project Client by MatHax.
the class ServerFinderScreen method saveToFile.
private void saveToFile() {
int newIPs = 0;
Path filePath = MatHax.GAME_FOLDER.toPath().resolve("servers.txt");
Set<IPAddress> hashedIPs = new HashSet<>();
if (Files.exists(filePath)) {
try {
List<String> ips = Files.readAllLines(filePath);
for (String ip : ips) {
IPAddress parsedIP = IPAddress.fromText(ip);
if (parsedIP != null)
hashedIPs.add(parsedIP);
}
} catch (IOException e) {
e.printStackTrace();
}
}
ServerList servers = multiplayerScreen.getServerList();
for (int i = 0; i < servers.size(); i++) {
ServerInfo info = servers.get(i);
IPAddress addr = IPAddress.fromText(info.address);
if (addr != null && hashedIPs.add(addr))
newIPs++;
}
StringBuilder fileOutput = new StringBuilder();
for (IPAddress ip : hashedIPs) {
String stringIP = ip.toString();
if (stringIP != null)
fileOutput.append(stringIP).append("\n");
}
try {
Files.writeString(filePath, fileOutput.toString());
} catch (IOException e) {
e.printStackTrace();
}
MatHax.LOG.info("Saved " + newIPs + " new IP" + (newIPs == 1 ? "" : "s"));
}
Aggregations