diff --git a/.gitignore b/.gitignore index 0f182a0..66dd0c3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ *.jar *.war *.ear + +/nbproject/private/ +/build/ +/dist/ diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..fcbdbd9 --- /dev/null +++ b/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project BukkitTelnetClient. + + + diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..408044f --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1053 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..267d65b --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b147f9b6 +build.xml.script.CRC32=71290436 +build.xml.stylesheet.CRC32=28e38971@1.50.2.46 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=b147f9b6 +nbproject/build-impl.xml.script.CRC32=8a821c88 +nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.2.46 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..378deae --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,75 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=BukkitTelnetClient +application.vendor=Steven +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/BukkitTelnetClient.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath=\ + ${libs.Apache_Commons_Lang.classpath}:\ + ${libs.Apache_Commons_Net.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=me.StevenLawson.BukkitTelnetClient.BukkitTelnetClient +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..08ad5eb --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + BukkitTelnetClient + + + + + + + + + diff --git a/src/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java b/src/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java new file mode 100644 index 0000000..9d8ba57 --- /dev/null +++ b/src/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java @@ -0,0 +1,155 @@ +package me.StevenLawson.BukkitTelnetClient; + +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.net.telnet.TelnetClient; + +public class BTC_ConnectionManager +{ + private static final Logger log = Logger.getLogger("BukkitTelnetClient"); + private final BukkitTelnetClient btc; + private final TelnetClient tc; + private Thread connectThread; + private String hostname; + private int port; + private boolean can_do_disconnect = false; + + public BTC_ConnectionManager(BukkitTelnetClient btc) + { + this.btc = btc; + this.tc = new TelnetClient(); + } + + public void trigger_connect(String hostname, int port) + { + btc.getBtn_connect().setEnabled(false); + btc.getTxt_server().setEnabled(false); + btc.getBtn_disconnect().setEnabled(true); + + System.out.println("Connecting to " + hostname + ":" + port + "..."); + + this.hostname = hostname; + this.port = port; + + startConnectThread(); + } + + public void trigger_connect(String hostname_and_port) + { + String[] parts = StringUtils.split(hostname_and_port, ":"); + + if (parts.length <= 1) + { + this.trigger_connect(parts[0], 23); + } + else + { + int t_port = 23; + + try + { + t_port = Integer.parseInt(parts[1]); + } + catch (NumberFormatException ex) + { + } + + this.trigger_connect(parts[0], t_port); + } + } + + public void trigger_disconnect() + { + if (can_do_disconnect) + { + can_do_disconnect = false; + + try + { + tc.disconnect(); + } + catch (IOException ex) + { + log.log(Level.SEVERE, null, ex); + } + } + } + + public void finish_disconnect() + { + btc.getBtn_connect().setEnabled(true); + btc.getTxt_server().setEnabled(true); + btc.getBtn_disconnect().setEnabled(false); + btc.getBtn_send().setEnabled(false); + btc.getTxt_command().setEnabled(false); + + System.out.println("\nDisconnected."); + } + + public void send_command(String text) + { + try + { + System.out.println(text); + tc.getOutputStream().write((text + "\n").getBytes()); + tc.getOutputStream().flush(); + } + catch (IOException ex) + { + log.log(Level.SEVERE, null, ex); + } + } + + private void startConnectThread() + { + if (connectThread != null) + { + return; + } + + connectThread = new Thread(new Runnable() + { + @Override + public void run() + { + try + { + tc.connect(hostname, port); + can_do_disconnect = true; + + btc.getBtn_send().setEnabled(true); + btc.getTxt_command().setEnabled(true); + btc.getTxt_command().requestFocusInWindow(); + + InputStream in = tc.getInputStream(); + + byte[] buffer = new byte[1]; + int ret_read = 0; + do + { + ret_read = in.read(buffer); + if (ret_read > 0) + { + System.out.print(new String(buffer, 0, ret_read)); + } + } + while (ret_read >= 0); + + trigger_disconnect(); + } + catch (Exception ex) + { + log.log(Level.SEVERE, null, ex); + } + + finish_disconnect(); + + connectThread = null; + } + }); + connectThread.start(); + } +} diff --git a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form new file mode 100644 index 0000000..c7b9753 --- /dev/null +++ b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form @@ -0,0 +1,154 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java new file mode 100644 index 0000000..e1bd115 --- /dev/null +++ b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java @@ -0,0 +1,326 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.StevenLawson.BukkitTelnetClient; + +import java.awt.event.KeyEvent; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import javax.swing.SwingUtilities; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; + +/** + + @author + Steven + */ +public class BukkitTelnetClient extends javax.swing.JFrame +{ + private BTC_ConnectionManager connection_mgr; + + public BukkitTelnetClient() + { + initComponents(); + redirectSystemStreams(); + connection_mgr = new BTC_ConnectionManager(this); + } + + private void updateTextPane(final String text) + { + SwingUtilities.invokeLater(new Runnable() + { + @Override + public void run() + { + Document doc = main_output.getDocument(); + try + { + doc.insertString(doc.getLength(), text, null); + } + catch (BadLocationException e) + { + throw new RuntimeException(e); + } + main_output.setCaretPosition(doc.getLength() - 1); + } + }); + } + + private void redirectSystemStreams() + { + OutputStream out = new OutputStream() + { + @Override + public void write(final int b) throws IOException + { + updateTextPane(String.valueOf((char) b)); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException + { + updateTextPane(new String(b, off, len)); + } + + @Override + public void write(byte[] b) throws IOException + { + write(b, 0, b.length); + } + }; + + System.setOut(new PrintStream(out, true)); + System.setErr(new PrintStream(out, true)); + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + main_output = new javax.swing.JTextPane(); + txt_command = new javax.swing.JTextField(); + btn_connect = new javax.swing.JButton(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + txt_server = new javax.swing.JTextField(); + btn_disconnect = new javax.swing.JButton(); + btn_send = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("BukkitTelnetClient"); + + main_output.setEditable(false); + main_output.setFont(new java.awt.Font("Courier New", 0, 12)); // NOI18N + jScrollPane1.setViewportView(main_output); + + txt_command.setEnabled(false); + txt_command.addKeyListener(new java.awt.event.KeyAdapter() { + public void keyPressed(java.awt.event.KeyEvent evt) { + txt_commandKeyPressed(evt); + } + }); + + btn_connect.setText("Connect"); + btn_connect.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + btn_connectMouseClicked(evt); + } + }); + + jLabel1.setText("Command:"); + + jLabel2.setText("Server:"); + + txt_server.setText("tf.madgeekonline.com:28995"); + txt_server.addKeyListener(new java.awt.event.KeyAdapter() { + public void keyPressed(java.awt.event.KeyEvent evt) { + txt_serverKeyPressed(evt); + } + }); + + btn_disconnect.setText("Disconnect"); + btn_disconnect.setEnabled(false); + btn_disconnect.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + btn_disconnectMouseClicked(evt); + } + }); + + btn_send.setText("Send"); + btn_send.setEnabled(false); + btn_send.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + btn_sendMouseClicked(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(18, 18, 18) + .addComponent(txt_command)) + .addGroup(layout.createSequentialGroup() + .addGap(17, 17, 17) + .addComponent(txt_server, javax.swing.GroupLayout.DEFAULT_SIZE, 567, Short.MAX_VALUE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(btn_connect) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btn_disconnect)) + .addComponent(btn_send, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) + .addContainerGap()) + ); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btn_connect, btn_disconnect}); + + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(txt_command, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel1) + .addComponent(btn_send)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(txt_server, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2) + .addComponent(btn_connect) + .addComponent(btn_disconnect)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void txt_serverKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_txt_serverKeyPressed + {//GEN-HEADEREND:event_txt_serverKeyPressed + if (!txt_server.isEnabled()) + { + return; + } + if (evt.getKeyCode() == KeyEvent.VK_ENTER) + { + connection_mgr.trigger_connect(txt_server.getText()); + } + }//GEN-LAST:event_txt_serverKeyPressed + + private void btn_connectMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_btn_connectMouseClicked + {//GEN-HEADEREND:event_btn_connectMouseClicked + if (!btn_connect.isEnabled()) + { + return; + } + connection_mgr.trigger_connect(txt_server.getText()); + }//GEN-LAST:event_btn_connectMouseClicked + + private void btn_disconnectMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_btn_disconnectMouseClicked + {//GEN-HEADEREND:event_btn_disconnectMouseClicked + if (!btn_disconnect.isEnabled()) + { + return; + } + connection_mgr.trigger_disconnect(); + }//GEN-LAST:event_btn_disconnectMouseClicked + + private void txt_commandKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_txt_commandKeyPressed + {//GEN-HEADEREND:event_txt_commandKeyPressed + if (!txt_command.isEnabled()) + { + return; + } + if (evt.getKeyCode() == KeyEvent.VK_ENTER) + { + connection_mgr.send_command(txt_command.getText()); + txt_command.selectAll(); + } + }//GEN-LAST:event_txt_commandKeyPressed + + private void btn_sendMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_btn_sendMouseClicked + {//GEN-HEADEREND:event_btn_sendMouseClicked + if (!btn_send.isEnabled()) + { + return; + } + connection_mgr.send_command(txt_command.getText()); + txt_command.selectAll(); + }//GEN-LAST:event_btn_sendMouseClicked + + public static void main(String args[]) + { + try + { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) + { + if ("Nimbus".equals(info.getName())) + { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } + catch (ClassNotFoundException ex) + { + java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (InstantiationException ex) + { + java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (IllegalAccessException ex) + { + java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (javax.swing.UnsupportedLookAndFeelException ex) + { + java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + + java.awt.EventQueue.invokeLater(new Runnable() + { + public void run() + { + new BukkitTelnetClient().setVisible(true); + } + }); + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btn_connect; + private javax.swing.JButton btn_disconnect; + private javax.swing.JButton btn_send; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextPane main_output; + private javax.swing.JTextField txt_command; + private javax.swing.JTextField txt_server; + // End of variables declaration//GEN-END:variables + + public javax.swing.JButton getBtn_connect() + { + return btn_connect; + } + + public javax.swing.JButton getBtn_disconnect() + { + return btn_disconnect; + } + + public javax.swing.JButton getBtn_send() + { + return btn_send; + } + + public javax.swing.JTextPane getMain_output() + { + return main_output; + } + + public javax.swing.JTextField getTxt_command() + { + return txt_command; + } + + public javax.swing.JTextField getTxt_server() + { + return txt_server; + } +}