Skip to content

Commit

Permalink
Add a debug command
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 17, 2015
1 parent 82a580c commit 921049c
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ else if (arg.matches("}")) {
bracesSection.get(bracesSection.size() - 1).entryData.transferDataFrom(scriptEntry.entryData);
if (hyperdebug) dB.echoDebug(scriptEntry, "Command added: " + cmd + ", with " + String.valueOf(args.length) + " arguments");
} catch (ScriptEntryCreationException e) {
if (hyperdebug) dB.echoError(scriptEntry.getResidingQueue(), e.getMessage());
dB.echoError(scriptEntry.getResidingQueue(), e.getMessage());
}
}
if (hyperdebug) dB.echoDebug(scriptEntry, "Adding section " + bracesName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,38 @@ public <T extends RegistrationableInstance> T get(Class<T> clazz) {

public void registerCoreCommands() {

// <--[command]
// @Name Debug
// @Syntax debug [<type>] [<message>] (name:<name>)
// @Required 2
// @Stable stable
// @Short Shows a debug message.
// @Author mcmonkey
// @Group core
// @Description
// Use to quickly output debug information to console.
// Valid types include:
// DEBUG: standard hideable debug.
// HEADER: standard hideable debug inside a header line.
// FOOTER: a footer line.
// SPACER: a spacer line.
// LOG: global output, non-hideable.
// APPROVAL: "Okay!" output, non-hideable.
// ERROR: "Error!" output, non-hideable.
// REPORT: normally used to describe the arguments of a command, requires a name, hideable.
// @Tags
// None
// @Usage
// Use to show an error
// - debug error "Something went wrong!"
// @Usage
// Use to add some information to help your own ability to read debug output from you script
// - debug debug "Time is currently <def[milliseconds].div[1000].round> seconds!"
// -->
registerCoreMember(DebugCommand.class,
"debug", "debug [<type>] [<message>] (name:<name>)", 2);


// <--[command]
// @Name Define
// @Syntax define [<id>] [<value>]
Expand Down Expand Up @@ -113,7 +145,7 @@ public void registerCoreCommands() {
// <def[<ID>]> to get the value assigned to an ID

// @Usage
// Use to make complex tags look less complex, and scripts more readable.
// Use to make complex tags look less complex, and scripts more readable
// - narrate 'You invoke your power of notice...'
// - define range '<player.flag[range_level].mul[3]>'
// - define blocks '<player.flag[noticeable_blocks]>'
Expand All @@ -122,13 +154,13 @@ public void registerCoreCommands() {

// @Usage
// Use to keep the value of a replaceable tag that you might use many times within a single script. Definitions
// can be faster and cleaner than reusing a replaceable tag over and over.
// can be faster and cleaner than reusing a replaceable tag over and over
// - define arg1 <c.args.get[1]>
// - if <def[arg1]> == hello narrate 'Hello!'
// - if <def[arg1]> == goodbye narrate 'Goodbye!'

// @Usage
// Use to pass some important information (arguments) on to another queue.
// Use to pass some important information (arguments) on to another queue
// - run 'new_task' d:hello|world
// 'new_task' now has some definitions, <def[1]> and <def[2]>, that contains the contents specified, 'hello' and 'world'.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package net.aufdemrand.denizencore.scripts.commands.core;

import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import net.aufdemrand.denizencore.utilities.debugging.dB;

public class DebugCommand extends AbstractCommand {

public enum DebugType {
DEBUG,
HEADER,
FOOTER,
SPACER,
LOG,
APPROVAL,
ERROR,
REPORT
}

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("type")
&& arg.matchesEnum(DebugType.values())) {
scriptEntry.addObject("type", arg.asElement());
}

else if (!scriptEntry.hasObject("debug")) {
scriptEntry.addObject("debug", new Element(arg.raw_value));
}

else if (!scriptEntry.hasObject("name")
&& arg.matchesPrefix("name")) {
scriptEntry.addObject("name", arg.asElement());
}

else arg.reportUnhandled();
}

if (!scriptEntry.hasObject("type") || !scriptEntry.hasObject("debug")) {
throw new InvalidArgumentsException("Must specify a definition and value!");
}
scriptEntry.defaultObject("name", new Element("name"));

}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

Element debug = scriptEntry.getElement("debug");
Element type = scriptEntry.getElement("type");
Element name = scriptEntry.getElement("name");

// Intentionally do not DB REPORT - we're making our own debug output!

switch (DebugType.valueOf(type.asString().toUpperCase())) {
case DEBUG:
dB.echoDebug(scriptEntry, debug.asString());
break;
case HEADER:
dB.echoDebug(scriptEntry, dB.DebugElement.Header, debug.asString());
break;
case FOOTER:
dB.echoDebug(scriptEntry, dB.DebugElement.Footer, debug.asString());
break;
case SPACER:
dB.echoDebug(scriptEntry, dB.DebugElement.Spacer, debug.asString());
break;
case LOG:
dB.log(debug.asString());
break;
case APPROVAL:
dB.echoApproval(debug.asString());
break;
case ERROR:
dB.echoError(scriptEntry.getResidingQueue(), debug.asString());
break;
case REPORT:
dB.report(scriptEntry, name.asString(), debug.asString());
break;
}
}
}

0 comments on commit 921049c

Please sign in to comment.