Skip to content

Commit

Permalink
Include shooters in entity damage world event names. i.e. now you can…
Browse files Browse the repository at this point in the history
… use "player damages entity" instead of just "arrow damages entity".
  • Loading branch information
davidcernat committed Oct 11, 2013
1 parent 15ff094 commit 7613330
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -341,22 +341,22 @@ public String getAttribute(Attribute attribute) {
.getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <l@location.block.below>
// @attribute <l@location.below>
// @returns dLocation
// @description
// Returns the location of the block below the location.
// Returns the location below this location.
// -->
if (attribute.startsWith("block.below"))
if (attribute.startsWith("below"))
return new dLocation(this.add(0,-1,0))
.getAttribute(attribute.fulfill(2));

// <--[tag]
// @attribute <l@location.block.above>
// @attribute <l@location.above>
// @returns dLocation
// @description
// Returns the location of the block above the location.
// Returns the location above this location.
// -->
if (attribute.startsWith("block.above"))
if (attribute.startsWith("above"))
return new dLocation(this.add(0,1,0))
.getAttribute(attribute.fulfill(2));

Expand Down Expand Up @@ -617,12 +617,12 @@ public int compare(dEntity ent1, dEntity ent2) {
}

// <--[tag]
// @attribute <l@location.block.material>
// @attribute <l@location.material>
// @returns Element
// @description
// Returns the Bukkit material name of the block at the location.
// -->
if (attribute.startsWith("block.material"))
if (attribute.startsWith("material"))
return dMaterial.getMaterialFrom(getBlock().getType(), getBlock().getData()).getAttribute(attribute.fulfill(2));


Expand Down
Expand Up @@ -1454,10 +1454,16 @@ public void entityDamage(EntityDamageEvent event) {

Player subPlayer = null;
dNPC subNPC = null;
dEntity shooter = null;

dEntity damager = new dEntity(subEvent.getDamager());
context.put("damager", damager.getDenizenObject());

events.add("entity damaged by entity");
events.add("entity damaged by " + damager.identifyType());
events.add(entity.identifyType() + " damaged by entity");
events.add(entity.identifyType() + " damaged by " + damager.identifyType());

if (damager.isNPC()) {
subNPC = damager.getDenizenNPC();

Expand All @@ -1475,14 +1481,14 @@ else if (damager.isPlayer()) {
// If the damager is a projectile, add its shooter (which can be null)
// to the context
else if (damager.hasShooter()) {
dEntity shooter = damager.getShooter();
shooter = damager.getShooter();
context.put("shooter", shooter.getDenizenObject());
}

events.add("entity damaged by entity");
events.add("entity damaged by " + damager.identifyType());
events.add(entity.identifyType() + " damaged by entity");
events.add(entity.identifyType() + " damaged by " + damager.identifyType());
if (shooter != null && !damager.getEntityType().equals(shooter.getEntityType())) {
events.add("entity damaged by " + shooter.identifyType());
events.add(entity.identifyType() + " damaged by " + shooter.identifyType());
}
}

// Have a new list of events for the subContextPlayer
// and subContextNPC
Expand All @@ -1494,12 +1500,22 @@ else if (damager.hasShooter()) {
subEvents.add(damager.identifyType() + " damages entity");
subEvents.add(damager.identifyType() + " damages " + entity.identifyType());

if (shooter != null && !damager.getEntityType().equals(shooter.getEntityType())) {
subEvents.add(shooter.identifyType() + " damages entity");
subEvents.add(shooter.identifyType() + " damages " + entity.identifyType());
}

if (isFatal) {
events.add("entity killed by entity");
events.add("entity killed by " + damager.identifyType());
events.add(entity.identifyType() + " killed by entity");
events.add(entity.identifyType() + " killed by " + damager.identifyType());

if (shooter != null && !damager.getEntityType().equals(shooter.getEntityType())) {
events.add("entity killed by " + shooter.identifyType());
events.add(entity.identifyType() + " killed by " + shooter.identifyType());
}

// <--[event]
// @Events
// entity kills entity
Expand All @@ -1524,6 +1540,11 @@ else if (damager.hasShooter()) {
subEvents.add("entity kills " + entity.identifyType());
subEvents.add(damager.identifyType() + " kills entity");
subEvents.add(damager.identifyType() + " kills " + entity.identifyType());

if (shooter != null && !damager.getEntityType().equals(shooter.getEntityType())) {
subEvents.add(shooter.identifyType() + " kills entity");
subEvents.add(shooter.identifyType() + " kills " + entity.identifyType());
}
}

determination = doEvents(subEvents, subNPC, subPlayer, context, true);
Expand Down

0 comments on commit 7613330

Please sign in to comment.