Playerlist and Serverlist combos are properly updated. It is possible to send commands to servers.
This commit is contained in:
@ -42,7 +42,8 @@ public class GUI implements ActionListener {
|
||||
private JComboBox<String> profiles;
|
||||
private final JLabel lblStatuslabel = new JLabel("Servers are stopped");
|
||||
//Server controls
|
||||
private JComboBox targetServer, targetPlayer;
|
||||
private JComboBox<String> targetServer;
|
||||
private JComboBox<String> targetPlayer;
|
||||
private JButton btnKick, btnBan, btnOp, btnDeop, btnCustomCommand, btnSaveserver, btnReload, btnServerConsoles;
|
||||
private JTextField customCommand;
|
||||
//Text
|
||||
@ -52,13 +53,13 @@ public class GUI implements ActionListener {
|
||||
private String downloadJarsText;
|
||||
private String aboutText;
|
||||
|
||||
private final ArrayList<String> globalPlayers;
|
||||
|
||||
|
||||
private JTabbedPane serversPane;
|
||||
|
||||
private final ArrayList<ServerTab> serverTabs = new ArrayList<>();
|
||||
|
||||
//TODO: Update target server list with the list of servers when adding or removing a server.
|
||||
|
||||
/**
|
||||
* Create the application window.
|
||||
*/
|
||||
@ -66,6 +67,36 @@ public class GUI implements ActionListener {
|
||||
initialize();
|
||||
loadMessages();
|
||||
gui = this;
|
||||
this.globalPlayers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addPlayer(String name) {
|
||||
this.globalPlayers.add(name);
|
||||
this.updatePlayers();
|
||||
}
|
||||
|
||||
public void removePlayer(String name) {
|
||||
for (int i = 0; i < this.globalPlayers.size(); i++) {
|
||||
if (this.globalPlayers.get(i).equals(name)) {
|
||||
this.globalPlayers.remove(i);
|
||||
}
|
||||
}
|
||||
this.updatePlayers();
|
||||
}
|
||||
|
||||
private void updatePlayers() {
|
||||
String selectedServerValue;
|
||||
Object selectedServer = targetServer.getSelectedItem();
|
||||
if (selectedServer != null) {
|
||||
targetPlayer.removeAllItems();
|
||||
selectedServerValue = selectedServer.toString();
|
||||
if (selectedServerValue.equals("All")) {
|
||||
for (String player : this.globalPlayers) targetPlayer.addItem(player);
|
||||
} else {
|
||||
for (String player : this.currentProfile().getCollection(selectedServerValue).getServer().getPlayers())
|
||||
targetPlayer.addItem(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setStatus(String text) {
|
||||
@ -112,7 +143,6 @@ public class GUI implements ActionListener {
|
||||
i = this.serverTabs.size();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
@ -274,11 +304,11 @@ public class GUI implements ActionListener {
|
||||
SpringLayout sl_panel_1 = new SpringLayout();
|
||||
controlServers.setLayout(sl_panel_1);
|
||||
|
||||
targetServer = new JComboBox();
|
||||
targetServer = new JComboBox<>();
|
||||
sl_panel_1.putConstraint(SpringLayout.NORTH, targetServer, 10, SpringLayout.NORTH, controlServers);
|
||||
controlServers.add(targetServer);
|
||||
|
||||
targetPlayer = new JComboBox();
|
||||
targetPlayer = new JComboBox<>();
|
||||
sl_panel_1.putConstraint(SpringLayout.NORTH, targetPlayer, 6, SpringLayout.SOUTH, targetServer);
|
||||
targetPlayer.setEditable(true);
|
||||
controlServers.add(targetPlayer);
|
||||
@ -334,6 +364,7 @@ public class GUI implements ActionListener {
|
||||
sl_panel_1.putConstraint(SpringLayout.EAST, btnCustomCommand, 0, SpringLayout.EAST, btnOp);
|
||||
controlServers.add(btnCustomCommand);
|
||||
btnCustomCommand.addActionListener(this);
|
||||
frame.getRootPane().setDefaultButton(btnCustomCommand);
|
||||
|
||||
customCommand = new JTextField();
|
||||
sl_panel_1.putConstraint(SpringLayout.WEST, customCommand, 10, SpringLayout.WEST, controlServers);
|
||||
@ -391,6 +422,14 @@ public class GUI implements ActionListener {
|
||||
serverTabs.add(serverTab);
|
||||
}
|
||||
|
||||
public void updateSelectServers() {
|
||||
this.targetServer.removeAllItems();
|
||||
this.targetServer.addItem("All");
|
||||
for (Collection collection : currentProfile().getCollections()) {
|
||||
this.targetServer.addItem(collection.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String selectedServerValue = null, selectedPlayerValue = null;
|
||||
@ -459,7 +498,8 @@ public class GUI implements ActionListener {
|
||||
}
|
||||
} else if (e.getSource() == btnCustomCommand) {
|
||||
if (selectedServerValue != null) {
|
||||
currentProfile().sendCommand(selectedServerValue, customCommand.getSelectedText());
|
||||
currentProfile().sendCommand(selectedServerValue, customCommand.getText());
|
||||
customCommand.setText("");
|
||||
}
|
||||
} else if (e.getSource() == btnSaveserver) {
|
||||
if (selectedServerValue != null) {
|
||||
|
Reference in New Issue
Block a user