Skip to content

Commit

Permalink
Debug everything else properly too
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 28, 2013
1 parent 068daca commit 3813eee
Show file tree
Hide file tree
Showing 47 changed files with 203 additions and 208 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -1184,7 +1184,7 @@ else if (attribute.startsWith("equipment")) {
// @attribute <e@entity.item_in_hand>
// @returns dItem
// @description
// returns the item the entity is holding, or null
// returns the item the entity is holding, or i@air
// if none.
// -->
if (attribute.startsWith("item_in_hand") ||
Expand Down
Expand Up @@ -64,7 +64,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

// Debug the execution

// dB.report(getName(), required_integer.debug()
// dB.report(scriptEntry, getName(), required_integer.debug()
// + required_location.debug());


Expand Down
Expand Up @@ -8,7 +8,6 @@
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;

/**
* TODO: Document usage
Expand All @@ -33,7 +32,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
if (aH.matchesScript(arg)) {
script = aH.getScriptFrom(arg);
if (script != null && !script.getType().equalsIgnoreCase("assignment")) {
dB.echoError("Script type must be 'ASSIGNMENT'. Script specified is '%s'.", script.getType());
dB.echoError("Script type must be 'ASSIGNMENT'. Script specified is '" + script.getType() + "'.");
script = null;
}
}
Expand All @@ -42,15 +41,16 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
else if (aH.matchesArg("SET, REMOVE", arg))
action = Action.valueOf(arg.toUpperCase());

else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
else
dB.echoError("Unnknown argument '" + arg + "'");
}

// If 'SET'ting with no 'script' throws an error.
if (action == Action.SET && script == null)
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "SCRIPT");
throw new InvalidArgumentsException("Missing 'script' argument!");
// If no NPC attached, throw an error
if (scriptEntry.getNPC() == null)
throw new InvalidArgumentsException(Messages.ERROR_NO_NPCID);
throw new InvalidArgumentsException("This command requires a linked npc!");

// Add objects that need to be passed to execute() to the scriptEntry
scriptEntry.addObject("script", script)
Expand All @@ -64,7 +64,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dScript script = (dScript) scriptEntry.getObject("script");

// Report to dB
dB.report(getName(),
dB.report(scriptEntry, getName(),
aH.debugObj("Action", action.toString())
+ (script != null ? script.debug() : "")
+ aH.debugObj("NPC", scriptEntry.getNPC().toString()));
Expand Down
Expand Up @@ -5,9 +5,7 @@
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.scripts.commands.npc.EngageCommand;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;

/**
* Unsets the Denizen from the Engage List.
Expand All @@ -30,15 +28,15 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException

// Make sure NPC is available
if (scriptEntry.getNPC() == null)
throw new InvalidArgumentsException(Messages.ERROR_NO_NPCID);
throw new InvalidArgumentsException("This command requires a linked NPC!");

}

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

// Report to dB
dB.report(getName(),
dB.report(scriptEntry, getName(),
aH.debugObj("NPC", scriptEntry.getNPC().toString()));

// Set Disengaged
Expand Down
Expand Up @@ -8,7 +8,6 @@
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.aH.ArgumentType;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.api.npc.NPC;

import org.bukkit.Location;
Expand All @@ -26,17 +25,17 @@ public void parseArgs(ScriptEntry scriptEntry)
for (String arg : scriptEntry.getArguments()) {
if (aH.matchesLocation(arg)) {
location = aH.getLocationFrom(arg);
dB.echoDebug("...location set");
dB.echoDebug(scriptEntry, "...location set");
} else if (aH.matchesArg("CATCHFISH", arg)) {
catchFish = true;
dB.echoDebug("...npc will catch fish");
dB.echoDebug(scriptEntry, "...npc will catch fish");
} else if (aH.matchesArg("STOP", arg)) {
stopping = true;
dB.echoDebug("...stopping");
dB.echoDebug(scriptEntry, "...stopping");
} else if (aH.matchesValueArg("CATCHPERCENT, PERCENT", arg, ArgumentType.Integer)) {
catchPercent = aH.getIntegerFrom(arg);
dB.echoDebug("...set catch percent: " + catchPercent);
} else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
dB.echoDebug(scriptEntry, "...set catch percent: " + catchPercent);
} else throw new InvalidArgumentsException("Unknown argument '" + arg + "'");
}

scriptEntry.addObject("location", location)
Expand All @@ -46,8 +45,7 @@ public void parseArgs(ScriptEntry scriptEntry)
}

@Override
public void execute(ScriptEntry scriptEntry)
throws CommandExecutionException {
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Boolean stopping = (Boolean) scriptEntry.getObject("stopping");
Boolean catchFish = (Boolean) scriptEntry.getObject("catchFish");
int catchPercent = (Integer) scriptEntry.getObject("catchPercent");
Expand Down
Expand Up @@ -34,13 +34,14 @@ else if (!scriptEntry.hasObject("target") &&
arg.matchesArgumentType(dEntity.class))
scriptEntry.addObject("target", arg.asType(dEntity.class));

else throw new InvalidArgumentsException(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
else
arg.reportUnhandled();
}
if (!scriptEntry.hasObject("target")) {
if (scriptEntry.hasPlayer())
scriptEntry.addObject("target", scriptEntry.getPlayer().getDenizenEntity());
else
throw new InvalidArgumentsException(dB.Messages.ERROR_NO_PLAYER);
throw new InvalidArgumentsException("This command requires a linked player!");
}
}

Expand All @@ -52,7 +53,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dEntity target = (dEntity) scriptEntry.getObject("target");

// Report to dB
dB.report(getName(),
dB.report(scriptEntry, getName(),
(scriptEntry.getPlayer() != null ? scriptEntry.getPlayer().debug() : "")
+ (stop == null ? aH.debugObj("Action", "FOLLOW")
: aH.debugObj("Action", "STOP"))
Expand Down
Expand Up @@ -7,7 +7,6 @@
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.aH.ArgumentType;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.trait.LookClose;

Expand Down Expand Up @@ -46,21 +45,21 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException

if (aH.matchesArg("REALISTIC", arg)) {
realistic = true;
dB.echoDebug(Messages.DEBUG_SET_TYPE, arg);

} else if (aH.matchesValueArg("RANGE", arg, ArgumentType.Double)) {
}
else if (aH.matchesValueArg("RANGE", arg, ArgumentType.Double)) {
range = aH.getDoubleFrom(arg);
dB.echoDebug(Messages.DEBUG_SET_RANGE, String.valueOf(range));

} else if (aH.matchesState(arg)) {
}
else if (aH.matchesState(arg)) {
toggle = aH.getBooleanFrom(arg);
dB.echoDebug(Messages.DEBUG_TOGGLE, String.valueOf(toggle));

} else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}
else dB.echoError("Unknown argument '" + arg + "'");
}

if (scriptEntry.getNPC() == null)
throw new InvalidArgumentsException(Messages.ERROR_NO_NPCID);
throw new InvalidArgumentsException("This command requires a linked NPC!");


scriptEntry.addObject("realistic", realistic)
Expand Down
Expand Up @@ -7,7 +7,6 @@
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.trait.waypoint.Waypoints;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -53,15 +52,16 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException

if (aH.matchesDuration(arg)) {
duration = aH.getIntegerFrom(arg);
dB.echoDebug(Messages.DEBUG_SET_DURATION, arg);

} else if (aH.matchesArg("WAYPOINTS", arg) || aH.matchesArg("NAVIGATION", arg)
}
else if (aH.matchesArg("WAYPOINTS", arg) || aH.matchesArg("NAVIGATION", arg)
|| aH.matchesArg("ACTIVITY", arg) || aH.matchesArg("WAYPOINTS", arg)) {
// Could also maybe do for( ... : PauseType.values()) ... not sure which is faster.
pauseType = PauseType.valueOf(arg.toUpperCase());
dB.echoDebug(Messages.DEBUG_SET_TYPE, arg);

} else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}
else
dB.echoError("Unknown argument '" + arg + "'");
}
}

Expand All @@ -74,14 +74,16 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
if (duration > 0) {
if (durations.containsKey(dNPC.getCitizen().getId() + pauseType.name())) {
try { denizen.getServer().getScheduler().cancelTask(durations.get(dNPC.getCitizen().getId() + pauseType.name())); }
catch (Exception e) { dB.echoError(Messages.ERROR_CANCELLING_DELAYED_TASK); }
catch (Exception e) { dB.echoError("There was an error pausing that!"); e.printStackTrace(); }

} dB.echoDebug(Messages.DEBUG_SETTING_DELAYED_TASK, "UNPAUSE " + pauseType);
}
dB.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType.toString());

final ScriptEntry se = scriptEntry;
durations.put(dNPC.getId() + pauseType.name(), denizen.getServer().getScheduler().scheduleSyncDelayedTask(denizen,
new Runnable() {
@Override public void run() {
dB.echoDebug(Messages.DEBUG_RUNNING_DELAYED_TASK, "UNPAUSING " + pauseType);
dB.echoDebug(se, "Running delayed task: Pausing " + pauseType.toString());
pause(dNPC, pauseType, false);

}
Expand Down
Expand Up @@ -10,7 +10,6 @@
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.trait.Poses;

/**
Expand Down Expand Up @@ -44,15 +43,18 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException

} else if (aH.matchesArg("PLAYER", arg)) {
targetType = TargetType.PLAYER;
dB.echoDebug("Setting pose on PLAYER!");
dB.echoDebug(scriptEntry, "Setting pose on PLAYER!");

} else throw new InvalidArgumentsException(dB.Messages.ERROR_UNKNOWN_ARGUMENT);
} else
dB.echoError("Unknown argument '" + arg + "'");

}

// If TARGET is NPC/PLAYER and no NPC/PLAYER available, throw exception.
if (targetType == TargetType.PLAYER && scriptEntry.getPlayer() == null) throw new InvalidArgumentsException(Messages.ERROR_NO_PLAYER);
else if (targetType == TargetType.NPC && scriptEntry.getNPC() == null) throw new InvalidArgumentsException(Messages.ERROR_NO_NPCID);
if (targetType == TargetType.PLAYER && scriptEntry.getPlayer() == null)
throw new InvalidArgumentsException("This command requires a linked player!");
else if (targetType == TargetType.NPC && scriptEntry.getNPC() == null)
throw new InvalidArgumentsException("This command requires a linked NPC!");
scriptEntry.addObject("target", targetType)
.addObject("action", action).addObject("id", id);
}
Expand All @@ -68,7 +70,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
String id = (String) scriptEntry.getObject("id");

// Report to dB
dB.report(getName(),
dB.report(scriptEntry, getName(),
aH.debugObj(target.toString(), npc.toString())
+ aH.debugObj("Action", action.toString())
+ aH.debugObj("Id", id));
Expand Down
Expand Up @@ -41,7 +41,7 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept

Element name = (Element) scriptEntry.getObject("name");

dB.report(getName(), name.debug());
dB.report(scriptEntry, getName(), name.debug());

NPC npc = scriptEntry.getNPC().getCitizen();

Expand Down
Expand Up @@ -10,7 +10,6 @@
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Wolf;
Expand All @@ -26,7 +25,8 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
&& !scriptEntry.hasObject("location")) {
scriptEntry.addObject("location", arg.asType(dLocation.class));
}
else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
else
arg.reportUnhandled();
}

}
Expand All @@ -53,7 +53,7 @@ else if (scriptEntry.getNPC().getEntityType() == EntityType.WOLF) {
SittingTrait trait = scriptEntry.getNPC().getCitizen().getTrait(SittingTrait.class);
if (!scriptEntry.getNPC().getCitizen().hasTrait(SittingTrait.class)) {
scriptEntry.getNPC().getCitizen().addTrait(SittingTrait.class);
dB.echoDebug("...added sitting trait");
dB.echoDebug(scriptEntry, "...added sitting trait");
}

if (trait.isSitting()) {
Expand Down
Expand Up @@ -3,10 +3,10 @@
import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.npc.traits.SittingTrait;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.api.npc.NPC;

public class StandCommand extends AbstractCommand{
Expand All @@ -15,21 +15,21 @@ public class StandCommand extends AbstractCommand{
public void parseArgs(ScriptEntry scriptEntry)
throws InvalidArgumentsException {
//stand should have no additional arguments
for (String arg: scriptEntry.getArguments())
throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
arg.reportUnhandled();
}

}

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

NPC npc = scriptEntry.getNPC().getCitizen();
SittingTrait trait = npc.getTrait(SittingTrait.class);

if (!npc.hasTrait(SittingTrait.class)){
npc.addTrait(SittingTrait.class);
dB.echoDebug("...added sitting trait");
dB.echoDebug(scriptEntry, "...added sitting trait");
}

if (!trait.isSitting()) {
Expand Down
Expand Up @@ -7,7 +7,6 @@
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
Expand All @@ -32,10 +31,10 @@ else if (!scriptEntry.hasObject("trait"))
}

if (!scriptEntry.hasObject("trait"))
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "TRAIT");
throw new InvalidArgumentsException("Missing trait argument!");

if (!scriptEntry.hasNPC())
throw new InvalidArgumentsException(Messages.ERROR_NO_NPCID);
throw new InvalidArgumentsException("This command requires a linked NPC!");

scriptEntry.defaultObject("state", new Element("TOGGLE"));

Expand All @@ -48,7 +47,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element traitName = scriptEntry.getElement("trait");
NPC npc = scriptEntry.getNPC().getCitizen();

dB.report(getName(),
dB.report(scriptEntry, getName(),
traitName.debug() +
toggle.debug() +
scriptEntry.getNPC().debug());
Expand Down

0 comments on commit 3813eee

Please sign in to comment.