Skip to content

Commit 510df7f

Browse files
committed
Prefix and other config options
1 parent ddf32bd commit 510df7f

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

src/xyz/jadonfowler/phasebot/ChatMessage.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ else if (full.matches("\\[\\[(.*)\\](.*) -> me\\] (.*)")) {
2323
else if (full.matches("<(.+)> (.+)")) {
2424
sender = full.split("<")[1].split(">")[0];
2525
message = full.split("> ")[1];
26-
PhaseBot.getConsole().println(sender + ": " + message);
26+
//PhaseBot.getConsole().println(sender + ": " + message);
2727
}
2828

29-
if (PhaseBot.getPrefix().equals(".")) message = "." + message;
3029
if (message != null && message.startsWith(PhaseBot.getPrefix()))
31-
command = message.split(PhaseBot.getPrefix())[1].split(" ")[0];
30+
command = message.replaceFirst(PhaseBot.getPrefix(), "").split(" ")[0];
3231
}
3332
catch (Exception e) {}
3433
}

src/xyz/jadonfowler/phasebot/PacketHandler.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ else if (event.getPacket() instanceof ServerPlayerPositionRotationPacket) {
3232
PhaseBot.getBot().pos.z = event.<ServerPlayerPositionRotationPacket> getPacket().getZ();
3333
PhaseBot.getBot().pitch = event.<ServerPlayerPositionRotationPacket> getPacket().getPitch();
3434
PhaseBot.getBot().yaw = event.<ServerPlayerPositionRotationPacket> getPacket().getYaw();
35-
PhaseBot.getConsole().println("My Position: " + PhaseBot.getBot().pos.x + "," + PhaseBot.getBot().pos.y + ","
36-
+ PhaseBot.getBot().pos.z);
35+
PhaseBot.getConsole().println("My Position: " + PhaseBot.getBot().pos.x + "," + PhaseBot.getBot().pos.y
36+
+ "," + PhaseBot.getBot().pos.z);
3737
event.getSession().send(new ClientPlayerPositionRotationPacket(false, PhaseBot.getBot().pos.x,
3838
PhaseBot.getBot().pos.y, PhaseBot.getBot().pos.z, PhaseBot.getBot().pitch, PhaseBot.getBot().yaw));
3939
}
@@ -134,8 +134,9 @@ else if (event.getPacket() instanceof ServerSetSlotPacket) {
134134
ServerSetSlotPacket p = event.<ServerSetSlotPacket> getPacket();
135135
if (p.getWindowId() == 0) {// Player's Inventory
136136
PhaseBot.getBot().getInventory().setItem(p.getSlot(), p.getItem());
137-
//if(p.getItem() != null)
138-
//PhaseBot.getConsole().println("Inventory Slot #" + p.getSlot() + " change to " + p.getItem().getId());
137+
// if(p.getItem() != null)
138+
// PhaseBot.getConsole().println("Inventory Slot #" +
139+
// p.getSlot() + " change to " + p.getItem().getId());
139140
}
140141
}
141142
else if (event.getPacket() instanceof ServerChatPacket) {
@@ -147,7 +148,10 @@ else if (event.getPacket() instanceof ServerChatPacket) {
147148
event.getSession().send(new ClientChatPacket("/msg " + m.getSender() + " You are not my master!"));
148149
return;
149150
}
150-
PhaseBot.getBot().runCommand(m.getMessage().split(PhaseBot.getPrefix())[1], true);
151+
if (m.getMessage().startsWith(PhaseBot.getPrefix())) {
152+
String command = m.getMessage().replaceFirst(PhaseBot.getPrefix(), "");
153+
PhaseBot.getBot().runCommand(command, true);
154+
}
151155
}
152156
catch (Exception e) {
153157
e.printStackTrace();
@@ -156,6 +160,7 @@ else if (event.getPacket() instanceof ServerChatPacket) {
156160
}
157161

158162
@Override public void disconnected(DisconnectedEvent event) {
159-
PhaseBot.getConsole().println("Disconnected: " + Message.fromString(event.getReason()).getFullText(), false, Color.RED);
163+
PhaseBot.getConsole().println("Disconnected: " + Message.fromString(event.getReason()).getFullText(), false,
164+
Color.RED);
160165
}
161166
}

src/xyz/jadonfowler/phasebot/PhaseBot.java

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
public class PhaseBot {
2121

22-
@Getter @Setter private static String prefix = "owk, ";
22+
@Getter @Setter private static String prefix = ".";
2323
@Getter private static String[] owners = { "Phase", "Voltz" };
2424
private static String USERNAME = "username";
2525
private static String PASSWORD = "password";
@@ -84,34 +84,48 @@ public static void loadConfig() {
8484
}
8585
if (config.createNewFile()) {
8686
BufferedWriter w = new BufferedWriter(new FileWriter(config));
87-
w.write("PhaseBot Configuration File\r\n");
88-
w.write("Username: Notch\r\n");
89-
w.write("Password: Derp");
87+
//@formatter:off
88+
w.write("PhaseBot Configuration File :O\r\n"
89+
+ "https://github.com/phase/phasebot\r\n"
90+
+ "Username: Notch\r\n"
91+
+ "Password: Derp\r\n"
92+
+ "Server: github.orgs:25565\r\n"
93+
+ "Owners: Phase,Voltz\r\n");
94+
//@formatter:on
9095
w.close();
9196
}
9297
}
9398
else {
9499
BufferedReader br = new BufferedReader(new FileReader(config));
95100
String line = br.readLine();
96101
while (line != null) {
97-
if (line.startsWith("Username: ")) { // Username:Notch
98-
USERNAME = line.split(": ")[1];
99-
}
100-
else if (line.startsWith("Password: ")) { // Password:Derp
101-
PASSWORD = line.split(": ")[1];
102-
}
103-
else if (line.startsWith("Server: ")) { // Server:minecraft.net:25565
104-
HOST = line.split(": ")[1].split(":")[0];
105-
PORT = Integer.parseInt(line.split(": ")[1].split(":")[1]);
106-
}
107-
else if (line.startsWith("Proxy")) { // Proxy:123.456.789:860
108-
PROXY = new Proxy(Proxy.Type.HTTP,
109-
new InetSocketAddress(line.split(":")[1], Integer.parseInt(line.split(":")[2])));
110-
}
111-
else if (line.startsWith("Owners")) {
112-
String o = line.split(": ")[1];
113-
owners = o.contains(",") ? o.split(",") : new String[] { o };
102+
try {
103+
if (line.startsWith("Username: ")) { // Username:Notch
104+
USERNAME = line.split(": ")[1];
105+
}
106+
else if (line.startsWith("Password: ")) { // Password:Derp
107+
PASSWORD = line.split(": ")[1];
108+
}
109+
else if (line.startsWith("Server: ")) { // Server:minecraft.net:25565
110+
HOST = line.split(": ")[1].split(":")[0];
111+
PORT = Integer.parseInt(line.split(": ")[1].split(":")[1]);
112+
}
113+
else if (line.startsWith("Proxy: ")) { // Proxy:123.456.789:860
114+
PROXY = new Proxy(Proxy.Type.HTTP,
115+
new InetSocketAddress(line.split(":")[1], Integer.parseInt(line.split(":")[2])));
116+
}
117+
else if (line.startsWith("Owners: ")) {
118+
String o = line.split(": ")[1];
119+
owners = o.contains(",") ? o.split(",") : new String[] { o };
120+
}
121+
else if (line.startsWith("Prefix: ")) {
122+
prefix = line.split(": ")[1];
123+
}
124+
else if (line.startsWith("Online: ")) {
125+
VERIFY_USERS = Boolean.parseBoolean(line.split(": ")[1].toLowerCase());
126+
}
114127
}
128+
catch (Exception e) {}
115129
line = br.readLine();
116130
}
117131
br.close();

src/xyz/jadonfowler/phasebot/cmd/CommandManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public Command addCommand(Command c) {
2323
public void performCommand(String in, String[] args, Session s) {
2424
for (Command c : commands) {
2525
if (c.getCommand().equalsIgnoreCase(args[0].replace(".", ""))) {
26-
//PhaseBot.getConsole().println(in + " : " + Arrays.toString(args));
26+
//System.out.println(in + " : " + Arrays.toString(args));
2727
latestIn = in;
2828
latestArgs = args;
2929
latestSession = s;

0 commit comments

Comments
 (0)