Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Commit b25d68a

Browse files
committed
Updated Command Exceptions
1 parent 95d78a3 commit b25d68a

4 files changed

Lines changed: 81 additions & 19 deletions

File tree

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.zero.client.api.command.exception;
22

3+
import me.zero.client.api.command.Command;
4+
35
/**
46
* Superclass for all exceptions in the
57
* {@code me.zero.client.api.exception.command} package.
@@ -9,13 +11,29 @@
911
*/
1012
public class CommandException extends Exception {
1113

12-
public CommandException() {}
14+
/**
15+
* Command that encountered an exception
16+
*/
17+
private final Command command;
18+
19+
public CommandException(Command command) {
20+
this.command = command;
21+
}
1322

14-
public CommandException(String message) {
23+
public CommandException(Command command, String message) {
1524
super(message);
25+
this.command = command;
1626
}
1727

18-
public CommandException(String message, Object... args) {
28+
public CommandException(Command command, String message, Object... args) {
1929
super(String.format(message, args));
30+
this.command = command;
31+
}
32+
33+
/**
34+
* @return The command that encountered an exception
35+
*/
36+
public final Command getCommand() {
37+
return this.command;
2038
}
2139
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.zero.client.api.command.exception;
22

3+
import me.zero.client.api.command.Command;
4+
35
/**
46
* Called when the initialization of a {@code Command}
57
* fails.c
@@ -9,7 +11,7 @@
911
*/
1012
public final class CommandInitException extends CommandException {
1113

12-
public CommandInitException(String message) {
13-
super(message);
14+
public CommandInitException(Command command, String message) {
15+
super(command, message);
1416
}
1517
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package me.zero.client.api.command.exception;
2+
3+
import me.zero.client.api.command.Command;
4+
5+
/**
6+
* @author Brady
7+
* @since 6/7/2017 9:34 AM
8+
*/
9+
public final class InvalidArgumentException extends CommandException {
10+
11+
/**
12+
* Array of inputted arguments
13+
*/
14+
private final String[] args;
15+
16+
/**
17+
* Index of the bag argument
18+
*/
19+
private final int badArg;
20+
21+
/**
22+
* Expected type
23+
*/
24+
private final Class<?> expected;
25+
26+
public InvalidArgumentException(Command command, String[] args, int badArg, Class<?> expected) {
27+
super(command);
28+
this.args = args;
29+
this.badArg = badArg;
30+
this.expected = expected;
31+
}
32+
33+
/**
34+
* @return Array of inputted arguments
35+
*/
36+
public final String[] getArgs() {
37+
return this.args;
38+
}
39+
40+
/**
41+
* @return Index of the bad argument
42+
*/
43+
public final int getBadArg() {
44+
return this.badArg;
45+
}
46+
47+
/**
48+
* Returns the expected class type of the given argument.
49+
*
50+
* @return The expected type
51+
*/
52+
public Class<?> getExpectedType() {
53+
return this.expected;
54+
}
55+
}

src/main/java/me/zero/client/api/command/exception/InvalidSyntaxException.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,7 @@
1111
*/
1212
public final class InvalidSyntaxException extends CommandException {
1313

14-
/**
15-
* The command that had invalid syntax provided
16-
*/
17-
private final Command command;
18-
1914
public InvalidSyntaxException(Command command) {
20-
super("Invalid Command Syntax");
21-
this.command = command;
22-
}
23-
24-
/**
25-
* @return The command that had invalid syntax provided
26-
*/
27-
public final Command getCommand() {
28-
return this.command;
15+
super(command, "Invalid Command Syntax");
2916
}
3017
}

0 commit comments

Comments
 (0)