Skip to content

Commit 05d02d2

Browse files
committed
2 screens in GUI
1 parent 510df7f commit 05d02d2

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

src/xyz/jadonfowler/phasebot/PacketHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.spacehq.packetlib.event.session.*;
1818
import xyz.jadonfowler.phasebot.entity.*;
1919
import xyz.jadonfowler.phasebot.inventory.*;
20+
import xyz.jadonfowler.phasebot.script.*;
2021
import xyz.jadonfowler.phasebot.world.*;
2122

2223
public class PacketHandler extends SessionAdapter {
@@ -142,6 +143,7 @@ else if (event.getPacket() instanceof ServerSetSlotPacket) {
142143
else if (event.getPacket() instanceof ServerChatPacket) {
143144
Message message = event.<ServerChatPacket> getPacket().getMessage();
144145
try {
146+
PhaseBot.getConsole().addChatMessage(message.getFullText());
145147
ChatMessage m = new ChatMessage(message.getFullText());
146148
if (!m.isCommand()) return;
147149
if (!Arrays.asList(PhaseBot.getOwners()).contains(m.getSender())) {
@@ -150,6 +152,7 @@ else if (event.getPacket() instanceof ServerChatPacket) {
150152
}
151153
if (m.getMessage().startsWith(PhaseBot.getPrefix())) {
152154
String command = m.getMessage().replaceFirst(PhaseBot.getPrefix(), "");
155+
command = Script.replaceVariables(command);
153156
PhaseBot.getBot().runCommand(command, true);
154157
}
155158
}

src/xyz/jadonfowler/phasebot/PhaseBot.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ private static void login() {
270270
}
271271
}
272272
else {
273+
273274
protocol = new MinecraftProtocol(USERNAME);
274275
}
275276
Client client = new Client(HOST, PORT, protocol, new TcpSessionFactory(PROXY));

src/xyz/jadonfowler/phasebot/gui/ConsoleGui.java

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ public class ConsoleGui {
1111

1212
JFrame frame;
1313
JTextPane console;
14+
JTextPane chat;
1415
JTextField input;
15-
JScrollPane scrollPane;
16-
StyledDocument document;
16+
JScrollPane consoleScrollPane;
17+
JScrollPane chatScrollPane;
18+
StyledDocument consoleDocument;
19+
StyledDocument chatDocument;
1720
public boolean trace = true;
1821
ArrayList<String> recentInputs = new ArrayList<String>();
1922
int recentInputId = 0;
@@ -34,7 +37,14 @@ public void run() {
3437
console.setEditable(false);
3538
console.setFont(new Font("Open Sans", Font.PLAIN, 12));
3639
console.setOpaque(false);
37-
document = console.getStyledDocument();
40+
console.setBackground(new Color(50, 50, 50));
41+
consoleDocument = console.getStyledDocument();
42+
chat = new JTextPane();
43+
chat.setEditable(false);
44+
chat.setFont(new Font("Open Sans", Font.PLAIN, 12));
45+
chat.setOpaque(false);
46+
chat.setBackground(new Color(50, 50, 50));
47+
chatDocument = chat.getStyledDocument();
3848
input = new JTextField();
3949
// input.setEditable(true); //Probably don't need
4050
// input.setBorder(null);
@@ -81,12 +91,22 @@ public void keyReleased(KeyEvent e) {}
8191

8292
public void keyTyped(KeyEvent e) {}
8393
});
84-
scrollPane = new JScrollPane(console);
85-
scrollPane.setBorder(null);
86-
scrollPane.setOpaque(false);
87-
scrollPane.getViewport().setOpaque(false);
94+
consoleScrollPane = new JScrollPane(console);
95+
consoleScrollPane.setBorder(null);
96+
consoleScrollPane.setOpaque(false);
97+
consoleScrollPane.getViewport().setOpaque(false);
98+
chatScrollPane = new JScrollPane(chat);
99+
chatScrollPane.setBorder(null);
100+
chatScrollPane.setOpaque(false);
101+
chatScrollPane.getViewport().setOpaque(false);
102+
JTabbedPane tabs = new JTabbedPane();
103+
tabs.addTab("Console", null, consoleScrollPane, "Console for PhaseBot");
104+
tabs.addTab("Chat", null, chatScrollPane, "Incoming chat messages");
105+
tabs.setBackground(new Color(50, 50, 50));
88106
frame.add(input, BorderLayout.SOUTH);
89-
frame.add(scrollPane, BorderLayout.CENTER);
107+
frame.add(tabs, BorderLayout.CENTER);
108+
//frame.add(consoleScrollPane, BorderLayout.WEST);
109+
//frame.add(chatScrollPane, BorderLayout.EAST);
90110
frame.getContentPane().setBackground(new Color(50, 50, 50));
91111
frame.setSize(660, 350);// TODO Change
92112
frame.setLocationRelativeTo(null);
@@ -108,6 +128,14 @@ public void print(String s, boolean trace) {
108128
print(s, trace, new Color(255, 255, 255));
109129
}
110130

131+
public void addChatMessage(String s) {
132+
try {
133+
Style style = console.addStyle("Style", null);
134+
chatDocument.insertString(chatDocument.getLength(), s + "\n", style);
135+
}
136+
catch (Exception e) {}
137+
}
138+
111139
public void print(String s, boolean trace, Color c) {
112140
try {
113141
Style style = console.addStyle("Style", null);
@@ -118,13 +146,13 @@ public void print(String s, boolean trace, Color c) {
118146
String caller = elements[0].getClassName();
119147
s = caller + " > " + s;
120148
}
121-
document.insertString(document.getLength(), s, style);
149+
consoleDocument.insertString(consoleDocument.getLength(), s, style);
122150
}
123151
catch (Exception e) {}
124152
}
125153

126154
public void println(String s, boolean trace) {
127-
println(s, trace, new Color(255, 255, 255));
155+
print(s +"\n", trace);
128156
}
129157

130158
public void println(String s, boolean trace, Color c) {
@@ -149,7 +177,7 @@ public void println(String s) {
149177

150178
public void clear() {
151179
try {
152-
document.remove(0, document.getLength());
180+
consoleDocument.remove(0, consoleDocument.getLength());
153181
}
154182
catch (Exception e) {}
155183
}

src/xyz/jadonfowler/phasebot/script/Script.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private String replaceArguments(String s, String[] args) {
148148
return s;
149149
}
150150

151-
private String replaceVariables(String command) {
151+
public static String replaceVariables(String command) {
152152
for (String h : command.split(" ")) {
153153
if (h.startsWith("@")) {
154154
// PhaseBot.getConsole().println(h + " : " + command + " : " +

0 commit comments

Comments
 (0)