Skip to content

Commit

Permalink
debug handling cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 6, 2021
1 parent 7ef9b04 commit bd64db5
Show file tree
Hide file tree
Showing 38 changed files with 65 additions and 265 deletions.
Expand Up @@ -24,49 +24,32 @@ public ActionHandler() {
}

public String doAction(String actionName, NPCTag npc, PlayerTag player, AssignmentScriptContainer assignment, Map<String, ObjectTag> context) {

if (context == null) {
context = new HashMap<>();
}

String determination = "none";

if (assignment == null) {
// dB.echoDebug("Tried to do 'on " + actionName + ":' but couldn't find a matching script.");
return determination;
}

if (!assignment.containsScriptSection("actions.on " + actionName)) {
return determination;
}

Debug.report(assignment, "Action",
ArgumentHelper.debugObj("Type", "On " + actionName)
+ ArgumentHelper.debugObj("NPC", npc.toString())
+ assignment.getAsScriptArg().debug()
+ (player != null ? ArgumentHelper.debugObj("Player", player.getName()) : ""));

Debug.report(assignment, "Action", ArgumentHelper.debugObj("Type", "On " + actionName), npc, assignment.getAsScriptArg(), player);
// Fetch script from Actions
List<ScriptEntry> script = assignment.getEntries(new BukkitScriptEntryData(player, npc), "actions.on " + actionName);
if (script.isEmpty()) {
return determination;
}

Debug.echoDebug(assignment, DebugElement.Header,
"Building action 'On " + actionName.toUpperCase() + "' for " + npc.toString());

Debug.echoDebug(assignment, DebugElement.Header, "Building action 'On " + actionName.toUpperCase() + "' for " + npc.toString());
// Add entries and context to the queue
ScriptQueue queue = new InstantQueue(assignment.getName());
queue.addEntries(script);

ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = context;
src.contexts.put("event_header", new ElementTag(actionName));
queue.setContextSource(src);

// Start the queue!
queue.start();

// Check the determination by asking the DetermineCommand
if (queue.determinations != null && queue.determinations.size() > 0) {
determination = queue.determinations.get(0);
Expand Down
Expand Up @@ -79,7 +79,7 @@ public class HealthTrait extends Trait implements Listener {
private String respawnDelay = Settings.healthTraitRespawnDelay();

@Persist("respawnlocation")
private String respawnLocation = "<npc.flag[respawn_location] || <npc.location>>";
private String respawnLocation = "<npc.flag[respawn_location].if_null[<npc.location>]>";

@Persist("blockdrops")
private boolean blockDrops = Settings.healthTraitBlockDrops();
Expand Down
Expand Up @@ -144,7 +144,7 @@ public void execute(final ScriptEntry scriptEntry) {
DurationTag duration = scriptEntry.getObjectTag("duration");
ElementTag stepElement = scriptEntry.getElement("step");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), Utilities.getEntryPlayer(scriptEntry), script, stepElement != null ? stepElement.debug() : db("step", "++ (inc)"), duration);
Debug.report(scriptEntry, getName(), Utilities.getEntryPlayer(scriptEntry), script, stepElement != null ? stepElement : db("step", "++ (inc)"), duration);
}
String step = stepElement == null ? null : stepElement.asString();
String currentStep = InteractScriptHelper.getCurrentStep(Utilities.getEntryPlayer(scriptEntry), script.getName());
Expand Down
Expand Up @@ -60,9 +60,7 @@ private enum AgeType {ADULT, BABY}

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

for (Argument arg : scriptEntry) {

if (!scriptEntry.hasObject("entities")
&& arg.matchesArgumentList(EntityTag.class)) {
scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
Expand All @@ -83,15 +81,10 @@ else if (!scriptEntry.hasObject("lock")
arg.reportUnhandled();
}
}

// Check to make sure required arguments have been filled
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("No valid entities specified.");
}

// Use default age if one is not specified
scriptEntry.defaultObject("age", new ElementTag(1));

}

@Override
Expand All @@ -102,22 +95,12 @@ public void execute(final ScriptEntry scriptEntry) {
boolean lock = scriptEntry.hasObject("lock");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (lock ? db("lock", true) : "") +
(ageType != null ? db("agetype", ageType)
: db("age", age)) +
db("entities", entities.toString()));
Debug.report(scriptEntry, getName(), (lock ? db("lock", true) : ""), (ageType != null ? db("agetype", ageType) : db("age", age)), db("entities", entities.toString()));
}

// Go through all the entities and set their ages
for (EntityTag entity : entities) {
if (entity.isSpawned()) {

// Check if entity specified can be described by 'EntityAge'
if (EntityAge.describes(entity)) {

EntityAge property = EntityAge.getFrom(entity);

// Adjust 'ageType'
if (ageType != null) {
if (ageType.equals(AgeType.BABY)) {
property.setBaby(true);
Expand All @@ -129,16 +112,12 @@ public void execute(final ScriptEntry scriptEntry) {
else {
property.setAge(age);
}

// Adjust 'locked'
property.setLock(lock);
}
else {
Debug.echoError(scriptEntry.getResidingQueue(), entity.identify() + " is not ageable!");
}

}
}

}
}
Expand Up @@ -127,10 +127,8 @@ public void execute(final ScriptEntry scriptEntry) {
String nmsAnimation = scriptEntry.hasObject("nms_animation") ? (String) scriptEntry.getObject("nms_animation") : null;
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(),
(animation != null ? db("animation", animation.name()) :
effect != null ? db("effect", effect.name()) : db("animation", nmsAnimation)) +
db("entities", entities)
+ (forPlayers != null ? db("for", forPlayers) : ""));
(animation != null ? db("animation", animation.name()) : effect != null ? db("effect", effect.name()) : db("animation", nmsAnimation)),
db("entities", entities), db("for", forPlayers));
}
for (EntityTag entity : entities) {
if (entity.isSpawned()) {
Expand Down
Expand Up @@ -157,8 +157,8 @@ public void execute(final ScriptEntry scriptEntry) {
ElementTag pitch_offset = scriptEntry.getElement("pitch_offset");
boolean shouldCancel = cancel.asBoolean();
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("entities", entities), (shouldCancel ? cancel.debug() : target.debug()), relative, offset,
yaw_offset, pitch_offset, sync_server, no_rotate, no_pitch, (forPlayers == null ? "" : db("for", forPlayers)));
Debug.report(scriptEntry, getName(), db("entities", entities), shouldCancel ? cancel : target, relative, offset,
yaw_offset, pitch_offset, sync_server, no_rotate, no_pitch, db("for", forPlayers));
}
BiConsumer<EntityTag, UUID> procPlayer = (entity, player) -> {
if (shouldCancel) {
Expand Down
Expand Up @@ -98,9 +98,7 @@ public void execute(final ScriptEntry scriptEntry) {
EntityTag target = scriptEntry.getObjectTag("target");
boolean cancel = scriptEntry.hasObject("cancel");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (cancel ? db("cancel", "true") : "") +
db("entities", entities) +
(target != null ? db("target", target) : ""));
Debug.report(scriptEntry, getName(), (cancel ? db("cancel", "true") : ""), db("entities", entities), db("target", target));
}
for (EntityTag entity : entities) {
if (entity.isCitizensNPC()) {
Expand Down
Expand Up @@ -170,11 +170,7 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag reset = scriptEntry.getElement("reset");
DurationTag duration = scriptEntry.getObjectTag("duration");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("entities", entities.toString())
+ db("equipment", equipment.toString())
+ (reset == null ? "" : reset.debug())
+ (duration == null ? "" : duration.debug())
+ db("for", playersFor));
Debug.report(scriptEntry, getName(), db("entities", entities.toString()), db("equipment", equipment.toString()), reset, duration, db("for", playersFor));
}
boolean isReset = reset != null && reset.asBoolean();
for (PlayerTag player : playersFor) {
Expand Down
Expand Up @@ -126,11 +126,7 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag amount = scriptEntry.getElement("amount");
ElementTag saturation = scriptEntry.getElement("saturation");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(),
(player == null ? "" : player.debug())
+ (npc == null ? "" : npc.debug())
+ amount.debug()
+ saturation.debug());
Debug.report(scriptEntry, getName(), player, npc, amount, saturation);
}
if (npc != null) {
if (!npc.getCitizen().hasTrait(HungerTrait.class)) {
Expand Down
Expand Up @@ -117,10 +117,7 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag heal = scriptEntry.getElement("heal");
List<EntityTag> targets = (List<EntityTag>) scriptEntry.getObject("target");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (quantity != null ? quantity.debug() : "") +
(action != null ? action.debug() : "") +
heal.debug() +
db("target", targets.toString()));
Debug.report(scriptEntry, getName(), quantity, action, heal, db("target", targets.toString()));
}
if (quantity == null && action == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Null quantity!");
Expand Down
Expand Up @@ -110,7 +110,7 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag state = scriptEntry.getElement("state");
EntityTag target = scriptEntry.getObjectTag("target");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), state.debug() + target.debug());
Debug.report(scriptEntry, getName(), state, target);
}
if (target.isCitizensNPC()) {
NPC npc = target.getDenizenNPC().getCitizen();
Expand Down
Expand Up @@ -114,9 +114,7 @@ else if (holderObject instanceof LocationTag) {
}
boolean cancel = scriptEntry.hasObject("cancel");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (cancel ? db("cancel", cancel) : "") +
db("entities", entities.toString()) +
(holder != null ? db("holder", holder) : db("holder", holderLoc)));
Debug.report(scriptEntry, getName(), (cancel ? db("cancel", "true") : ""), db("entities", entities.toString()), (holder != null ? db("holder", holder) : db("holder", holderLoc)));
}
for (EntityTag entity : entities) {
if (entity.isSpawned() && entity.isLivingEntity()) {
Expand Down
Expand Up @@ -198,18 +198,9 @@ public void execute(final ScriptEntry scriptEntry) {
ElementTag precision = scriptEntry.getElement("precision");
ElementTag ignore_collision = scriptEntry.getElement("ignore_collision");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("origin", originEntity != null ? originEntity : originLocation) +
db("entities", entities.toString()) +
destination.debug() +
speedElement.debug() +
duration.debug() +
(script != null ? script.debug() : "") +
force_along.debug() +
precision.debug() +
(no_rotate ? db("no_rotate", "true") : "") +
(no_damage ? db("no_damage", "true") : "") +
(ignore_collision != null ? ignore_collision.debug() : "") +
(definitions != null ? definitions.debug() : ""));
Debug.report(scriptEntry, getName(), db("origin", originEntity != null ? originEntity : originLocation), db("entities", entities.toString()),
destination, speedElement, duration, script, force_along, precision, (no_rotate ? db("no_rotate", "true") : ""), (no_damage ? db("no_damage", "true") : ""),
ignore_collision, definitions);
}
final boolean ignoreCollision = ignore_collision != null && ignore_collision.asBoolean();
final double speed = speedElement.asDouble();
Expand Down
Expand Up @@ -132,11 +132,7 @@ public void execute(final ScriptEntry scriptEntry) {
if (perPlayer != null && perPlayer.asBoolean()) {
NetworkInterceptHelper.enable();
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), name.debug()
+ targets.debug()
+ perPlayer.debug()
+ (listNameOnly != null ? listNameOnly.debug() : "")
+ (players == null ? "" : db("for", players)));
Debug.report(scriptEntry, getName(), name, targets, perPlayer, listNameOnly, db("for", players));
}
for (ObjectTag target : targets.objectForms) {
EntityTag entity = target.asType(EntityTag.class, CoreUtilities.noDebugContext);
Expand Down Expand Up @@ -203,9 +199,7 @@ public void execute(final ScriptEntry scriptEntry) {
nameString = nameString.substring(0, 256);
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("name", nameString)
+ (listNameOnly != null ? listNameOnly.debug() : "")
+ targets.debug());
Debug.report(scriptEntry, getName(), db("name", nameString), listNameOnly, targets);
}
for (ObjectTag target : targets.objectForms) {
EntityFormObject entity = target.asType(EntityTag.class, CoreUtilities.noDebugContext);
Expand Down
Expand Up @@ -128,7 +128,7 @@ public void execute(final ScriptEntry scriptEntry) {
final boolean infinite = scriptEntry.hasObject("infinite");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (cancel ? db("cancel", true) : ""), db("entities", entities),
(infinite ? db("duration", "infinite") : duration.debug()), frequency, yaw, pitch);
(infinite ? db("duration", "infinite") : duration), frequency, yaw, pitch);
}
for (EntityTag entity : entities) {
if (cancel) {
Expand Down
Expand Up @@ -139,11 +139,7 @@ public void execute(ScriptEntry scriptEntry) {
List<PlayerTag> forPlayers = (List<PlayerTag>) scriptEntry.getObject("for_players");
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), mode.debug()
+ db("entities", entities)
+ (forPlayers != null ? db("for_players", forPlayers) : "")
+ (fake != null ? fake.debug() : "")
+ (stopfake != null ? stopfake.debug() : ""));
Debug.report(scriptEntry, getName(), mode, db("entities", entities), db("for_players", forPlayers), fake, stopfake);
}
boolean shouldSneak = mode.asString().equalsIgnoreCase("start");
boolean shouldFake = fake != null && fake.asBoolean();
Expand Down
Expand Up @@ -102,7 +102,7 @@ public void execute(final ScriptEntry scriptEntry) {
LocationTag location = scriptEntry.getObjectTag("location");
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("location", location), db("entities", entities.toString()));
Debug.report(scriptEntry, getName(), location, db("entities", entities.toString()));
}
for (EntityTag entity : entities) {
if (entity.isFake && entity.getWorld().equals(location.getWorld())) {
Expand Down
Expand Up @@ -165,13 +165,7 @@ public void execute(ScriptEntry scriptEntry) {
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
final LocationTag lookat = scriptEntry.getObjectTag("lookat");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (loc != null ? loc.debug() : "")
+ (speed != null ? speed.debug() : "")
+ (auto_range != null ? auto_range.debug() : "")
+ (radius != null ? radius.debug() : "")
+ (lookat != null ? lookat.debug() : "")
+ stop.debug()
+ (db("entities", entities)));
Debug.report(scriptEntry, getName(), loc, speed, auto_range, radius, lookat, stop, (db("entities", entities)));
}
boolean shouldStop = stop.asBoolean();
List<NPCTag> npcs = new ArrayList<>();
Expand Down
Expand Up @@ -120,8 +120,7 @@ public void execute(ScriptEntry scriptEntry) {
final List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
final ElementTag player_only = scriptEntry.getElement("player_only");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("items", items) + elSlot.debug() + duration.debug()
+ db("players", players) + player_only.debug());
Debug.report(scriptEntry, getName(), db("items", items), elSlot, duration, db("players", players), player_only);
}
if (players.size() == 0) {
return;
Expand Down
Expand Up @@ -60,7 +60,7 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag value = scriptEntry.getElement("value");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), item.debug() + key.debug() + value.debug());
Debug.report(scriptEntry, getName(), item, key, value);
}

ItemStack itemStack = item.getItemStack();
Expand Down

0 comments on commit bd64db5

Please sign in to comment.