mirror of
https://github.com/TotalFreedomMC/ZeroTelnetClient.git
synced 2024-12-22 16:25:14 +00:00
Switched usage of config in main program.
TODO: -Server list order. -"reason" checkbox and dialog. -"favorite" command buttons + config
This commit is contained in:
parent
0f00da9dcb
commit
0f25e91082
2 changed files with 10 additions and 46 deletions
|
@ -77,6 +77,10 @@ public class BTC_ConfigLoader
|
||||||
|
|
||||||
public boolean save()
|
public boolean save()
|
||||||
{
|
{
|
||||||
|
final HashSet<ServerEntry> uniqueServers = new HashSet<>(this.servers);
|
||||||
|
this.servers.clear();
|
||||||
|
this.servers.addAll(uniqueServers);
|
||||||
|
|
||||||
return generateXML(new File(SETTINGS_FILE));
|
return generateXML(new File(SETTINGS_FILE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +187,7 @@ public class BTC_ConfigLoader
|
||||||
while ((line = in.readLine()) != null)
|
while ((line = in.readLine()) != null)
|
||||||
{
|
{
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
oldServers.add(new ServerEntry("imported", line));
|
oldServers.add(new ServerEntry("legacy", line));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,10 @@ import javax.swing.text.StyledDocument;
|
||||||
|
|
||||||
public class BTC_MainPanel extends javax.swing.JFrame
|
public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
{
|
{
|
||||||
private static final String SERVERS_FILE_NAME = "btc_servers.cfg";
|
|
||||||
|
|
||||||
public static final ByteArrayOutputStream CONSOLE = new ByteArrayOutputStream();
|
public static final ByteArrayOutputStream CONSOLE = new ByteArrayOutputStream();
|
||||||
public static final PrintStream CONSOLE_STREAM = new PrintStream(CONSOLE);
|
public static final PrintStream CONSOLE_STREAM = new PrintStream(CONSOLE);
|
||||||
|
|
||||||
private final BTC_ConnectionManager connectionManager = new BTC_ConnectionManager();
|
private final BTC_ConnectionManager connectionManager = new BTC_ConnectionManager();
|
||||||
private final LinkedList<String> serverList = new LinkedList<>();
|
|
||||||
|
|
||||||
public BTC_MainPanel()
|
public BTC_MainPanel()
|
||||||
{
|
{
|
||||||
|
@ -444,29 +441,11 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
|
|
||||||
public final void loadServerList()
|
public final void loadServerList()
|
||||||
{
|
{
|
||||||
try
|
txtServer.removeAllItems();
|
||||||
{
|
|
||||||
serverList.clear();
|
|
||||||
txtServer.removeAllItems();
|
|
||||||
|
|
||||||
final File file = new File(SERVERS_FILE_NAME);
|
for (BTC_ConfigLoader.ServerEntry serverEntry : BukkitTelnetClient.config.getServers())
|
||||||
if (file.exists())
|
|
||||||
{
|
|
||||||
try (final BufferedReader in = new BufferedReader(new FileReader(file)))
|
|
||||||
{
|
|
||||||
String line;
|
|
||||||
while ((line = in.readLine()) != null)
|
|
||||||
{
|
|
||||||
line = line.trim();
|
|
||||||
serverList.add(line);
|
|
||||||
txtServer.addItem(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
{
|
||||||
BukkitTelnetClient.LOGGER.log(Level.SEVERE, null, ex);
|
txtServer.addItem(serverEntry.getAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,28 +459,9 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
BukkitTelnetClient.config.getServers().add(new BTC_ConfigLoader.ServerEntry("legacy", selectedServer));
|
||||||
{
|
|
||||||
if (serverList.contains(selectedServer))
|
|
||||||
{
|
|
||||||
serverList.remove(selectedServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
serverList.addFirst(selectedServer);
|
BukkitTelnetClient.config.save();
|
||||||
try (final BufferedWriter out = new BufferedWriter(new FileWriter(new File(SERVERS_FILE_NAME))))
|
|
||||||
{
|
|
||||||
for (final String server : serverList)
|
|
||||||
{
|
|
||||||
out.write(server + '\n');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
BukkitTelnetClient.LOGGER.log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
loadServerList();
|
|
||||||
|
|
||||||
connectionManager.triggerConnect(selectedServer);
|
connectionManager.triggerConnect(selectedServer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue