mirror of
https://github.com/TotalFreedomMC/ZeroTelnetClient.git
synced 2024-12-23 00:35:22 +00:00
v1.0.0.0 - Initial Commit
This commit is contained in:
parent
dc2193456b
commit
12c5e384ae
10 changed files with 1867 additions and 0 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -4,3 +4,7 @@
|
||||||
*.jar
|
*.jar
|
||||||
*.war
|
*.war
|
||||||
*.ear
|
*.ear
|
||||||
|
|
||||||
|
/nbproject/private/
|
||||||
|
/build/
|
||||||
|
/dist/
|
||||||
|
|
74
build.xml
Normal file
74
build.xml
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- You may freely edit this file. See commented blocks below for -->
|
||||||
|
<!-- some examples of how to customize the build. -->
|
||||||
|
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||||
|
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||||
|
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||||
|
<!-- the Compile on Save feature is turned off for the project. -->
|
||||||
|
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||||
|
<!-- in the project's Project Properties dialog box.-->
|
||||||
|
<project name="BukkitTelnetClient" default="default" basedir=".">
|
||||||
|
<description>Builds, tests, and runs the project BukkitTelnetClient.</description>
|
||||||
|
<import file="nbproject/build-impl.xml"/>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
There exist several targets which are by default empty and which can be
|
||||||
|
used for execution of your tasks. These targets are usually executed
|
||||||
|
before and after some main targets. They are:
|
||||||
|
|
||||||
|
-pre-init: called before initialization of project properties
|
||||||
|
-post-init: called after initialization of project properties
|
||||||
|
-pre-compile: called before javac compilation
|
||||||
|
-post-compile: called after javac compilation
|
||||||
|
-pre-compile-single: called before javac compilation of single file
|
||||||
|
-post-compile-single: called after javac compilation of single file
|
||||||
|
-pre-compile-test: called before javac compilation of JUnit tests
|
||||||
|
-post-compile-test: called after javac compilation of JUnit tests
|
||||||
|
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||||
|
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||||
|
-pre-jar: called before JAR building
|
||||||
|
-post-jar: called after JAR building
|
||||||
|
-post-clean: called after cleaning build products
|
||||||
|
|
||||||
|
(Targets beginning with '-' are not intended to be called on their own.)
|
||||||
|
|
||||||
|
Example of inserting an obfuscator after compilation could look like this:
|
||||||
|
|
||||||
|
<target name="-post-compile">
|
||||||
|
<obfuscate>
|
||||||
|
<fileset dir="${build.classes.dir}"/>
|
||||||
|
</obfuscate>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
For list of available properties check the imported
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
|
||||||
|
Another way to customize the build is by overriding existing main targets.
|
||||||
|
The targets of interest are:
|
||||||
|
|
||||||
|
-init-macrodef-javac: defines macro for javac compilation
|
||||||
|
-init-macrodef-junit: defines macro for junit execution
|
||||||
|
-init-macrodef-debug: defines macro for class debugging
|
||||||
|
-init-macrodef-java: defines macro for class execution
|
||||||
|
-do-jar-with-manifest: JAR building (if you are using a manifest)
|
||||||
|
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
||||||
|
run: execution of project
|
||||||
|
-javadoc-build: Javadoc generation
|
||||||
|
test-report: JUnit report generation
|
||||||
|
|
||||||
|
An example of overriding the target for project execution could look like this:
|
||||||
|
|
||||||
|
<target name="run" depends="BukkitTelnetClient-impl.jar">
|
||||||
|
<exec dir="bin" executable="launcher.exe">
|
||||||
|
<arg file="${dist.jar}"/>
|
||||||
|
</exec>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
Notice that the overridden target depends on the jar target and not only on
|
||||||
|
the compile target as the regular run target does. Again, for a list of available
|
||||||
|
properties which you can use, check the target you are overriding in the
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
-->
|
||||||
|
</project>
|
3
manifest.mf
Normal file
3
manifest.mf
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
X-COMMENT: Main-Class will be added automatically by build
|
||||||
|
|
1053
nbproject/build-impl.xml
Normal file
1053
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
|
@ -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
|
75
nbproject/project.properties
Normal file
75
nbproject/project.properties
Normal file
|
@ -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
|
15
nbproject/project.xml
Normal file
15
nbproject/project.xml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||||
|
<type>org.netbeans.modules.java.j2seproject</type>
|
||||||
|
<configuration>
|
||||||
|
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||||
|
<name>BukkitTelnetClient</name>
|
||||||
|
<source-roots>
|
||||||
|
<root id="src.dir"/>
|
||||||
|
</source-roots>
|
||||||
|
<test-roots>
|
||||||
|
<root id="test.src.dir"/>
|
||||||
|
</test-roots>
|
||||||
|
</data>
|
||||||
|
</configuration>
|
||||||
|
</project>
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
154
src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form
Normal file
154
src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||||
|
<Properties>
|
||||||
|
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||||
|
<Property name="title" type="java.lang.String" value="BukkitTelnetClient"/>
|
||||||
|
</Properties>
|
||||||
|
<SyntheticProperties>
|
||||||
|
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||||
|
</SyntheticProperties>
|
||||||
|
<AuxValues>
|
||||||
|
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||||
|
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||||
|
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||||
|
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||||
|
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||||
|
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||||
|
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||||
|
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||||
|
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||||
|
</AuxValues>
|
||||||
|
|
||||||
|
<Layout>
|
||||||
|
<DimensionLayout dim="0">
|
||||||
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
|
<Group type="102" attributes="0">
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
|
<Component id="jScrollPane1" max="32767" attributes="0"/>
|
||||||
|
<Group type="102" alignment="0" attributes="0">
|
||||||
|
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||||
|
<Component id="jLabel2" max="32767" attributes="0"/>
|
||||||
|
<Component id="jLabel1" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
|
<Group type="102" alignment="0" attributes="0">
|
||||||
|
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||||
|
<Component id="txt_command" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<Group type="102" attributes="0">
|
||||||
|
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
|
||||||
|
<Component id="txt_server" pref="567" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||||
|
<Group type="102" attributes="0">
|
||||||
|
<Component id="btn_connect" linkSize="4" min="-2" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Component id="btn_disconnect" linkSize="4" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<Component id="btn_send" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
</DimensionLayout>
|
||||||
|
<DimensionLayout dim="1">
|
||||||
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
|
<Group type="102" alignment="0" attributes="0">
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Component id="jScrollPane1" pref="334" max="32767" attributes="0"/>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
|
<Component id="txt_command" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="btn_send" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
|
<Component id="txt_server" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="btn_connect" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="btn_disconnect" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
</DimensionLayout>
|
||||||
|
</Layout>
|
||||||
|
<SubComponents>
|
||||||
|
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
||||||
|
<AuxValues>
|
||||||
|
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||||
|
</AuxValues>
|
||||||
|
|
||||||
|
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||||
|
<SubComponents>
|
||||||
|
<Component class="javax.swing.JTextPane" name="main_output">
|
||||||
|
<Properties>
|
||||||
|
<Property name="editable" type="boolean" value="false"/>
|
||||||
|
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||||
|
<Font name="Courier New" size="12" style="0"/>
|
||||||
|
</Property>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
</SubComponents>
|
||||||
|
</Container>
|
||||||
|
<Component class="javax.swing.JTextField" name="txt_command">
|
||||||
|
<Properties>
|
||||||
|
<Property name="enabled" type="boolean" value="false"/>
|
||||||
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txt_commandKeyPressed"/>
|
||||||
|
</Events>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JButton" name="btn_connect">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Connect"/>
|
||||||
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="btn_connectMouseClicked"/>
|
||||||
|
</Events>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JLabel" name="jLabel1">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Command:"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JLabel" name="jLabel2">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Server:"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JTextField" name="txt_server">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="tf.madgeekonline.com:28995"/>
|
||||||
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txt_serverKeyPressed"/>
|
||||||
|
</Events>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JButton" name="btn_disconnect">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Disconnect"/>
|
||||||
|
<Property name="enabled" type="boolean" value="false"/>
|
||||||
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="btn_disconnectMouseClicked"/>
|
||||||
|
</Events>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JButton" name="btn_send">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Send"/>
|
||||||
|
<Property name="enabled" type="boolean" value="false"/>
|
||||||
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="btn_sendMouseClicked"/>
|
||||||
|
</Events>
|
||||||
|
</Component>
|
||||||
|
</SubComponents>
|
||||||
|
</Form>
|
326
src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java
Normal file
326
src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java
Normal file
|
@ -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")
|
||||||
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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();
|
||||||
|
}// </editor-fold>//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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue