-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
DebugInvalidCommand.java
54 lines (49 loc) · 2.46 KB
/
DebugInvalidCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.denizenscript.denizencore.scripts.commands.core;
import com.denizenscript.denizencore.DenizenCore;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.utilities.debugging.Debug;
/**
* This command exists for technical reasons, to handle invalid commands.
*/
public class DebugInvalidCommand extends AbstractCommand {
public DebugInvalidCommand() {
setName("debug-invalid-command");
setSyntax("");
setRequiredArguments(0, Integer.MAX_VALUE);
isProcedural = true;
}
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
}
@Override
public void execute(ScriptEntry scriptEntry) {
Debug.echoDebug(scriptEntry, Debug.DebugElement.Header, "Executing command: " + scriptEntry.getCommandName());
AbstractCommand command = DenizenCore.commandRegistry.get(scriptEntry.internal.command);
if (scriptEntry.internal.brokenArgs) {
if (scriptEntry.getOriginalArguments().size() > command.maximumArguments) {
Debug.echoError(scriptEntry.getResidingQueue(), scriptEntry.toString() + " cannot be executed! Too many arguments - did you forget to use quotes?\nUsage: " + command.getUsageHint());
}
else {
Debug.echoError(scriptEntry.getResidingQueue(), scriptEntry.toString() + " cannot be executed! Too few arguments - did you forget a required input?\nUsage: " + command.getUsageHint());
}
return;
}
else {
if (command != null) {
int argCount = scriptEntry.getOriginalArguments().size();
if (argCount < command.minimumArguments || argCount > command.maximumArguments) {
scriptEntry.internal.brokenArgs = true;
}
else {
scriptEntry.internal.actualCommand = command;
}
scriptEntry.getResidingQueue().injectEntryAtStart(scriptEntry);
return;
}
Debug.echoError(scriptEntry.getResidingQueue(), scriptEntry.getCommandName() + " is an invalid command! Are you sure it loaded?");
}
Debug.echoDebug(scriptEntry, Debug.DebugElement.Footer);
}
}