Merge pull request #316 from babbaj/master

Never send chat message when using prefix
This commit is contained in:
Leijurv 2019-01-20 09:21:51 -08:00
commit 0de1517bd8
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A

View File

@ -77,6 +77,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
"costs - (debug) all movement costs from current location\n" + "costs - (debug) all movement costs from current location\n" +
"damn - Daniel "; "damn - Daniel ";
private static final String COMMAND_PREFIX = "#";
public ExampleBaritoneControl(Baritone baritone) { public ExampleBaritoneControl(Baritone baritone) {
super(baritone); super(baritone);
} }
@ -88,15 +90,18 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
} }
String msg = event.getMessage(); String msg = event.getMessage();
if (Baritone.settings().prefix.get()) { if (Baritone.settings().prefix.get()) {
if (!msg.startsWith("#")) { if (msg.startsWith(COMMAND_PREFIX)) {
return; if (!runCommand(msg.substring(COMMAND_PREFIX.length()))) {
logDirect("Invalid command");
} }
msg = msg.substring(1); event.cancel(); // always cancel if using prefix
} }
} else {
if (runCommand(msg)) { if (runCommand(msg)) {
event.cancel(); event.cancel();
} }
} }
}
public boolean runCommand(String msg0) { public boolean runCommand(String msg0) {
String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
@ -121,7 +126,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
for (String line : HELP_MSG.split("\n")) { for (String line : HELP_MSG.split("\n")) {
logDirect(line); logDirect(line);
} }
return false; return true;
} }
if (msg.contains(" ")) { if (msg.contains(" ")) {
String[] data = msg.split(" "); String[] data = msg.split(" ");