mirror of
https://github.com/TotalFreedomMC/ZeroTelnetClient.git
synced 2024-12-22 16:25:14 +00:00
Moved coloring and filtering functions to new class.
Fixed "Username: " and "Password: " prompts.
This commit is contained in:
parent
d650867207
commit
8417702fb7
6 changed files with 133 additions and 59 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target/
|
2
pom.xml
2
pom.xml
|
@ -3,7 +3,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>me.StevenLawson</groupId>
|
<groupId>me.StevenLawson</groupId>
|
||||||
<artifactId>BukkitTelnetClient</artifactId>
|
<artifactId>BukkitTelnetClient</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.3-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package me.StevenLawson.BukkitTelnetClient;
|
package me.StevenLawson.BukkitTelnetClient;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.PrintStream;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.net.telnet.TelnetClient;
|
import org.apache.commons.net.telnet.TelnetClient;
|
||||||
|
@ -94,11 +96,14 @@ public class BTC_ConnectionManager
|
||||||
System.out.println("\nDisconnected.");
|
System.out.println("\nDisconnected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final ByteArrayOutputStream consoleBuffer = new ByteArrayOutputStream();
|
||||||
|
private final PrintStream consoleStream = new PrintStream(consoleBuffer);
|
||||||
|
|
||||||
public void sendCommand(String text)
|
public void sendCommand(String text)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
System.out.println(text);
|
consoleStream.format("%s\r\n", text);
|
||||||
|
|
||||||
this.telnetClient.getOutputStream().write((text + "\n").getBytes());
|
this.telnetClient.getOutputStream().write((text + "\n").getBytes());
|
||||||
this.telnetClient.getOutputStream().flush();
|
this.telnetClient.getOutputStream().flush();
|
||||||
|
@ -132,14 +137,43 @@ public class BTC_ConnectionManager
|
||||||
btc.getTxtCommand().setEnabled(true);
|
btc.getTxtCommand().setEnabled(true);
|
||||||
btc.getTxtCommand().requestFocusInWindow();
|
btc.getTxtCommand().requestFocusInWindow();
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(telnetClient.getInputStream())))
|
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(telnetClient.getInputStream())))
|
||||||
{
|
{
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null)
|
int read = 0;
|
||||||
|
while (read != -1)
|
||||||
{
|
{
|
||||||
if (!btc.skipLine(line))
|
boolean block = true;
|
||||||
|
|
||||||
|
while (block || reader.ready())
|
||||||
{
|
{
|
||||||
System.out.println(line);
|
block = false;
|
||||||
|
|
||||||
|
read = reader.read();
|
||||||
|
if (read != -1)
|
||||||
|
{
|
||||||
|
consoleBuffer.write(read);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read == '\n')
|
||||||
|
{
|
||||||
|
final String line = consoleBuffer.toString();
|
||||||
|
if (!BTC_FormatHandler.skipLine(line))
|
||||||
|
{
|
||||||
|
System.out.print(line);
|
||||||
|
}
|
||||||
|
consoleBuffer.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (consoleBuffer.size() > 0)
|
||||||
|
{
|
||||||
|
final String line = consoleBuffer.toString();
|
||||||
|
if (line.endsWith("Username: ") || line.endsWith("Password: "))
|
||||||
|
{
|
||||||
|
System.out.print(consoleBuffer.toString());
|
||||||
|
consoleBuffer.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
package me.StevenLawson.BukkitTelnetClient;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class BTC_FormatHandler
|
||||||
|
{
|
||||||
|
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 static final boolean skipLine(String line)
|
||||||
|
{
|
||||||
|
final BTC_MainPanel mainPanel = BukkitTelnetClient.mainPanel;
|
||||||
|
|
||||||
|
if (mainPanel == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mainPanel.getChkShowChatOnly().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 (mainPanel.getChkIgnoreServerCommands().isSelected() && ISSUED_SERVER_COMMAND.matcher(line).find())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (mainPanel.getChkIgnorePlayerCommands().isSelected() && PLAYER_COMMAND.matcher(line).find())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Color getColor(String text)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package me.StevenLawson.BukkitTelnetClient;
|
package me.StevenLawson.BukkitTelnetClient;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyAdapter;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
@ -13,7 +12,7 @@ import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.regex.Pattern;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.text.BadLocationException;
|
import javax.swing.text.BadLocationException;
|
||||||
import javax.swing.text.SimpleAttributeSet;
|
import javax.swing.text.SimpleAttributeSet;
|
||||||
|
@ -56,40 +55,6 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
this.setVisible(true);
|
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)
|
public final void updateTextPane(final String text)
|
||||||
{
|
{
|
||||||
SwingUtilities.invokeLater(new Runnable()
|
SwingUtilities.invokeLater(new Runnable()
|
||||||
|
@ -99,26 +64,12 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
{
|
{
|
||||||
final StyledDocument styledDocument = mainOutput.getStyledDocument();
|
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
|
try
|
||||||
{
|
{
|
||||||
styledDocument.insertString(
|
styledDocument.insertString(
|
||||||
styledDocument.getLength(),
|
styledDocument.getLength(),
|
||||||
text,
|
text,
|
||||||
StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color)
|
StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, BTC_FormatHandler.getColor(text))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (BadLocationException ex)
|
catch (BadLocationException ex)
|
||||||
|
@ -169,6 +120,26 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JCheckBox getChkAutoScroll()
|
||||||
|
{
|
||||||
|
return chkAutoScroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JCheckBox getChkIgnorePlayerCommands()
|
||||||
|
{
|
||||||
|
return chkIgnorePlayerCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JCheckBox getChkIgnoreServerCommands()
|
||||||
|
{
|
||||||
|
return chkIgnoreServerCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JCheckBox getChkShowChatOnly()
|
||||||
|
{
|
||||||
|
return chkShowChatOnly;
|
||||||
|
}
|
||||||
|
|
||||||
public final void saveServersAndTriggerConnect()
|
public final void saveServersAndTriggerConnect()
|
||||||
{
|
{
|
||||||
String selected_server = (String) txtServer.getSelectedItem();
|
String selected_server = (String) txtServer.getSelectedItem();
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.apache.commons.io.output.TeeOutputStream;
|
||||||
|
|
||||||
public class BukkitTelnetClient
|
public class BukkitTelnetClient
|
||||||
{
|
{
|
||||||
public static final String VERSION_STRING = "v2.01_b1";
|
public static final String VERSION_STRING = "v2.0.3";
|
||||||
|
|
||||||
public static final Logger LOGGER = Logger.getLogger(BukkitTelnetClient.class.getName());
|
public static final Logger LOGGER = Logger.getLogger(BukkitTelnetClient.class.getName());
|
||||||
public static final ByteArrayOutputStream CONSOLE = new ByteArrayOutputStream();
|
public static final ByteArrayOutputStream CONSOLE = new ByteArrayOutputStream();
|
||||||
|
|
Loading…
Reference in a new issue