Skip to content

Commit

Permalink
Add /denizen debug -e to toggle event firing debug messages. (This wi…
Browse files Browse the repository at this point in the history
…ll show all events firing, whether there is a script or not…) Fix some entity on entity events in WorldScriptHelper.
  • Loading branch information
aufdemrand committed Aug 17, 2013
1 parent 63c2945 commit 2f6ab2c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/main/java/net/aufdemrand/denizen/CommandHandler.java
Expand Up @@ -687,14 +687,20 @@ public void health(CommandContext args, CommandSender sender, NPC npc) throws Co
@Command(
aliases = { "denizen" }, usage = "debug",
desc = "Toggles debug mode for Denizen.", modifiers = { "debug", "de", "db" },
min = 1, max = 3, permission = "denizen.debug", flags = "sc")
min = 1, max = 3, permission = "denizen.debug", flags = "sceb")
public void debug(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (args.hasFlag('s')) {
if (!dB.debugMode) dB.toggle();
dB.showStackTraces = !dB.showStackTraces;
} else if (args.hasFlag('c')) {
if (!dB.debugMode) dB.toggle();
dB.showColor = !dB.showColor;
} else if (args.hasFlag('e')) {
if (!dB.debugMode) dB.toggle();
dB.showEventsFiring = !dB.showEventsFiring;
} else if (args.hasFlag('b')) {
if (!dB.debugMode) dB.toggle();
dB.showScriptBuilder = !dB.showScriptBuilder;
} else dB.toggle();

Messaging.send(sender, ChatColor.YELLOW + "Denizen debugger is " + (dB.debugMode ?
Expand Down
Expand Up @@ -112,14 +112,14 @@ public static String doEvents(List<String> eventNames, dNPC npc, Player player,

String determination = "none";

// dB.log("Fired for '" + eventNames.toString() + "'");
if (dB.showEventsFiring) dB.log("Fired for '" + eventNames.toString() + "'");

for (WorldScriptContainer script : world_scripts.values()) {

if (script == null) continue;

for (String eventName : eventNames) {

if (!script.contains("EVENTS.ON " + eventName.toUpperCase())) continue;

// Fetch script from Event
Expand Down Expand Up @@ -527,7 +527,7 @@ public void entityDamage(EntityDamageEvent event) {
Map<String, Object> context = new HashMap<String, Object>();
boolean isFatal = false;
dEntity entity = new dEntity(event.getEntity());
String entityType = entity.getType();
String entityType = entity.getEntityType().name();
String cause = event.getCause().name();

String determination;
Expand Down Expand Up @@ -580,10 +580,10 @@ else if (entity.isPlayer()) {

dPlayer subPlayer = null;
dNPC subNPC = null;

dEntity damager = new dEntity(subEvent.getDamager());
String damagerType = damager.getType();
String damagerType = damager.getEntityType().name();

if (damager.isNPC()) {
subNPC = new dNPC(damager.getNPC());
context.put("damager", subNPC);
Expand All @@ -592,13 +592,15 @@ else if (entity.isPlayer()) {
// If we had no NPC in our regular context, use this one
if (npc == null) npc = subNPC;
}

else if (damager.isPlayer()) {
subPlayer = new dPlayer(damager.getPlayer());
context.put("damager", subPlayer);

// If we had no player in our regular context, use this one
if (player == null) player = subPlayer;
}

else {
context.put("damager", damager);

Expand All @@ -619,7 +621,7 @@ else if (shooter.isPlayer()) {
}
}
}

events.add("entity damaged by entity");
events.add("entity damaged by " + damagerType);
events.add(entityType + " damaged by entity");
Expand Down
Expand Up @@ -58,6 +58,7 @@ public class dB {
public static boolean showStackTraces = true;
public static boolean showScriptBuilder = false;
public static boolean showColor = true;
public static boolean showEventsFiring = false;

/**
* Can be used with echoDebug(...) to output a header, footer,
Expand Down

0 comments on commit 2f6ab2c

Please sign in to comment.