diff --git a/.gitignore b/.gitignore index a6f89c2..6913fda 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/target/ \ No newline at end of file +/target/ +settings.xml diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java index 3b2efe9..52d0584 100644 --- a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java +++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java @@ -17,7 +17,7 @@ public class BTC_ConnectionManager { private static final Pattern LOGIN_MESSAGE = Pattern.compile("\\[.+?@BukkitTelnet\\]\\$ Logged in as (.+)\\."); - private final TelnetClient telnetClient; + private final TelnetClient telnetClient = new TelnetClient(); private Thread connectThread; private String hostname; private int port; @@ -26,7 +26,6 @@ public class BTC_ConnectionManager public BTC_ConnectionManager() { - this.telnetClient = new TelnetClient(); } public void triggerConnect(final String hostname, final int port) @@ -119,6 +118,12 @@ public class BTC_ConnectionManager BukkitTelnetClient.mainPanel.writeToConsole(new BTC_ConsoleMessage(":" + text)); } + final OutputStream out = this.telnetClient.getOutputStream(); + if (out == null) + { + return; + } + this.telnetClient.getOutputStream().write((text + "\r\n").getBytes()); this.telnetClient.getOutputStream().flush(); } diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_FavoriteButtonsPanel.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_FavoriteButtonsPanel.java new file mode 100644 index 0000000..cd64858 --- /dev/null +++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_FavoriteButtonsPanel.java @@ -0,0 +1,48 @@ +package me.StevenLawson.BukkitTelnetClient; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; +import javax.swing.JButton; +import javax.swing.JPanel; + +public class BTC_FavoriteButtonsPanel extends JPanel +{ + public BTC_FavoriteButtonsPanel(final List buttonList) + { + super.setLayout(new GridLayout(0, 2, 1, 1)); + + final ActionListener actionListener = new ActionListener() + { + @Override + public void actionPerformed(final ActionEvent event) + { + if (BukkitTelnetClient.mainPanel != null) + { + BukkitTelnetClient.mainPanel.getConnectionManager().sendDelayedCommand(event.getActionCommand(), true, 100); + } + } + }; + + for (final FavoriteButtonData buttonData : buttonList) + { + final JButton button = new JButton(); + button.setText(buttonData.getLabel()); + button.setActionCommand(buttonData.getCommand()); + button.addActionListener(actionListener); + + final Dimension max = button.getMaximumSize(); + max.setSize(max.getWidth(), 10); + button.setMaximumSize(max); + + add(button); + } + } + + @Override + public void setLayout(LayoutManager lm) + { + //Disable + } +} diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.form b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.form index 58cfbfb..f2a5c46 100644 --- a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.form +++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.form @@ -368,6 +368,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java index 37996fb..e3ddf97 100644 --- a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java +++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java @@ -1,35 +1,16 @@ package me.StevenLawson.BukkitTelnetClient; -import java.awt.Color; -import java.awt.EventQueue; -import java.awt.Toolkit; +import java.awt.*; import java.awt.datatransfer.StringSelection; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; +import java.awt.event.*; import java.net.URL; -import java.util.ArrayList; -import java.util.LinkedList; +import java.util.*; import java.util.List; import java.util.Queue; -import javax.swing.JCheckBox; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPopupMenu; -import javax.swing.JScrollBar; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; +import javax.swing.*; import javax.swing.Timer; import javax.swing.table.AbstractTableModel; -import javax.swing.text.BadLocationException; -import javax.swing.text.SimpleAttributeSet; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyleContext; -import javax.swing.text.StyledDocument; +import javax.swing.text.*; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.SystemUtils; @@ -39,8 +20,30 @@ public class BTC_MainPanel extends javax.swing.JFrame private final List playerList = new ArrayList<>(); private final PlayerListTableModel playerListTableModel = new PlayerListTableModel(playerList); + private final List favButtonList = new ArrayList<>(); + public BTC_MainPanel() { + favButtonList.add(new FavoriteButtonData("Op All", "opall")); + favButtonList.add(new FavoriteButtonData("Deop All", "deopall")); + favButtonList.add(new FavoriteButtonData("Nick Clean", "nickclean")); + favButtonList.add(new FavoriteButtonData("Adminmode ON", "adminmode on")); + favButtonList.add(new FavoriteButtonData("Adminmode OFF", "adminmode off")); + favButtonList.add(new FavoriteButtonData("Cake", "cake")); + favButtonList.add(new FavoriteButtonData("Mob Purge", "mp")); + favButtonList.add(new FavoriteButtonData("Remove Drops", "rd")); + favButtonList.add(new FavoriteButtonData("Purge All", "purgeall")); + favButtonList.add(new FavoriteButtonData("Set Limit = 500", "setl")); + favButtonList.add(new FavoriteButtonData("Stop Server", "stop")); + favButtonList.add(new FavoriteButtonData("Toggle Water Placement", "toggle waterplace")); + favButtonList.add(new FavoriteButtonData("Toggle Fire Placement", "toggle fireplace")); + favButtonList.add(new FavoriteButtonData("Toggle Lava Placement", "toggle lavaplace")); + favButtonList.add(new FavoriteButtonData("Toggle Fluid Spread", "toggle fluidspread")); + favButtonList.add(new FavoriteButtonData("Toggle Lava Damage", "toggle lavadmg")); + favButtonList.add(new FavoriteButtonData("Toggle Fire Spread", "toggle firespread")); + favButtonList.add(new FavoriteButtonData("Toggle Lockdown", "toggle lockdown")); + favButtonList.add(new FavoriteButtonData("Toggle Explosives", "toggle explosives")); + initComponents(); } @@ -68,7 +71,7 @@ public class BTC_MainPanel extends javax.swing.JFrame setupTablePopup(); - this.connectionManager.updateTitle(false); + this.getConnectionManager().updateTitle(false); this.tblPlayers.setModel(playerListTableModel); @@ -352,7 +355,7 @@ public class BTC_MainPanel extends javax.swing.JFrame final String output = String.format(_command.getFormat(), _player.getName()); - BTC_MainPanel.this.connectionManager.sendDelayedCommand(output, true, 100); + BTC_MainPanel.this.getConnectionManager().sendDelayedCommand(output, true, 100); } else if (_source instanceof PlayerListPopupItem) { @@ -482,7 +485,7 @@ public class BTC_MainPanel extends javax.swing.JFrame loadServerList(); - connectionManager.triggerConnect(entry.getAddress()); + getConnectionManager().triggerConnect(entry.getAddress()); } @SuppressWarnings("unchecked") @@ -513,6 +516,9 @@ public class BTC_MainPanel extends javax.swing.JFrame chkIgnoreServerCommands = new javax.swing.JCheckBox(); chkShowChatOnly = new javax.swing.JCheckBox(); chkIgnoreErrors = new javax.swing.JCheckBox(); + jPanel4 = new javax.swing.JPanel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jPanel5 = new BTC_FavoriteButtonsPanel(favButtonList); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("BukkitTelnetClient"); @@ -712,6 +718,30 @@ public class BTC_MainPanel extends javax.swing.JFrame jTabbedPane1.addTab("Filters", jPanel1); + jScrollPane1.setBorder(null); + + jPanel5.setLayout(null); + jScrollPane1.setViewportView(jPanel5); + + javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); + jPanel4.setLayout(jPanel4Layout); + jPanel4Layout.setHorizontalGroup( + jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel4Layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 293, Short.MAX_VALUE) + .addContainerGap()) + ); + jPanel4Layout.setVerticalGroup( + jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel4Layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) + .addContainerGap()) + ); + + jTabbedPane1.addTab("Commands", jPanel4); + splitPane.setRightComponent(jTabbedPane1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); @@ -742,7 +772,7 @@ public class BTC_MainPanel extends javax.swing.JFrame } if (evt.getKeyCode() == KeyEvent.VK_ENTER) { - connectionManager.sendCommand(txtCommand.getText()); + getConnectionManager().sendCommand(txtCommand.getText()); txtCommand.selectAll(); } }//GEN-LAST:event_txtCommandKeyPressed @@ -762,7 +792,7 @@ public class BTC_MainPanel extends javax.swing.JFrame { return; } - connectionManager.triggerDisconnect(); + getConnectionManager().triggerDisconnect(); }//GEN-LAST:event_btnDisconnectActionPerformed private void btnSendActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSendActionPerformed @@ -771,7 +801,7 @@ public class BTC_MainPanel extends javax.swing.JFrame { return; } - connectionManager.sendCommand(txtCommand.getText()); + getConnectionManager().sendCommand(txtCommand.getText()); txtCommand.selectAll(); }//GEN-LAST:event_btnSendActionPerformed @@ -802,6 +832,9 @@ public class BTC_MainPanel extends javax.swing.JFrame private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; + private javax.swing.JPanel jPanel4; + private javax.swing.JPanel jPanel5; + private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JTextPane mainOutput; @@ -872,4 +905,9 @@ public class BTC_MainPanel extends javax.swing.JFrame { return playerList; } + + public BTC_ConnectionManager getConnectionManager() + { + return connectionManager; + } } diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/FavoriteButtonData.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/FavoriteButtonData.java new file mode 100644 index 0000000..85a3d9e --- /dev/null +++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/FavoriteButtonData.java @@ -0,0 +1,23 @@ +package me.StevenLawson.BukkitTelnetClient; + +public class FavoriteButtonData +{ + private final String label; + private final String command; + + public FavoriteButtonData(String label, String command) + { + this.label = label; + this.command = command; + } + + public String getLabel() + { + return label; + } + + public String getCommand() + { + return command; + } +}