Fix player table throwing errors on interaction

This commit is contained in:
rtm516 2020-07-06 00:46:51 +01:00
parent cfaf4051b7
commit 6cdf1eaf43

View file

@ -47,20 +47,19 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Vector;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class GeyserStandaloneGUI { public class GeyserStandaloneGUI {
private static final String[] playerTableHeadings = new String[] { private static final DefaultTableModel playerTableModel = new DefaultTableModel();
LanguageUtils.getLocaleStringLog("geyser.gui.table.ip"),
LanguageUtils.getLocaleStringLog("geyser.gui.table.username")};
private static final List<Integer> ramValues = new ArrayList<>(); private static final List<Integer> ramValues = new ArrayList<>();
private static final ColorPane consolePane = new ColorPane(); private static final ColorPane consolePane = new ColorPane();
private static final GraphPanel ramGraph = new GraphPanel(); private static final GraphPanel ramGraph = new GraphPanel();
private static final JTable playerTable = new JTable(new String[][] { }, playerTableHeadings); private static final JTable playerTable = new JTable(playerTableModel);
private static final int originalFontSize = consolePane.getFont().getSize(); private static final int originalFontSize = consolePane.getFont().getSize();
private static final long MEGABYTE = 1024L * 1024L; private static final long MEGABYTE = 1024L * 1024L;
@ -201,6 +200,9 @@ public class GeyserStandaloneGUI {
ramGraph.setXLabel(LanguageUtils.getLocaleStringLog("geyser.gui.graph.loading")); ramGraph.setXLabel(LanguageUtils.getLocaleStringLog("geyser.gui.graph.loading"));
rightContentPane.add(ramGraph); rightContentPane.add(ramGraph);
playerTableModel.addColumn(LanguageUtils.getLocaleStringLog("geyser.gui.table.ip"));
playerTableModel.addColumn(LanguageUtils.getLocaleStringLog("geyser.gui.table.username"));
JScrollPane playerScrollPane = new JScrollPane(playerTable); JScrollPane playerScrollPane = new JScrollPane(playerTable);
rightContentPane.add(playerScrollPane); rightContentPane.add(playerScrollPane);
@ -288,18 +290,17 @@ public class GeyserStandaloneGUI {
Runnable periodicTask = () -> { Runnable periodicTask = () -> {
if (GeyserConnector.getInstance() != null) { if (GeyserConnector.getInstance() != null) {
// Update player table // Update player table
String[][] playerNames = new String[GeyserConnector.getInstance().getPlayers().size()][2]; playerTableModel.getDataVector().removeAllElements();
int i = 0;
for (Map.Entry<InetSocketAddress, GeyserSession> player : GeyserConnector.getInstance().getPlayers().entrySet()) {
playerNames[i][0] = player.getKey().getHostName();
playerNames[i][1] = player.getValue().getPlayerEntity().getUsername();
i++; for (Map.Entry<InetSocketAddress, GeyserSession> player : GeyserConnector.getInstance().getPlayers().entrySet()) {
Vector row = new Vector();
row.add(player.getKey().getHostName());
row.add(player.getValue().getPlayerEntity().getUsername());
playerTableModel.addRow(row);
} }
DefaultTableModel model = new DefaultTableModel(playerNames, playerTableHeadings); playerTableModel.fireTableDataChanged();
playerTable.setModel(model);
model.fireTableDataChanged();
} }
// Update ram graph // Update ram graph