Initial commit of BukkitTelnetClient v2.

This commit is contained in:
StevenLawson 2014-08-15 21:55:16 -04:00
commit 65f12447f6
6 changed files with 1002 additions and 0 deletions

17
nbactions.xml Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath me.StevenLawson.BukkitTelnetClient.BukkitTelnetClient</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
</actions>

58
pom.xml Normal file
View file

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.StevenLawson</groupId>
<artifactId>BukkitTelnetClient</artifactId>
<version>v2.01_b1</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<minimizeJar>true</minimizeJar>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>me.StevenLawson.BukkitTelnetClient.BukkitTelnetClient</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<name>BukkitTelnetClient</name>
</project>

View file

@ -0,0 +1,161 @@
package me.StevenLawson.BukkitTelnetClient;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.net.telnet.TelnetClient;
public class BTC_ConnectionManager
{
private final TelnetClient telnetClient;
private Thread connectThread;
private String hostname;
private int port;
private boolean canDoDisconnect = false;
public BTC_ConnectionManager()
{
this.telnetClient = new TelnetClient();
}
public void triggerConnect(String hostname, int port)
{
final BTC_MainPanel btc = BukkitTelnetClient.mainPanel;
btc.getBtnConnect().setEnabled(false);
btc.getTxtServer().setEnabled(false);
btc.getBtnDisconnect().setEnabled(true);
btc.setTitle("BukkitTelnetClient - " + BukkitTelnetClient.VERSION_STRING + " - " + hostname + ":" + port);
System.out.println("Connecting to " + hostname + ":" + port + "...");
this.hostname = hostname;
this.port = port;
startConnectThread();
}
public void triggerConnect(String hostnameAndPort)
{
final String[] parts = StringUtils.split(hostnameAndPort, ":");
if (parts.length <= 1)
{
this.triggerConnect(parts[0], 23);
}
else
{
int _port = 23;
try
{
_port = Integer.parseInt(parts[1]);
}
catch (NumberFormatException ex)
{
}
this.triggerConnect(parts[0], _port);
}
}
public void triggerDisconnect()
{
if (this.canDoDisconnect)
{
this.canDoDisconnect = false;
try
{
this.telnetClient.disconnect();
}
catch (IOException ex)
{
BukkitTelnetClient.LOGGER.log(Level.SEVERE, null, ex);
}
}
}
public void finishDisconnect()
{
final BTC_MainPanel btc = BukkitTelnetClient.mainPanel;
btc.getBtnConnect().setEnabled(true);
btc.getTxtServer().setEnabled(true);
btc.getBtnDisconnect().setEnabled(false);
btc.getBtnSend().setEnabled(false);
btc.getTxtCommand().setEnabled(false);
btc.setTitle("BukkitTelnetClient - " + BukkitTelnetClient.VERSION_STRING + " - Disconnected");
System.out.println("\nDisconnected.");
}
public void sendCommand(String text)
{
try
{
System.out.println(text);
this.telnetClient.getOutputStream().write((text + "\n").getBytes());
this.telnetClient.getOutputStream().flush();
}
catch (IOException ex)
{
BukkitTelnetClient.LOGGER.log(Level.SEVERE, null, ex);
}
}
private void startConnectThread()
{
if (this.connectThread != null)
{
return;
}
this.connectThread = new Thread(new Runnable()
{
private final BTC_MainPanel btc = BukkitTelnetClient.mainPanel;
@Override
public void run()
{
try
{
BTC_ConnectionManager.this.telnetClient.connect(hostname, port);
BTC_ConnectionManager.this.canDoDisconnect = true;
btc.getBtnSend().setEnabled(true);
btc.getTxtCommand().setEnabled(true);
btc.getTxtCommand().requestFocusInWindow();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(telnetClient.getInputStream())))
{
String line;
while ((line = reader.readLine()) != null)
{
if (!btc.skipLine(line))
{
System.out.println(line);
}
}
}
triggerDisconnect();
}
catch (IOException ex)
{
BukkitTelnetClient.LOGGER.log(Level.SEVERE, null, ex);
}
finishDisconnect();
BTC_ConnectionManager.this.connectThread = null;
}
});
this.connectThread.start();
}
}

View file

@ -0,0 +1,195 @@
<?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"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</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" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="chkIgnorePlayerCommands" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="chkIgnoreServerCommands" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="chkShowChatOnly" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<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>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtCommand" pref="680" max="32767" attributes="0"/>
<Component id="txtServer" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="btnConnect" linkSize="4" max="32767" attributes="0"/>
<Component id="btnSend" linkSize="4" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="btnDisconnect" linkSize="4" min="-2" max="-2" attributes="0"/>
<Component id="chkAutoScroll" linkSize="4" min="-2" max="-2" 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="338" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="chkIgnorePlayerCommands" alignment="3" min="-2" pref="23" max="-2" attributes="0"/>
<Component id="chkIgnoreServerCommands" alignment="3" min="-2" pref="23" max="-2" attributes="0"/>
<Component id="chkShowChatOnly" alignment="3" min="-2" pref="23" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtCommand" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnSend" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="chkAutoScroll" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnConnect" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnDisconnect" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtServer" 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="mainOutput">
<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="txtCommand">
<Properties>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtCommandKeyPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnConnect">
<Properties>
<Property name="text" type="java.lang.String" value="Connect"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnConnectActionPerformed"/>
</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.JButton" name="btnDisconnect">
<Properties>
<Property name="text" type="java.lang.String" value="Disconnect"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnDisconnectActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnSend">
<Properties>
<Property name="text" type="java.lang.String" value="Send"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSendActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="txtServer">
<Properties>
<Property name="editable" type="boolean" value="true"/>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="chkAutoScroll">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="AutoScroll"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkAutoScrollActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="chkIgnorePlayerCommands">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="Ignore &quot;[PLAYER_COMMAND]&quot; messages"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="chkIgnoreServerCommands">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="Ignore &quot;issued server command&quot; messages"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="chkShowChatOnly">
<Properties>
<Property name="text" type="java.lang.String" value="Show chat only"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkShowChatOnlyActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View file

@ -0,0 +1,457 @@
package me.StevenLawson.BukkitTelnetClient;
import java.awt.Color;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.regex.Pattern;
import javax.swing.SwingUtilities;
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;
public class BTC_MainPanel extends javax.swing.JFrame
{
private static final String SERVERS_FILE_NAME = "btc_servers.cfg";
private final BTC_ConnectionManager connectionManager = new BTC_ConnectionManager();
private final LinkedList<String> serverList = new LinkedList<>();
public BTC_MainPanel()
{
initComponents();
this.txtServer.getEditor().getEditorComponent().addKeyListener(new KeyAdapter()
{
@Override
public void keyTyped(KeyEvent e)
{
if (e.getKeyChar() == KeyEvent.VK_ENTER)
{
BTC_MainPanel.this.saveServersAndTriggerConnect();
}
}
});
this.loadServerList();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
private static final Pattern CHAT_MESSAGE = Pattern.compile("^:\\[.+? INFO\\]: \\<");
private static final Pattern SAY_MESSAGE = Pattern.compile("^:\\[.+? INFO\\]: \\[Server:");
private static final Pattern ADMINSAY_MESSAGE = Pattern.compile("^:\\[.+? INFO\\]: \\[TotalFreedomMod\\] \\[ADMIN\\] ");
private static final Pattern CSAY_MESSAGE = Pattern.compile("^:\\[.+? INFO\\]: \\[CONSOLE\\]<");
private static final Pattern WORLD_EDIT = Pattern.compile("^:\\[.+? INFO\\]: WorldEdit: ");
private static final Pattern PREPROCESS_COMMAND = Pattern.compile("^:\\[.+? INFO\\]: \\[PREPROCESS_COMMAND\\] ");
private static final Color DARK_GREEN = new Color(86, 130, 3);
private static final Pattern ISSUED_SERVER_COMMAND = Pattern.compile("^:\\[.+? INFO\\]: .+? issued server command: ");
private static final Pattern PLAYER_COMMAND = Pattern.compile("^:\\[.+? INFO\\]: \\[PLAYER_COMMAND\\] ");
public final boolean skipLine(String line)
{
if (this.chkShowChatOnly.isSelected())
{
if (!CHAT_MESSAGE.matcher(line).find() && !SAY_MESSAGE.matcher(line).find() && !ADMINSAY_MESSAGE.matcher(line).find() && !CSAY_MESSAGE.matcher(line).find())
{
return true;
}
}
else if (this.chkIgnoreServerCommands.isSelected() && ISSUED_SERVER_COMMAND.matcher(line).find())
{
return true;
}
else if (this.chkIgnorePlayerCommands.isSelected() && PLAYER_COMMAND.matcher(line).find())
{
return true;
}
return false;
}
public final void updateTextPane(final String text)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
final StyledDocument styledDocument = mainOutput.getStyledDocument();
Color color = Color.BLACK;
if (CHAT_MESSAGE.matcher(text).find() || SAY_MESSAGE.matcher(text).find() || ADMINSAY_MESSAGE.matcher(text).find() || CSAY_MESSAGE.matcher(text).find())
{
color = Color.BLUE;
}
else if (WORLD_EDIT.matcher(text).find())
{
color = Color.RED;
}
else if (PREPROCESS_COMMAND.matcher(text).find())
{
color = DARK_GREEN;
}
try
{
styledDocument.insertString(
styledDocument.getLength(),
text,
StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color)
);
}
catch (BadLocationException ex)
{
throw new RuntimeException(ex);
}
if (BTC_MainPanel.this.chkAutoScroll.isSelected() && BTC_MainPanel.this.mainOutput.getSelectedText() == null)
{
BTC_MainPanel.this.mainOutput.setCaretPosition(styledDocument.getLength() - 1);
}
}
});
}
public void updateConsole()
{
final String data = BukkitTelnetClient.CONSOLE.toString();
BukkitTelnetClient.CONSOLE.reset();
BTC_MainPanel.this.updateTextPane(data);
}
public final void loadServerList()
{
try
{
serverList.clear();
txtServer.removeAllItems();
File file = new File(SERVERS_FILE_NAME);
if (file.exists())
{
try (BufferedReader in = new BufferedReader(new FileReader(file)))
{
String line;
while ((line = in.readLine()) != null)
{
line = line.trim();
serverList.add(line);
txtServer.addItem(line);
}
}
}
}
catch (IOException ex)
{
BukkitTelnetClient.LOGGER.log(Level.SEVERE, null, ex);
}
}
public final void saveServersAndTriggerConnect()
{
String selected_server = (String) txtServer.getSelectedItem();
if (selected_server == null || selected_server.isEmpty())
{
System.out.println("Invalid server address.");
return;
}
try
{
if (serverList.contains(selected_server))
{
serverList.remove(selected_server);
}
serverList.addFirst(selected_server);
try (BufferedWriter out = new BufferedWriter(new FileWriter(new File(SERVERS_FILE_NAME))))
{
for (String server : serverList)
{
out.write(server + '\n');
}
}
}
catch (IOException ex)
{
BukkitTelnetClient.LOGGER.log(Level.SEVERE, null, ex);
}
loadServerList();
connectionManager.triggerConnect(selected_server);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents()
{
jScrollPane1 = new javax.swing.JScrollPane();
mainOutput = new javax.swing.JTextPane();
txtCommand = new javax.swing.JTextField();
btnConnect = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
btnDisconnect = new javax.swing.JButton();
btnSend = new javax.swing.JButton();
txtServer = new javax.swing.JComboBox();
chkAutoScroll = new javax.swing.JCheckBox();
chkIgnorePlayerCommands = new javax.swing.JCheckBox();
chkIgnoreServerCommands = new javax.swing.JCheckBox();
chkShowChatOnly = new javax.swing.JCheckBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("BukkitTelnetClient");
mainOutput.setEditable(false);
mainOutput.setFont(new java.awt.Font("Courier New", 0, 12)); // NOI18N
jScrollPane1.setViewportView(mainOutput);
txtCommand.setEnabled(false);
txtCommand.addKeyListener(new java.awt.event.KeyAdapter()
{
public void keyPressed(java.awt.event.KeyEvent evt)
{
txtCommandKeyPressed(evt);
}
});
btnConnect.setText("Connect");
btnConnect.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
btnConnectActionPerformed(evt);
}
});
jLabel1.setText("Command:");
jLabel2.setText("Server:");
btnDisconnect.setText("Disconnect");
btnDisconnect.setEnabled(false);
btnDisconnect.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
btnDisconnectActionPerformed(evt);
}
});
btnSend.setText("Send");
btnSend.setEnabled(false);
btnSend.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
btnSendActionPerformed(evt);
}
});
txtServer.setEditable(true);
chkAutoScroll.setSelected(true);
chkAutoScroll.setText("AutoScroll");
chkAutoScroll.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
chkAutoScrollActionPerformed(evt);
}
});
chkIgnorePlayerCommands.setSelected(true);
chkIgnorePlayerCommands.setText("Ignore \"[PLAYER_COMMAND]\" messages");
chkIgnoreServerCommands.setSelected(true);
chkIgnoreServerCommands.setText("Ignore \"issued server command\" messages");
chkShowChatOnly.setText("Show chat only");
chkShowChatOnly.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
chkShowChatOnlyActionPerformed(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)
.addGroup(layout.createSequentialGroup()
.addComponent(chkIgnorePlayerCommands)
.addGap(18, 18, 18)
.addComponent(chkIgnoreServerCommands)
.addGap(18, 18, 18)
.addComponent(chkShowChatOnly)
.addGap(0, 0, Short.MAX_VALUE))
.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))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtCommand, javax.swing.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE)
.addComponent(txtServer, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btnConnect, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnSend, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnDisconnect)
.addComponent(chkAutoScroll))))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnConnect, btnDisconnect, btnSend, chkAutoScroll});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(chkIgnorePlayerCommands, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(chkIgnoreServerCommands, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(chkShowChatOnly, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtCommand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addComponent(btnSend)
.addComponent(chkAutoScroll))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(btnConnect)
.addComponent(btnDisconnect)
.addComponent(txtServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void txtCommandKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_txtCommandKeyPressed
{//GEN-HEADEREND:event_txtCommandKeyPressed
if (!txtCommand.isEnabled())
{
return;
}
if (evt.getKeyCode() == KeyEvent.VK_ENTER)
{
connectionManager.sendCommand(txtCommand.getText());
txtCommand.selectAll();
}
}//GEN-LAST:event_txtCommandKeyPressed
private void chkAutoScrollActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_chkAutoScrollActionPerformed
{//GEN-HEADEREND:event_chkAutoScrollActionPerformed
updateTextPane("");
}//GEN-LAST:event_chkAutoScrollActionPerformed
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnConnectActionPerformed
{//GEN-HEADEREND:event_btnConnectActionPerformed
if (!btnConnect.isEnabled())
{
return;
}
saveServersAndTriggerConnect();
}//GEN-LAST:event_btnConnectActionPerformed
private void btnDisconnectActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnDisconnectActionPerformed
{//GEN-HEADEREND:event_btnDisconnectActionPerformed
if (!btnDisconnect.isEnabled())
{
return;
}
connectionManager.triggerDisconnect();
}//GEN-LAST:event_btnDisconnectActionPerformed
private void btnSendActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSendActionPerformed
{//GEN-HEADEREND:event_btnSendActionPerformed
if (!btnSend.isEnabled())
{
return;
}
connectionManager.sendCommand(txtCommand.getText());
txtCommand.selectAll();
}//GEN-LAST:event_btnSendActionPerformed
private void chkShowChatOnlyActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_chkShowChatOnlyActionPerformed
{//GEN-HEADEREND:event_chkShowChatOnlyActionPerformed
boolean enable = !chkShowChatOnly.isSelected();
chkIgnorePlayerCommands.setEnabled(enable);
chkIgnoreServerCommands.setEnabled(enable);
}//GEN-LAST:event_chkShowChatOnlyActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnConnect;
private javax.swing.JButton btnDisconnect;
private javax.swing.JButton btnSend;
private javax.swing.JCheckBox chkAutoScroll;
private javax.swing.JCheckBox chkIgnorePlayerCommands;
private javax.swing.JCheckBox chkIgnoreServerCommands;
private javax.swing.JCheckBox chkShowChatOnly;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextPane mainOutput;
private javax.swing.JTextField txtCommand;
private javax.swing.JComboBox txtServer;
// End of variables declaration//GEN-END:variables
public javax.swing.JButton getBtnConnect()
{
return btnConnect;
}
public javax.swing.JButton getBtnDisconnect()
{
return btnDisconnect;
}
public javax.swing.JButton getBtnSend()
{
return btnSend;
}
public javax.swing.JTextPane getMainOutput()
{
return mainOutput;
}
public javax.swing.JTextField getTxtCommand()
{
return txtCommand;
}
public javax.swing.JComboBox getTxtServer()
{
return txtServer;
}
}

View file

@ -0,0 +1,114 @@
package me.StevenLawson.BukkitTelnetClient;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UnsupportedLookAndFeelException;
import org.apache.commons.io.output.TeeOutputStream;
public class BukkitTelnetClient
{
public static final String VERSION_STRING = "v2.01_b1";
public static final Logger LOGGER = Logger.getLogger(BukkitTelnetClient.class.getName());
public static final ByteArrayOutputStream CONSOLE = new ByteArrayOutputStream();
public static BTC_MainPanel mainPanel = null;
public static void main(String args[])
{
final PrintStream guiConsole = new PrintStream(CONSOLE, true)
{
@Override
public void write(byte[] bytes) throws IOException
{
super.write(bytes);
if (mainPanel != null)
{
mainPanel.updateConsole();
}
}
@Override
public void write(int i)
{
super.write(i);
if (mainPanel != null)
{
mainPanel.updateConsole();
}
}
@Override
public void write(byte[] bytes, int i, int i1)
{
super.write(bytes, i, i1);
if (mainPanel != null)
{
mainPanel.updateConsole();
}
}
@Override
public void flush()
{
super.flush();
if (mainPanel != null)
{
mainPanel.updateConsole();
}
}
};
System.setOut(new PrintStream(new TeeOutputStream(System.out, guiConsole)));
System.setErr(new PrintStream(new TeeOutputStream(System.err, guiConsole)));
findAndSetLookAndFeel("Windows");
java.awt.EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
mainPanel = new BTC_MainPanel();
}
});
}
private static void findAndSetLookAndFeel(final String searchStyleName)
{
try
{
javax.swing.UIManager.LookAndFeelInfo foundStyle = null;
javax.swing.UIManager.LookAndFeelInfo fallbackStyle = null;
for (javax.swing.UIManager.LookAndFeelInfo style : javax.swing.UIManager.getInstalledLookAndFeels())
{
if (searchStyleName.equalsIgnoreCase(style.getName()))
{
foundStyle = style;
break;
}
else if ("Nimbus".equalsIgnoreCase(style.getName()))
{
fallbackStyle = style;
}
}
if (foundStyle != null)
{
javax.swing.UIManager.setLookAndFeel(foundStyle.getClassName());
}
else if (fallbackStyle != null)
{
javax.swing.UIManager.setLookAndFeel(fallbackStyle.getClassName());
}
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex)
{
LOGGER.log(Level.SEVERE, null, ex);
}
}
}